Search code examples
stompactivemq-artemis

ApacheMQ Artemis keep messages with no route


I am using Artemis 2.6.2 with STOMP only and the following constellation:

Broker:

  • No queues configured in broker.xml, everything is auto created.

Server:

  • SUBSCRIBE to destination TaskResponse without selector/filter
  • SEND to destination TaskRequest with header clientId = ID (the ID of the client what the server would request to)

Client 123:

  • SUBSCRIBE to destination TaskRequest with selector clientId = 123
  • SEND to destination TaskResponse with header clientId = 123

When I watch at the Artemis Console the following happens:

  1. No server and no client is connected: No address or queue is present

  2. Server connect: Artemis creates a multicast address TaskResponse and a multicast queue for this address with empty filter

  3. Client 123 connect: Artemis creates a multicast address TaskRequest and a multicast queue for this address with filter clientId = 123

  4. Message exchange: Messages are transfered from server to client and back to server as expected.

  5. Client 123 disconnect: Artemis removes the multicast address TaskRequest and the coresponding multicast queue with filter clientId = 123

  6. Server sends message to TaskRequest for client 123: According to STOMP client on server the message is sent successful. On the broker the message disappears.

  7. Same behavior vice versa: Client 123 is connected and server is not: According to STOMP client on client 123 the message is sent successful. On the broker the message disappears.

My guess is that the message is discarded because there is no route to a subscriber. If I enable the option "send-to-dla-on-no-route" in address-settings section of broker.xml the message goes directly to dead letter queue.

Do you know a way to preserve the messages until the subscriber reconnects?

Appendix 1: STOMP Messages

I am using the Stomp.Net Library with SelectorsCore Example but reduced only to selector s1. The workflow is a bit other than what I wrote above.

Unfortunately I did not found an example to enable logging of STOMP messages into a file in Artemis. Therefore I recorded the packets with WireShark, exported as text and uploaded into Gist StompMessages.txt. You can see there the diffrent STOMP messages, e.g. search for CONNECT, SEND, etc.

Solution

The solution was to use the option anycastPrefix=/queue/ in the acceptor element in broker.xml to force the queues to type ANYCAST:

<acceptor name="stomp">tcp://0.0.0.0:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true;anycastPrefix=/queue/</acceptor>

Solution

  • What you are observing is the expected behavior. If you send a message to an address with no queues (or in STOMP terms - a destination with no subscribers) then the message will have nowhere to go and will be discarded. This is normal pub/sub semantics.

    If you want to preserve the messages even if no subscriber is present you can either:

    1. Use anycast (i.e. point-to-point) semantics rather than multicast. This is discussed in the Artemis documentation.
    2. Use "durable" STOMP subscribers as discussed in the Artemis documentation. The caveat here is that the subscription will still need to be created before messages are sent and you will also need to make sure you remove the subscription when you are done with it or it may accumulate messages.