Results 1 to 3 of 3

Thread: starting/stopping SimpleMessageListenerContainer

  1. #1
    Join Date
    Dec 2010
    Posts
    12

    Question 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.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    Make sure you have an up to date spring-rabbit jar and also that you have a broker with at least 2.3.1 (there was a bug in the broker in older versions).

  3. #3
    Join Date
    Dec 2010
    Posts
    12

    Default

    After ugrading my jar files

    <rabbitmq.version>2.3.1</rabbitmq.version>
    <spring-rabbit.version>1.0.0.M3</spring-rabbit.version>

    My logic to enable/diable the listener now works

    Thank you so much for your assistance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •