如何停止/启动/暂停@JmsListener(干净的方法) [英] How can I Stop/start/Pause a @JmsListener (the clean way)
本文介绍了如何停止/启动/暂停@JmsListener(干净的方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在项目上使用Spring(boot),并且使用以下命令访问JMS队列(ActiveMQ):
I am using Spring(boot) on my project and I access a JMS Queue (ActiveMQ) using :
@JmsListener(destination = "mydestinationQueue")
public void processMessage(String content) {
//do something
}
它运行良好,但是我需要能够以编程方式(REST调用或类似的东西)停止/暂停/启动此bean
And it works perfectly but I need to be able to stop/pause/start this bean programatically (a REST call or something like that)
当我停止或暂停该bean时,我想确保已完全处理了当前消息.
When I stop or pause this bean I want to be sure to have fully processed the current message.
对此有任何想法吗?
谢谢
推荐答案
这是我找到的解决方案
@RestController
@RequestMapping("/jms")
public class JmsController {
@Autowired
ApplicationContext context;
@RequestMapping(value="/halt", method= RequestMethod.GET)
public @ResponseBody
String haltJmsListener() {
JmsListenerEndpointRegistry customRegistry =
context.getBean("jmsRegistry", JmsListenerEndpointRegistry.class);
customRegistry.stop();
return "Jms Listener Stopped";
}
@RequestMapping(value="/restart", method=RequestMethod.GET)
public @ResponseBody
String reStartJmsListener() {
JmsListenerEndpointRegistry customRegistry =
context.getBean("jmsRegistry", JmsListenerEndpointRegistry.class);
customRegistry.start();
return "Jms Listener restarted";
}
@RequestMapping(value="/stopApp", method=RequestMethod.GET)
public @ResponseBody
String stopApp() {
String[] args={};
SpringApplication.run(FacturationApplicationFrontDaemon.class, args).close();
return "stopped";
}
}
这篇关于如何停止/启动/暂停@JmsListener(干净的方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文