So question is how to temporary stop and start a jms listener created using spring using the fallowing way :
You can assign an id to the listener-container. Then get a reference to it, either by calling getBean or getting it injected. This will give you a AbstractJmsListeningContainer on which you can call start / stop.
You can also get a hold of the messageListenerContainer, and invoke stop() on it:
@javax.annotation.Resource //autowire by name
private AbstractJmsListeningContainer myMessageListenerContainer;
myMessageListenerContainer.stop();
I'm using the more verbose setup of this container:
<bean id="myMessageListenerContainer" class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
<property name="destination" ref="myQueue"/>
<property name="messageListener" ref="myListener"/>
<property name="autoStartup" value="true" />
</bean>
Here you see that you can set autoStartup to false if you don't want the listenerContainer to automatically start.
Yes thats do the trick.
<jms:listener-container concurrency="1" connection-factory="exampleJmsFactory" destination-type="queue" message-converter="exampleMessageConverter">
<jms:listener id="exampleProductsMessageListener" destination="incoming.example.client.queue" ref="exampleProductsMessageConsumer" method="consume"/>
</jms:listener-container>
DefaultMessageListenerContainer exampleProductsMessageListener= Registry.getApplicationContext().getBean("exampleProductsMessageListener", DefaultMessageListenerContainer.class);
exampleProductsMessageListener.stop();