Announcement Announcement Module
Collapse
No announcement yet.
Enabling Disabling AMQP Message Listener Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Enabling Disabling AMQP Message Listener

    I have defined a messageListenerContainer (session scoped) within my webapplication and disabled the startup ofthe listener on deployment of the webapp in tomcat.

    Code:
    <bean id="messageListenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer" scope="session">
    		<property name="connectionFactory" ref="connectionFactory" />		
    	<property name="queueName" value="anu.cbs.push.queue"/>
    	    <property name="concurrentConsumers" value="1" />
    	    <property name="messageListener" ref="messageListenerAdapter" />
    	    <property name="autoStartup" value="false" />
    	      
    	</bean>
    
    <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="messageListenerAdapter" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter" >
    		<property name="delegate" ref="msgHandler" />		
    	</bean>
    	
    	<bean id="msgHandler" class="com.catmktg.digitalgateway.consumer.asynch.MessageHandler">	   
    	</bean>
    IMy web application code provides links to disable and enable the listener. From what I'm observing the enabling logic works but disabling the listener seems to be incorrect.

    Code To enable the listener
    Code:
    pplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
    
    SimpleMessageListenerContainer sml = (SimpleMessageListenerContainer) applicationContext.getBean("messageListenerContainer");
    
    sml.start();
    Code To disable the listener
    Code:
    sml.stop();
    Upon disabling the listener I am not able to place messages on the queue. It seems the listener is still enabled.

    Am i using the correct logic to enable/disable listeners?

  • #2
    I would also like to comment on the behaviour of messages on the queue.

    1- I place 500 messages on the queue.
    2 - I deploy the webapplication with the listener autostartup set to false
    3 - I enable the listener via my web application (calling the start() method)
    4 - All messages on the queue are consumed by the listener (I have verified this by logging the messages being picked up by the consumer)
    5 - I disable the listener by calling the stop() method on the listener
    6 - I now place another 500 messages on the queue
    7 - I enable the listener (calling start() method) and I only see one message being picked up from the queue.

    I have my listener set to session scope so that there is always one instance of the listener that is being enabled/disabled.

    Comment

    Working...
    X