This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • How do I unack the message with Stomp
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

There is no explicit "unack" command in Stomp. Once the client receives the message it cannot be marked as "unconsumed" and sent to another subscriber (or redelivered to the same subscriber again). It's up to your application (or Stomp client) to handle failed processing of received messages and implement "message redelivery".

Stomp transactions are often mistakenly considered to be a solution for this use case. But that's not the case, since transactions are only related to sending messages and acknowledgments. If you start a transaction, send a message ack in a transaction and finally abort it, the message will not be redelivered again. It just means that broker will not send any more messages to the client if the prefetch limit is reached.

Take a look at the following example:

StompConnection connection = new StompConnection();"localhost", 61613);
connection.connect("system", "manager");
connection.send("/queue/test", "message 1");
connection.send("/queue/test", "message 2");
connection.send("/queue/test", "message 3");
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("activemq.prefetchSize", "1");
connection.subscribe("/queue/test", "client", headers);
StompFrame frame = connection.receive();
connection.ack(frame, "tx1");
connection.ack(frame, "tx2");        //sending the ack again
frame = connection.receive();
connection.ack(frame, "tx2");
frame = connection.receive();
connection.ack(frame, "tx3");

This simple application will print

message 1
message 2
message 3

Since the transaction tx1 has been aborted, we needed to acknowledge that message again in tx2 in order to be able to receive the next message (since the prefetch size used is 1).

Also take a look at these pages for more info:

  • No labels