JMS specifies 3 acknowledgement modes:
AUTO_ACKNOWLEDGE
CLIENT_ACKNOWLEDGE
DUPS_OK_ACKNOWLEDGE
The acknowledgement modes all involve sending acknowledgements from the client to the server. However, in the case where you can afford to lose messages in event of failure, it would make sense to acknowledge the message on the server before delivering it to the client.
The disadvantage of acknowledging on the server before delivery is that the message will be lost if the system crashes after acknowledging the message on the server but before it is delivered to the client. In that case, the message is lost and will not be recovered when the system restart.
Depending on your messaging case, pre-acknowledgement mode can avoid extra network traffic and CPU at the cost of coping with message loss.
An example of a use case for pre-acknowledgement is for stock price update messages. With these messages it might be reasonable to lose a message in event of crash, since the next price update message will arrive soon, overriding the previous price.
This can be configured in the jbm-jms.xml file on the connection factory like this:
<connection-factory name="ConnectionFactory"> <connector-ref connector-name="netty-connector"/> <entries> <entry name="ConnectionFactory"/> </entries> <pre-acknowledge>true</pre-acknowledge> </connection-factory>
Alternatively use pre-acknowledgement mode using the JMS API, create a JMS Session with the JBossSession.PRE_ACKNOWLEDGE constant.
// messages will be acknowledge on the server *before* being delivered to the client Session session = connection.createSession(false, JBossSession.PRE_ACKNOWLEDGE);
Or you can set pre-acknowledge directly on the JBossConnectionFactory instance using the setter method.
To use pre-acknowledgement mode using the core API you can set it directly on the ClientSessionFactory instance using the setter method.
See Section 9.1.35, “Pre-Acknowledge” for an example which shows how to use pre-acknowledgement mode with with JMS.