简体   繁体   English

在应用程序启动和关闭时管理JMS消息容器

[英]Managing JMS Message Containers on Application Startup and Shutdown

Currently, we have four JMS listener containers that are started during the application start. 目前,我们有四个在应用程序启动期间启动的JMS侦听器容器。 They all connect through Apache ZooKeeper and are manually started. 它们都通过Apache ZooKeeper连接并手动启动。 This becomes problematic when a connection to ZooKeeper cannot be established. 当无法建立与ZooKeeper的连接时,这会成为问题。 The (Wicket) application cannot start, even though it is not necessary for the JMS listeners be active to use the application. (Wicket)应用程序无法启动,即使JMS侦听器不必处于活动状态以使用该应用程序。 They simply need to listen to messages in the background, save them and a cron job will process them in batches. 他们只需要在后台监听消息,保存它们,而cron作业将分批处理它们。

Goals : 目标

  1. Allow the application to start and not be prevented by the message containers not being able to connect. 允许应用程序启动,而不会被消息容器无法连接阻止。
  2. After the application starts, start the message listeners. 应用程序启动后,启动消息侦听器。
  3. If the connection to one or any of the message listeners goes down, it should attempt to automatically reconnect. 如果与一个或任何消息侦听器的连接中断,则应尝试自动重新连接。
  4. On application shutdown (such as the Tomcat being shutdown), the application should stop the message listeners and the cron job that processes the saved messages. 在应用程序关闭(例如Tomcat正在关闭)时,应用程序应该停止消息侦听器和处理已保存消息的cron作业。
  5. Make all of this testable (as in, be able to write integration tests for this setup). 使所有这些都可测试(例如,能够为此设置编写集成测试)。

Current Setup : 当前设置

  1. Spring Boot 1.5.6 Spring Boot 1.5.6
  2. Apache ZooKeeper 3.4.6 Apache ZooKeeper 3.4.6
  3. Apache ActiveMQ 5.7 Apache ActiveMQ 5.7
  4. Wicket 7.7.0 Wicket 7.7.0

Work done so far : 迄今为止完成的工作

  1. Define a class that implements ApplicationListener<ApplicationReadyEvent> . 定义一个实现ApplicationListener<ApplicationReadyEvent>
  2. Setting the autoStart property of the DefaultMessageListenerContainer to false and start each container in the onApplicationEvent in a separate thread. 设置autoStart的财产DefaultMessageListenerContainer为假,并开始在每个容器onApplicationEvent在一个单独的线程。

Questions : 问题

  1. Is it necessary to start each message container in its own thread? 是否有必要在自己的线程中启动每个消息容器? This seems to be overkill, but the way the "start" process works is that the DefaultMessageListenerContainer is built for that listener and then it is started. 这似乎有些过分,但“启动”过程的工作方式是为该侦听器构建DefaultMessageListenerContainer然后启动它。 There is a UI component that a user can use to start/stop the message listeners if need be, and if these are started sequentially in one thread, then the latter three message containers could be null if the first one has yet to connect on startup. 如果需要,用户可以使用UI组件来启动/停止消息侦听器,如果这些组件在一个线程中按顺序启动,那么如果第一个消息容器在启动时尚未连接,则后三个消息容器可以为null 。
  2. How do I accomplish goals 4 and 5? 我如何实现目标4和5?

Of course, any commments on whether I am on the right track would be helpful. 当然,关于我是否在正确的轨道上的任何提交都会有所帮助。

If you do not start them in a custom thread then the whole application cannot be fully started. 如果您不在自定义线程中启动它们,则无法完全启动整个应用程序。 It is not just Wicket, but the Servlet container won't change the application state from STARTING to STARTED due to the blocking request to ZooKeeper. 它不仅仅是Wicket,而且由于对ZooKeeper的阻塞请求,Servlet容器不会将应用程序状态从STARTING更改为STARTED。

Another option is to use a non-blocking request to ZooKeeper but this is done by the JMS client (ActiveMQ), so you need to check whether this is supported in their docs (both ActiveMQ and ZooKeeper). 另一种选择是对ZooKeeper使用非阻塞请求,但这是由JMS客户端(ActiveMQ)完成的,因此您需要检查它们的文档(ActiveMQ和ZooKeeper)是否支持它。 I haven't used those in several years, so I cannot help you more. 我好几年没用过了,所以我帮不了你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM