2
votes

My consumer listen to a queue. Auto Ack = false. - If I ACK message will be removed from the queue. - And if I did not ACK, RabbitMQ will put the message to queue as expected. My problem is my consumer not CONTINUE TO LISTEN TO THOSE UN-ACKED messages. To verify that, if I put a new message, consumer picked it up.

Following is my code block. Any solution ?

while (true) {
        try {
            QueueingConsumer.Delivery delivery = consumer.nextDelivery();
            String message = new String(delivery.getBody());
            String response = sendEndpoint(message);
            if (!response.equals(ERROR_CODE)) {
                channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
            } 
        } catch (InterruptedException ignore) {
            continue;
        }
    }
1

1 Answers

2
votes

Did you try basic.reject? As stated in this blog entry, basic.reject will deliver it to the same queue and "RabbitMQ doesn't take care to stop the same consumer getting the message again". So this should work for you.

Depending on what you are trying to do, you also might be interested in the dead letter feature. See here for more information.