Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A subscriber client receiving messages from a queue or topic in the broker should be configured to send an acknowledgment back to the broker when the messages are received. There are several acknowledgment methods that can be used by the subscriber.

Table of Contents

Configuring the time taken to acknowledge messages 

There are several acknowledgment models defined in JMS specification 1.1. To configure the time within which consumers can acknowledge messages, you can set the AndesAckWaitTimeOut entry in the JMS client as follows: 

Code Block
System.setProperty("AndesAckWaitTimeOut", "30000");

If the acknowledgment fails within the above time, the client informs the broker that the message is rejected. The message is then scheduled to be redelivered later by the server. 

Configuring standard JMS message acknowledgment patterns

The following JMS acknowledgment patterns can be used:

  • Auto Acknowledge: The messages transmitted through the session are automatically acknowledged by the message receiving client.
  • Duplicates Allowed: When this acknowledgment method is used, the messages will be acknowledged automatically but not always. This means that duplicate messages can sometimes go through a session. However, each message will be acknowledged at least once.
  • Client Acknowledge: The method of message acknowledgment should be enabled at the client end and not by the broker (JMS provider) sending the message.
  • Transacted Acknowledgement: With this method, the client creates a transacted session with the broker (JMS provider) and messages are acknowledged automatically. Once all messages in the transaction are acknowledged, the messages will be committed to the subscriber client.

Configuring per-message acknowledgment

With Per Message Acknowledge we can acknowledge each message as per requirement. Any message that is not acknowledged will go through the same process as when client acknowledged such as the message getting rejected.

Following is a sequence diagram on how an example scenario will work:

 Screen Shot 2016-07-21 at 12.00.00 PM.png

Use the enum org.wso2.andes.jms.Session.PER_MESSAGE_ACKNOWLEDGE available in the andes-client jar or the value 259 when creating the session.

Code Block
import org.wso2.andes.jms.Session;
QueueSession queueSession = queueConnection.createQueueSession(false, Session.PER_MESSAGE_ACKNOWLEDGE);

or,

Code Block
QueueSession queueSession = queueConnection.createQueueSession(false, 259);