Issue
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.
@Bean
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
return new RabbitAdmin(connectionFactory);
}
@Bean
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);
admin.declareQueue(queue);
admin.declareBinding(binding);
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) {
...
}
Solution
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.