集群中的 spring 集成 + cron + 石英? [英] spring integration + cron + quartz in cluster?
问题描述
我有一个由 cron 表达式触发的 spring 集成流程,如下所示:
I have a spring integration flow triggered by the cron expression like follows:
<int-ftp:inbound-channel-adapter id="my-input-endpoint" ...>
<int:poller trigger="my-trigger"/>
</int-ftp:inbound-channel-adapter>
<bean id="my-trigger"
class="org.springframework.scheduling.support.CronTrigger">
<constructor-arg value="0 * * * * *" />
</bean>
它工作正常.但现在我必须扩展实现以使其集群就绪(同时仅在一个集群节点上执行作业).
It works fine. But now I have to extend the implementation to make it cluster ready (job execution on only one cluster node at the same point of time).
我的愿望是在集群模式下使用 Quartz 框架(将作业状态保留在数据库中)来触发此集成流程.Quartz 提供了一个开箱即用的美丽解决方案.唯一的问题是如何将 Quartz 与现有的 inbout-channer-adaptor 集成?poller"的trigger"属性只接受org.springframework.scheduling.Trigger的子类.我在轮询触发器"和 Quartz 框架之间找不到任何桥梁.
My wish would be to use the Quartz framework in the cluster mode (persisting the job status in the database) to trigger this integration flow. Quartz provides a beautful solution out of the box. The only problem is how to integrate the Quartz with the existing inbout-channer-adaptor? The "trigger" attribute of the "poller" accepts only the subclasses of the org.springframework.scheduling.Trigger. I could not find any bridge between "poller trigger" and the Quartz framework.
非常感谢!
推荐答案
这是一种方法...
将入站适配器上的自动启动属性设置为 false.
Set the auto-startup attribute on the inbound-adapter to false.
创建一个只触发一次的自定义触发器,立即...
Create a custom trigger that only fires once, immediately...
public static class FireOnceTrigger implements Trigger {
boolean done;
public Date nextExecutionTime(TriggerContext triggerContext) {
if (done) {
return null;
}
done = true;
return new Date();
}
public void reset() {
done = false;
}
}
在您的石英作业中,获取对触发器和 SourcePollingChannelAdapter
的引用.
In your quartz job, get a reference to the trigger and the SourcePollingChannelAdapter
.
当石英触发器触发时,让石英工作
When the quartz trigger fires, have the quartz job
- 适配器.stop()
- trigger.reset()
- 适配器.start()
这篇关于集群中的 spring 集成 + cron + 石英?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!