是否可以在没有 RabbitAutoConfiguration.class 的情况下自动创建队列? AMQP

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

我正在使用 2.1.0.RELEASE 版本的 Spring 启动与 AMQP。不幸的是,我需要连接到几个不同的 RabbitMQ 服务器。由于 spring 以上版本的更改,我不得不排除 RabbitAutoConfiguration.class,如果没有 ConnectionFactory bean 之一作为主要 bean 就无法启动,但即使我将其中一个设置为 @Primary,显然它不起作用,因为 amqp/spring-boot 怎么知道在哪个服务器上创建哪个队列...

那么,是否可以在禁用自动配置的情况下在不同的服务器上自动创建队列?

是的,每个连接工厂都需要 RabbitAdmin

默认情况下,所有组件都将在所有代理上声明,但您可以添加条件。参见 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;
}