如果不调用"setAdminsThatShouldDeclare",默认选择哪个RabbitAdmin?

Which RabbitAdmin is selected by default if "setAdminsThatShouldDeclare" is not called?

我想声明 QueueExchange,如果我不在队列或交换上调用 setAdminsThatShouldDeclare,则正在选择哪个 RabbitAdmin 实例:

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

@Bean
public Exchange exchange() {
    DirectExchange exchange = new DirectExchange("bar");
    // exchange.setAdminsThatShouldDeclare(admin2());
    return exchange;
}

应用程序中有多个 RabbitMQ 连接(多个 RabbitAdmin 个实例)

他们都会默认声明这个实体。

RabbitAdmin中的逻辑是这样的:

private <T extends Declarable> boolean declarableByMe(T dec) {
    return (dec.getDeclaringAdmins().isEmpty() && !this.explicitDeclarationsOnly) 
            || dec.getDeclaringAdmins().contains(this)
            || (this.beanName != null && dec.getDeclaringAdmins().contains(this.beanName));
}

另见 属性 描述:

/**
 * Set to true to only declare {@link Declarable} beans that are explicitly configured
 * to be declared by this admin.
 * @param explicitDeclarationsOnly true to ignore beans with no admin declaration
 * configuration.
 * @since 2.1.9
 */
public void setExplicitDeclarationsOnly(boolean explicitDeclarationsOnly) {

这是关于此事的文档:https://docs.spring.io/spring-amqp/docs/current/reference/html/#conditional-declaration