Search code examples
spring-rabbit

How to change SimpleMessageListenerContainer's connectionFactory


I want to change the connectionFactory of SimpleMessageListenerContainer at runtime,in other words,I want to modify the RabbitMQ's connection without restarting the app. although it provided a method "setConnectionFactory",I don't know if I can only do this.What should I do if I want to achieve my goal?


Solution

  • Call stop() on the listener container, then setConnectionFactory(), then start().

    You might want to call resetConnection() on the old factory to close its connection.