本文介绍了弹簧集成+ cron +石英群集中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由cron表达式触发的弹簧集成流程,如下所示:

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-adptor集成在一起? 轮询器"的触发"属性仅接受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.

非常感谢!

推荐答案

这是一种方法...

将入站适配器上的auto-startup属性设置为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

  1. adapter.stop()
  2. trigger.reset()
  3. adapter.start()

这篇关于弹簧集成+ cron +石英群集中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:55