RabbitMQ&SpringAMPQ: How to listen multiple queue that created on runtime


This Content is from Stack Overflow. Question asked by Chloe

I found that I can dynamically add queue using RabbitAdmin.
But I don’t know how to make it listen.
Here’s my RabbitMQ config.

public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
        return new RabbitAdmin(connectionFactory);
public DirectExchange exchange() {
        return new DirectExchange(exchange);

and then, I added this code on my service code.

Queue queue = new Queue(queueName, durable, false, false);
Binding binding = new Binding(queueName, Binding.DestinationType.QUEUE, EXCHANGE, routingKey, null);

My question is how to register the listener?

My origin Listener class is here. I declared queue name on yml file before, but now, I don’t know my queue name before run it. Any ideas for this?

@RabbitListener(queues = "${my.rabbitMQ}", concurrency = 2)
public void receiveMessage(String message) {


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?