0

I want to know how can we add/delete some listener from listener container at run time.

I have configured listener container as below :

<rabbit:listener-container connection-factory="connectionFactory">
  <rabbit:listener ref="Listener0" queues="ListenerQueue0" />
  <rabbit:listener ref="Listener1" queues="ListenerQueue1" />
  <rabbit:listener ref="Listener2" queues="ListenerQueue2" />

One method comes to mind is we can add/remove 'rabbit:listener' from xml at run time and refresh application context, so new config will be loaded. Is this good way of doing ?

Please let me know other suggestions as well. Thanks in advance.

Rajat Goyal
  • 465
  • 1
  • 5
  • 20

1 Answers1

0

I would not use the approach you describe.

Each <rabbit:listener/> child element is actually a SimpleMessageListenerContainer, the <rabbit:listener-container/> is just syntactic sugar to provide common attributes for the "child" containers.

If your listener is a POJO (i.e. not a MessageListener), wrap it in a MessageListenerAdapter.

So, you can simply create a new SimpleMessageListenerContainer at runtime - be sure to call afterPropertiesSet() after configuring it and then start().

Gary Russell
  • 166,535
  • 14
  • 146
  • 179