Open
Description
On the tutorials page (java) at https://www.rabbitmq.com/tutorials/tutorial-two-java.html there is an example of how to use Acknowledging. In this example the ack is always send. Shouldn't it be send only if the work succeeds? (I am a beginner at java however I think the finally branch always runs)
channel.basicQos(1); // accept only one unack-ed message at a time (see below)
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
System.out.println(" [x] Received '" + message + "'");
try {
doWork(message);
} finally {
System.out.println(" [x] Done");
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
};
boolean autoAck = false;
channel.basicConsume(TASK_QUEUE_NAME, autoAck, deliverCallback, consumerTag -> { });
I would solve this by taking the code out of the finally
block and adding a catch
block. Then escape the entire function on an exception in doWork(message)
.
Apologies if this should have been posted in another repo, I could not find from which repo the above code example originated.
Metadata
Assignees
Labels
No labels
Activity