Hi,
We should more explicitly support this type of scenario. What I can suggest is to either set autoStartup to false in RabbitAdmin or avoid its use completely so that it doesn't perform any of the declarations and instead do it yourself in code. Not ideal. Perhaps a better short term approach is to subclass RabbitAdmin and override the start method so that only the Exchange,Queues, and Bindings specific to a given broker/connection will be used. Instead of the current code that get all the queues, i.e.
Code:
applicationContext.getBeansOfType(Queue.class).values();
It would instead use a lookup method that uses qualifier annotations to restrict the set of returned beans.
Code:
getBeansWithAnnotation(Class<? extends Annotation> annotationType)
comes close but one would also like to specify the class... a getBeanOfTypeWithAnnotation method.... Otherwise you will have to filter out from the returned map the beans which are queues, exchanges, bindings...
The @Configuration bean definitons would then have the qualifier annotation on them.
Code:
@Bean(name = "eventQueue2")
@Qualifier("broker2")
public Queue eventQueue() {
}
I don't think there is 'inheritance' of qualifier annotations on the @Configuration class to the methods, but that might be nice to consider.
Then one would need two instances of this subclass of RabbitAdmin, each configured to use different qualifier annotations.
HTH,
Mark