Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is unconditional acknowledgement in tutorial two the right thing to do? #254

Open
Assignees
@dvdsk

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

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /