简体   繁体   中英

Spring RabbitMQ reconnect to primary broker

I'm using a CachingConnectionFactory and after a primary broker goes down it connects to the secondary. After restarting the primary broker I want to reconnect to it. Can this be done automatically?

This is what I've tried and it doesn't work:

factory.setRecoveryListener(new RecoveryListener() {
  @Override
  public void handleRecovery(final Recoverable recoverable) {
    factory.resetConnection();
  }

  @Override
  public void handleRecoveryStarted(final Recoverable recoverable) {
    factory.resetConnection();
  }
});

Can the factory be setup to take care of resetting the connection after the primary broker is back up?

Spring AMQP doesn't use auto recovery and, in any case, that is not called just because the original broker is back online.

You need some external mechanism to detect the other broker is back online, and call resetConnection() from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM