starting/stopping SimpleMessageListenerContainer
Could I please get some advice on how I should implement functionality to enable a "org.springframework.amqp.rabbit.listener.SimpleMe ssageListenerContainer" to "start" and "stop" picking up messages from a queue.
I have implemented a spring web application which defines the following within an application Context file.
Code:
<bean id="connectionFactory"
class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory">
<constructor-arg value="localhost" />
<property name="username" value="guest" />
<property name="password" value="guest" />
</bean>
<bean id="messageListenerContainer"
class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="queueName" value="cbs.push.queue" />
<property name="concurrentConsumers" value="1" />
<property name="messageListener" ref="cbsListener" />
<property name="channelTransacted" value="true" />
<property name="autoStartup" value="false" />
</bean>
<bean id="cbsListener"
class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
<property name="delegate" ref="msgController" />
</bean>
I place 10 messages on the queue and enable the listener by doing the following.
Code:
SimpleMessageListenerContainer sml = null;
try{
sml = (SimpleMessageListenerContainer) applicationContext.getBean("messageListenerContainer");
sml.start();
}catch(Exception e){
logger.debug("*******AppController.handleRequestInternal() -- Unable to retrieve messageListenerContainer");
}
I disable the listener in a similar fashion by calling
sml.stop();
The first time I enable/disable the listener everything seems to be working fine. However, when I attempt to enable the listener a second time the messages are not being picked up from the queue. I don't see any exceptions in my log.
Any advice on how i could modify my implementation to have control over the listener would be greatly appreciated.