Search code examples
spring-bootamqpspring-amqp

Is it possible to automatically create queues without RabbitAutoConfiguration.class? AMQP


I'm using 2.1.0.RELEASE version of Spring boot with AMQP. Unfortunetly I need to connect to several different RabbitMQ servers. I had to exclude RabbitAutoConfiguration.class besause due to changes in above version of spring it's impossible to start without one of the ConnectionFactory beans as primary, but even if I set one of them as @Primary, obviously it doesn't work, because how would amqp/spring-boot know which queue to create on which server...

so, is it possible to automatically create queues on different servers with auto configuration disabled?


Solution

  • Yes, you need a RabbitAdmin for each connection factory.

    By default all components will be declared on all brokers, but you can add conditions. See Conditional Declaration.

    By default, all queues, exchanges, and bindings are declared by all RabbitAdmin instances (assuming they have auto-startup="true") in the application context.

    @Bean
    public Queue queue1() {
        Queue queue = new Queue("foo");
        queue.setAdminsThatShouldDeclare(admin1());
        return queue;
    }