Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

spring - Not able to Stop MQueue listener

I have the following configuration for my MQueue:

<jms:listener-container container-type="default" connection-factory="cachedConnectionFactory" acknowledge="auto">
    <jms:listener id="myListenerId" destination="myDestination" ref="myListener" method="onMessage" />
</jms:listener-container>

When I try to stop the reception of JMS messages, I write the following code

jmsManagement = myProject.instance.getContext().getBean('myListenerId',Lifecycle.class);
jmsManagement.stop();

PS :

  • When I stop() my listener, the isRunning() return False, but I still get messages through the MQueue... the onMessage gets triggered.
  • jmsManagement is an instance of the class Lifecycle. Even when I changed it to DefaultMessageListenerContainer, same thing.
  • I'm receiving messages before calling start(), even when autoStartup is set to false.
  • jmsManagement.shutdown(); didn't stop the listener from being triggered.

Does anyone have an idea about how to stop this MQ listener ? Is there something I'm missing ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I actually had to set autoStartup to true.

Since I can't do that using jms:listener-container, I instanciated a DefaultMessageListenerContainer bean and set the autoStartup property to false.

Here's the code that worked for me :

<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer"  id="pitagorCPYListener">
    <property name="autoStartup" value="false" />
    <property name="connectionFactory" ref="cachedConnectionFactory" />
    <property name="destination" ref="defaultDestination" />
    <property name="messageListener" ref="listenerPitagorCPY" />
</bean>

 <bean id="defaultDestination" class="com.ibm.mq.jms.MQQueue">
    <constructor-arg value="#{mqConnectionFactory.destination}"/>
  </bean>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...