I am writing a Java application using ActiveMQ. I have a Producer Class (which takes user input) and a Consumer Class with a listener, so that as soon as messages arrive, Message Listener executes the onMessage(msg) function. My question, though, is when does a consumer sends back the acknowledgement to the broker, so that the msg is de-queued from the broker? Is it after completing the actions written in the onMessage(msg) function or is it just when the onMessage(msg) function is invoked?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
In the normal case the ack is sent after the onMessage completes since it needs to handle the case of onMessage throwing an exception.
Depends how it's configured, and in part on how you use transactions.
Are you using a message-driven bean? In that case, i believe the acknowledgement will be sent when the transaction is successfully committed. See the specification (specifically the 'ejbcore' version), section 5.4.14 Message Acknowledgment for JMS Message-Driven Beans, which says:
It goes on to say:
But since you really shouldn't be using bean-managed transactions, that is hopefully irrelevant.