-1

I am using CachingConnectionFactory the setAddresses method for multiple clusters.

connection = new CachingConnectionFactory(); connection.setAddresses("rabbit1:5672,rabbit2:5672");

when i turn off cluster rabbit1 it starts on the next cluster rabbit2

my question there is some configuration to be able to return to the first cluster rabbit1, I have tried but I find how to solve it ..

Thank you

Oliver
  • 1
  • Can you please format the code using available code block option in edit mode to make it more readable. – Abhi.G May 06 '20 at 01:28

1 Answers1

0

The connection factory has a method to reset the connection.

factory.resetConnection()

The next open will start again at the beginning (unless shuffleAddresses has been set to true).

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • add resetConnection (), but when rabbit1 already reboots it doesn't go back to rabbit1, it stays in rabbit2 @Bean public ConnectionFactory connectionFactory() throws Exception { CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); connectionFactory.setAddresses("rabbit1:5672,rabbit2:5672"); connectionFactory.setUsername("admin"); connectionFactory.setPassword("admin"); connectionFactory.resetConnection(); return connectionFactory; } – Oliver May 06 '20 at 16:40
  • Don't put code in comments here; as you can see, it does not render well and is hard to read. Edit the question instead. It won't go back the first one automatically, you have to force closed the connection to rabbit2 by calling `resetConnection()`. Run your code in a debugger and put a breakpoint in `AbstractConnectionFactory.connect()`. – Gary Russell May 06 '20 at 17:07