Currently, no, not in the same application context; the RabbitAdmin auto-declares all the queues/exchanges it finds in the context; so it's the connection factory that's wired into the RabbitAdmin that is used.
Please feel free to open an 'Improvement' issue; https://jira.springsource.org/browse/AMQP
You may be able to work around the issue by simply not defining a <rabbit:admin/> in the main context, and do the declarations in smaller contexts that just live long enough to do the declarations. This will only work for durable queues and exchanges though.
Something like:
Code:
main-context.xml
<import "classpath:env1-context.xml" />
<import "classpath:env2-context.xml" />
...
env1-context.xml
<!-- queues and exchanges -->
<!-- connection factory -->
env2-context.xml
<!-- queues and exchanges -->
<!-- connection factory -->
bootstrap1-context.xml
<import "classpath:env1-context.xml" />
<rabbit:admin .../>
bootstrap2-context.xml
<import "classpath:env2-context.xml" />
<rabbit:admin .../>
Just be sure to fire up (and close) the two bootstrap contexts before the main context starts, so all the queues/exhanges are in place.
Actually, you really don't need to run them every time you start the main context; just run them as an admin process when the queues etc change.
Gary P. Russell
Spring Integration Team
SpringSource, a division of VMware