简体   繁体   English

中断石英集群中的工作

[英]Interrupting a job in quartz cluster

I have a Quartz setup with multiple instances and I want to interrupt a job wherever it is executed.我有一个包含多个实例的 Quartz 设置,我想在执行作业的任何地方中断它。 As it was said in documentation, Scheduler.interrupt() method is not cluster aware so I'm looking for some common practice to overcome such limitation.正如文档中所说, Scheduler.interrupt()方法不是集群感知的,所以我正在寻找一些常见的做法来克服这种限制。

Well, here are some basics you should use to achieve that. 好吧,这里有一些你应该用来实现它的基础知识。

When running in cluster mode, the information about the currently running jobs are available in the quartz tables. 在群集模式下运行时,石英表中提供了有关当前正在运行的作业的信息。 For instance, the q_fired_triggers contains the job being executed. 例如, q_fired_triggers包含正在执行的作业。 The first column of this table is the scheduler name being in charge of it. 该表的第一列是负责它的调度程序名称。 So it is pretty easy to know who is doing what. 所以很容易知道谁在做什么。

Then, if you enable the JMX export of your quartz instances org.quartz.scheduler.jmx.export , the MBeans you will enable a new entry point to remotely manage each scheduler individually. 然后,如果启用石英实例org.quartz.scheduler.jmx.export的JMX导出,则MBean将启用新的入口点以单独远程管理每个调度程序。 The MBean provides a method boolean interruptJob("JobName", "JobGroup") MBean提供了一个方法boolean interruptJob("JobName", "JobGroup")

Then you " just " need to call this method on the appropriated scheduler instance to effectively interrupt it. 然后你“ 只需 ”在适当的调度程序实例上调用此方法以有效地中断它。

I tried all the process manually and it works fine, just need to be automatized :) 我手动尝试了所有的过程,它工作正常,只需要自动化:)

HIH HIH

You are right.你是对的。 The Scheduler.interrupt() does not work in the cluster mode. Scheduler.interrupt()在集群模式下不起作用。 Let's say that a job trigger is fired by a scheduler in a node but this API is called in another node.假设作业触发器由节点中的调度程序触发,但此 API 在另一个节点中被调用。

To overcome this, you might use the message broker approach (eg JMS, RabbitMQ, etc.) with publish/subscribe model. Instead of calling Scheduler.interrupt() , the client sends a message of this interruption to the message broker, the payload of the message consists of the identity of the job detail ie JobKey and the name of scheduler ((if there are multiple schedulers used in a node). Then, the message is consumed by all nodes in which the Quartz instance is running, and the nodes find Quartz scheduler by name and then executes Scheduler.interrupt() of the found scheduler with the identity of the job detail taken from the message payload.为了克服这个问题,您可以使用消息代理方法(例如 JMS、RabbitMQ 等)和发布/订阅 model。客户端不会调用Scheduler.interrupt() ,而是将此中断的消息发送到消息代理,有效负载消息的组成包括作业细节的身份,即JobKey和调度程序的名称((如果一个节点中使用了多个调度程序)。然后,该消息被运行 Quartz 实例的所有节点消费,并且节点按名称查找 Quartz 调度程序,然后使用从消息有效负载中获取的作业详细信息的标识执行找到的调度程序的Scheduler.interrupt()

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

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