Search code examples
springrabbitmqspring-rabbit

Is there a way to put a final variable to @RabbitListener?


I have a service and RabbitMQ in Kubernetes cluster. What I want to do is, I want different instances (or replicas) of the service to declare a brand new queue on startup. These queues will be bound to the same exchange.

Can I somehow put a final variable here:

public static final String QUEUE_NAME = "queue-" + UUID.randomUUID().toString();
// ...
@RabbitListener(queues = QUEUE_NAME)

Essentially, I just need a way to create a queue with a generated name, and then listen to this queue using @RabbitListener.


Solution

  • Ok, I figured it out. I tried to solve as it's stated here RabbitListener annotation queue name by ConfigurationProperties although it had not worked until I annotated Rabbit config class with @Component (rather than @Configuration), and set @DependsOn on that config class.