使用Spring启动和停止JMS侦听器 [英] Start and Stop JMS Listener using Spring

查看:115
本文介绍了使用Spring启动和停止JMS侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以问题是如何使用休假方式临时停止和启动使用spring创建的jms侦听器:

So question is how to temporary stop and start a jms listener created using spring using the fallowing way :

<amq:connectionFactory id="exampleJmsFactory" brokerURL="tcp://${jms.broker.url}" />

<jms:listener-container concurrency="1" connection-factory="exampleJmsFactory"  destination-type="queue" message-converter="exampleMessageConverter">
        <jms:listener destination="incoming.example.client.queue" ref="exampleProductsMessageConsumer" method="consume"/>
</jms:listener-container>


<bean id="exampleProductsMessageConsumer" class="com.unic.example.jms.receive.JmsExampleProductsMessageConsumer" scope="tenant"/>

那么基本上是什么问题.我们确实有一个init/update机制,客户端可以在任何时间运行,并且在此init/update期间我想停止使用任何消息,因为此时系统无法使用,并且如果出现消息,它将丢失.

So basically what is the problem. We do have an init/update mechanism that the client can run in any time and durring this init/update I want to stop consuming of ANY messages because the system is unusable in this time and if a message came it will be lost.

因此,如何使用API​​停止侦听器或侦听器容器或整个连接.我发现一个类AbstractJmsListeningContainer具有停止/启动功能,但是我如何获取呢?我的意思是这些jms都不是:侦听器和侦听器容器都没有名称或类似名称.

So how I can stop the listener or the listener container or the whole connection using the API. I found that a class AbstractJmsListeningContainer have stop/start but how I can get it ? I mean none of this jms: listener and listener-containers have a name or anything like that.

推荐答案

您可以为监听器-容器分配一个ID.然后通过调用getBean或注入它来获取对它的引用.这将为您提供一个AbstractJmsListeningContainer,您可以在其上调用start/stop.

You can assign an id to the listener-container. Then get a reference to it, either by calling getBean or getting it injected. This will give you a AbstractJmsListeningContainer on which you can call start / stop.

这篇关于使用Spring启动和停止JMS侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆