Issue
I want to declare Queue
and Exchange
, which RabbitAdmin
instance is being selected if I do not call the setAdminsThatShouldDeclare
on Queue or Exchange:
@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;
}
There are multiple RabbitMQ connections in the application (multiple RabbitAdmin
instances)
Solution
All of them are going to declare this entity by default.
The logic in the RabbitAdmin
is like this:
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));
}
See also that property description:
/**
* 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) {
Here is a doc on the matter: https://docs.spring.io/spring-amqp/docs/current/reference/html/#conditional-declaration
Answered By - Artem Bilan