Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring AMQP with two ConnectionFactory

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?

like image 906
jandres Avatar asked Aug 29 '26 21:08

jandres


1 Answers

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.

like image 71
Gary Russell Avatar answered Sep 01 '26 10:09

Gary Russell