activemq-classicsubscriptionstomp

STOMP subscription issue with ActiveMQ Classic


I have a client service written in Lua. It subscribes to a topic on ActiveMQ Classic 5.16.2 via STOMP. The logic of the service is to connect, create a durable subscriptions for all messages on a given topic, and disconnect the connection. The client receives a timeout message when no more messages are available for a topic, which is used as an indicator to send a DISCONNECT frame to close the connection. During testing I found that topic message(s) could be in an ack message for DISCONNECT command as well surprisingly.

Here are the steps the client takes to subscribe topic messages:

  1. Create a TCP connection.
  2. Send SUBSCRIBE frame to create a durable subscription.
  3. Receive all pending topic messages in a loop until no more MESSAGE frames are received and a timeout occurs.
  4. Send DISCONNECT frame (requesting a receipt).
  5. Receive any left-over MESSAGE frames and eventually a RECEIPT frame for the DISCONNECT.

The issue is that in Step 5 the client sometimes receives no frames and a timeout occurs. However, according to the ActiveMQ logs the RECEIPT frame was sent and sometimes MESSAGE frames are sent as well. At first, I thought these frames would come when the above steps were run again, but they were never received. They are simply lost.

So what is the best approach to resolve the issue? Is there any configuration in ActiveMQ to change?


Solution

  • In order to deal with the potential of lost messages you need to use an acknowledgement mode like client or client-individual. You're likely using auto which means the broker may send (and automatically acknowledge) a message that is never received by the client. This can happen in a lot of different situations (e.g. network failure, client crash, etc.).