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

Viewed 13

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) {
...
}
0 Answers
Related