Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java tutorial two: acknowledge only upon success #255

Closed
wants to merge 1 commit into from

Conversation

dvdsk
Copy link

@dvdsk dvdsk commented Jan 29, 2020

This would fix issue #254 by removing the try finally that caused the worker to acknowledge even if the doWork function ran into an exception as the finally branch of a try-finally is always run, even if an exception is raised in doWork.

Instead a comment is added explaining that an exception would cause the worker to crash and not ack

@pivotal-issuemaster
Copy link

@dskleingeld Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@dskleingeld Thank you for signing the Contributor License Agreement!

@dvdsk
Copy link
Author

dvdsk commented Jan 29, 2020

If this is merged I will open a second PR in rabbitmq-website (code from tutorial was copied to https://github.com/rabbitmq/rabbitmq-website/blob/live/site/tutorials/tutorial-two-java.md)

@michaelklishin
Copy link
Member

The current approach is not a mistake. Unconditional acknowledgement can be valid as well: not every delivery should be requeued. Of course, this begs the question "why don't you just use automatic acknowledgements then" and it's fair.

Perhaps the approach in this PR makes more sense in a tutorial but the current implementation has its merits as well.

@michaelklishin michaelklishin changed the title removes try finally in favor of comment Java tutorial two: acknowledge only upon success Jan 29, 2020
Copy link
Member

@michaelklishin michaelklishin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR an exception would indeed result in no acknowledgement but it also would NOT result in delivery requeueing because the channel would not be closed and this PR does not requeue explicitly.

We should either leave this code as is with a comment or requeue explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants