rabbitmqstompspring-rabbit

RabbitMQ stomp auto delete queue - Precondition failed


I am writing an application that uses STOMP for communication. Server side is written using Spring Boot 2.1.7 and as external broker RabbitMQ 3.7.1 is used. On the client side, I am using StompJS.

When a client subscribes to a user destination, eg. /user/queue/some-queue Spring will map it to /queue/some-queue-{sessionID} and RabbitMQ creates a queue with a corresponding name.

On subscription I added header {'auto-delete': true}, as specified here RabbitMQ Stomp Docs, and that created an auto delete queue in RabbitMQ.

Problem comes when I try sending a message to user as

simpTemplate.convertAndSendToUser('user', '/queue/some-queue', message)

Spring correctly translated the queue name, but RabbitMQ responds with an error

PRECONDITION_FAILED - inequivalent arg 'auto_delete' for queue

What can I do to fix this issue?


Solution

  • I think I found a solution. If I add same same headers, which were defined during subscription, when sending message, it will work correctly.

    On example it looks like this:

    Map<String, Object> headers = new HashMap<>();
    headers.put("auto-delete", "true");
    simpMessagingTemplate.convertAndSendToUser("some-user", "/queue/some-queue", "Test payload", headers);