Vasanth
Vasanth

Reputation: 494

How to stop/start spring DefaultMessageListenerContainer?

I have developed project using Spring JMS to receive the message from Queue. and it is deployed Websphere application Server (WAS 7.5) clustered environment. it is working fine once it is deployed in server.Later i have update my logger information and deployed in to server. it seems server not picking the latest code base. Even though i have stop/start the cluster.

Please refer below config xml.

<bean id="connectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
            <property name="hostName" value="${hostName}"/>
            <property name="port" value="${port}"/>
            <property name="queueManager" value="${queueManager}"/>
            <property name="transportType" value="${transportType}"/>
            <property name="channel" value="${channel}"/> 
   </bean>

   <jms:listener-container container-type="default"
connection-factory="connectionFactory" acknowledge="auto" concurrency="5" >
<jms:listener destination="DEV.TESTQUEUE" ref="jmsMessageListener" 
</jms:listener-container>

 <bean id="jmsMessageListener" class="JmsMessageListener"/>


      public class JmsMessageListener implements MessageListener { 

    public void onMessage(Message message) {

      }
    }
Could you please advise how to stop/start the container? 

Upvotes: 2

Views: 4635

Answers (2)

whealthmax
whealthmax

Reputation: 83

Here is my solution:

final Map<String, DefaultMessageListenerContainer> containers = ctx.getBeansOfType(DefaultMessageListenerContainer.class);
        if (containers != null && !containers.isEmpty()) {
            for (DefaultMessageListenerContainer container : containers.values()) {
                container.stop();
            }
        }

Upvotes: 3

Vasanth
Vasanth

Reputation: 494

At last i found answer.

Default executor of DMLC is SimpleAsyncTaskExecutor.

SimpleAsyncTaskExecutor: This implementation does not reuse any threads, rather it starts up a new thread for each invocation. However, it does support a concurrency limit which will block any invocations that are over the limit until a slot has been freed up. If you’re looking for true pooling, keep scrolling further down the page. Spring Framework Task Execution and Scheduling.

So thread keep on running in container. this root cause of my issue. then i have restarted my JVM(with the support WAS Admin) and implemented ThreadPoolExecutor.

<jms:listener-container container-type="default"
connection-factory="connectionFactory" acknowledge="auto" concurrency="5" task-executor="taskExecutor">
<jms:listener destination="topCli_Service" ref="jmsMessageListener" 
</jms:listener-container>

<bean id="taskExecutor"
    class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="5" />
    <property name="maxPoolSize" value="10" />
    <property name="WaitForTasksToCompleteOnShutdown" value="true" />
</bean> 

Upvotes: 2

Related Questions