问题
I have an application with two ConnectionFactory (different brokers). They are configured with java classes:
@Bean
public ConnectionFactory ...
@Bean
public Queue ...
...
In rabbittemplate you can indicate the connection, but not in queues or in the exchanges, so they are being created in the two connections. Do I have to use RabbitAdmin to create queues in only one of the two connections? is there any other way?
回答1:
See the documentation : Conditional Declaration.
Starting with the 1.2 release, it is possible to conditionally declare these elements. This is particularly useful when an application connects to multiple brokers and needs to specify with which broker(s) a particular element should be declared.
You need a RabbitAdmin
for each connection factory and use declared-by
to indicate which admin(s) should declare each queue/exchange/binding.
来源:https://stackoverflow.com/questions/34416404/spring-amqp-with-two-connectionfactory