spring integration + cron + quartz in cluster?

前端 未结 4 531
猫巷女王i
猫巷女王i 2020-12-01 15:23

I have a spring integration flow triggered by the cron expression like follows:


    <         


        
4条回答
  •  一生所求
    2020-12-01 15:45

    Here's one way...

    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;
        }
    }
    

    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()

提交回复
热议问题