Search code examples
spring-bootstompactivemq-artemis

If STOMP "expires" header is set for a message, the message expires right away without waiting for the expiry period set in the header


StompHeaders headers = new StompHeaders();
headers.set("persistent", "false");
headers.set("expires", "30000");
headers.set("priority", 9);

The configuration above is to make the message not expire for 30 seconds. But the message expires right after reaching the queue. The listener does not even receive the message.


Solution

  • The expires header indicates the absolute time at which the message will expire (e.g. like the JMSExpiration header on JMS messages), not the delay after which the message will expire. Try this instead:

    StompHeaders headers = new StompHeaders();
    headers.set("persistent", "false");
    headers.set("expires", System.currentTimeMillis() + 30000);
    headers.set("priority", 9);
    

    When you set expires to 30000 that tells the broker that the message expired at a time far in the past so it won't deliver the message to the client.