Spring AMQP with two ConnectionFactory

前提是你 提交于 2021-02-08 06:21:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!