Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring RabbitTemplate - How to create queues automatically upon send

I am using RabbitMQ together with Spring's RabbitTemplate.

When sending messages to queues using the template send methods, I want the queue to automatically be created/declared if it is not already exists.

It is very important since according to our business logic queue names are generated on run-time and I cannot declare them in advance.

Previously we have used JmsTemplate and any call to send or receive automatically created the queue.

like image 972
Oz Molaim Avatar asked Oct 22 '17 09:10

Oz Molaim


1 Answers

You can use a RabbitAdmin to automatically declare the exchange, queue, and binding. Check out this thread for more detail. This forum also bit related to your scenario. I have not tried spring with AMQP though, but I believe this would do it.

/**
 * Required for executing adminstration functions against an AMQP Broker
 */
@Bean
public AmqpAdmin amqpAdmin() {
    return new RabbitAdmin(connectionFactory());
}

Keep coding !

like image 98
Ravindra Ranwala Avatar answered Oct 13 '22 10:10

Ravindra Ranwala