Announcement Announcement Module
No announcement yet.
Enabling Disabling AMQP Message Listener Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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.

    <bean id="messageListenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer" scope="session">
    		<property name="connectionFactory" ref="connectionFactory" />		
    	<property name="queueName" value=""/>
    	    <property name="concurrentConsumers" value="1" />
    	    <property name="messageListener" ref="messageListenerAdapter" />
    	    <property name="autoStartup" value="false" />
    <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 id="messageListenerAdapter" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter" >
    		<property name="delegate" ref="msgHandler" />		
    	<bean id="msgHandler" class="com.catmktg.digitalgateway.consumer.asynch.MessageHandler">	   
    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
    pplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
    SimpleMessageListenerContainer sml = (SimpleMessageListenerContainer) applicationContext.getBean("messageListenerContainer");
    Code To disable the listener
    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.