Message acknowledgement
You don’t want messages getting lost. If you have a crucial message on the queue, and the one bean who gets it can’t commit—or worse, throws an exception and dies—what happens to your critical message?
That’s the point of acknowledgement. The Container tells the messaging service (not the original producer) that the message was delivered and everything is fine.
But if later, while the consumer (the message-driven bean) is processing the message, a Bad Thing happens, the Container can tell the messaging service to put the message back in the queue.
How does the Container really know that something went wrong? Two ways, and it’s your choice as a Bean Provider.
The transaction status
Message acknowledgement is tied to whether the transaction commits or rolls back. If the transaction rolls back, the message goes back on the queue. You get this behavior for beans that use container-managed transaction demarcation (we’ll cover transactions in the next chapter).
OR
The method completion
Message acknowledgement is tied to whether the method completes successfully. If the method throws a runtime exception, the message goes back on the queue. You get this behavior for beans that use bean-managed transaction demarcation.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access