Results 1 to 5 of 5

Thread: Unable to restart DefaultMessageListener after stopping via stop callback

Threaded View

  1. #1
    Join Date
    Jul 2010
    Posts
    10

    Default Unable to restart DefaultMessageListener after stopping via stop callback

    Hi All,

    I am developing an application which uses Spring's DefaultMessageListenerContainer to implement a MDP. As part of this application I have to implement a task which will run on a schedule (every x minutes) which I am implementing via Springs scheduledTasks support:

    Code:
    <task:scheduled-tasks scheduler="heartbeatScheduler">
        <task:scheduled ref="heartbeatService" method="processHeartbeat" cron="${heartbeat.cron}"/>
    </task:scheduled-tasks>
    
     <task:scheduler id="heartbeatScheduler" pool-size="1"/>
    Before this code executes it needs to stop/pause the JMS Listener container to avoid a potential race condition. As such I have attempted to implement this via the SmartLifecycle stop callback e.g:

    Code:
    messageListenerContainer.stop(new Runnable() {
    
                @Override
                public void run() {
                    LOGGER.info("JMS Container stopped executing task");
                    performTask();
                    LOGGER.info("Task complete starting JMS Container");
                    messageListenerContainer.start();
                }
    });
    The issue however is that although the messageListenerContainer.start(); is called and the container reports that it is both active and running, from checking the activemq console the JMS connection is never reinstated.

    If however I stop the container via the stop() callback and poll the container until the activeConsumerCount == 0 and then restart, the JMS Connection is reinstated correctly.

    My message listener container config is as follows:

    Code:
    <bean id="adapterListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <property name="connectionFactory" ref="jmsConnectionFactory"/>
            <property name="destinationName" value="${inbound.destination}" />
            <property name="messageListener" ref="messageListener" />
            <property name="transactionManager" ref="jmsTransactionManager" />
            <property name="maxConcurrentConsumers" value="${max.concurrent.consumers}" />
    </bean>
    Any help you could provide would be much appreciated.
    Last edited by pbray; Jun 21st, 2012 at 11:51 PM.

Tags for this Thread

Posting Permissions

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