我的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>
当我尝试停止接收 JMS 消息时,我编写以下代码
jmsManagement = myProject.instance.getContext().getBean('myListenerId',Lifecycle.class);
jmsManagement.stop();
附言 :
- 当我
stop()
我的侦听器时,isRunning()
返回 False,但我仍然通过 MQueue 收到消息......onMessage
被触发。 -
jmsManagement
是类Lifecycle
的一个实例。即使我把它改成DefaultMessageListenerContainer
,也是一样。 - 我在呼叫
start()
之前收到消息,即使autoStartup
设置为 false。 -
jmsManagement.shutdown();
并没有阻止听众被触发。
有没有人知道如何停止这个 MQ 侦听器?我错过了什么吗?
我实际上必须将autoStartup
设置为 true。
由于我不能使用 jms:listener-container
来做到这一点,我实例化了一个DefaultMessageListenerContainer
bean 并将 autoStartup
属性设置为 false。
这是对我有用的代码:
<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>