如何正常关闭Spring JMS MessageListenerAdapter [英] How to gracefully shut down a Spring JMS MessageListenerAdapter

查看:119
本文介绍了如何正常关闭Spring JMS MessageListenerAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个消息处理程序,该消息处理程序从JMS队列使用,并将结果发送到另一个JMS队列.消息处理程序位于Spring DefaultMessageListenerContainer中. 当容器关闭时,我希望它完成对它已经使用的所有请求的处理,并发送结果.同时,它不应再消耗来自请求队列的任何新消息.

I have a message handler, which consumes from a JMS queue and that sends results to another JMS queue. The message handler lives in a Spring DefaultMessageListenerContainer. When the container shuts down, I would like for it to finish handling any requests that it already consumed and send out the results. At the same time, it should no longer consume any new messages from the request queue.

现在,容器中没有特殊的关闭规定(安全的ApplicationContext.registerShutdownHook()),容器等待任何挂起的listernerMethod调用返回,但没有将结果发送到响应队列.

Right now, with no special shutdown provisions safe ApplicationContext.registerShutdownHook(), the container waits for any pending listernerMethod invocations to return, but it isn't sending out the results to the response queue.

什么是确保运行处理程序产生的响应被发送到响应队列的合适方法?

What would be the appropriate approach for making sure that responses produced by running handlers are sent to the response queue?

推荐答案

我认为方法必须通过DisposableBean接口或@PreDestroy注释进行.恕我直言,关键不是让Spring关闭DMLC,而是由知道当前系统内"消息的组件来完成此操作.这样,您就可以在等待当前处理的消息完成时停止监听新消息.

I think the way to go has to lead via DisposableBean interface or @PreDestroy annotation. The key thing IMHO is not to let Spring shut down the DMLC but rather let this being done by a component that is aware of messages currently "inside the system". This way you stop listening for new messages while waiting for currently proccessed messages to be finished.

使用bean声明上的depends-on属性,您还可以定义要关闭的bean的顺序. 春季参考文档.

Using the depends-on attribute on bean declarations you can also define the order of beans to be shut down. Red more on this in the Spring reference documentation.

这篇关于如何正常关闭Spring JMS MessageListenerAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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