Spring integration mail poller

懵懂的女人 提交于 2019-12-06 03:57:04

I can suggest to you OnlyOnceTrigger:

@Bean
public Trigger onlyOnceTrigger() {
       return new Trigger() {
              private final AtomicBoolean invoked = new AtomicBoolean();
              @Override
              public Date nextExecutionTime(TriggerContext triggerContext) {
                    return this.invoked.getAndSet(true) ? null : new Date();
              }
       };
}

Which should be injected to your <int:poller> of that adapter.

However you should take care about some barrier for the entire application if you say that it is standalone one and you really shouldn't lose process before you decide to close the app.

One of those good choice is CountDownLatch with 1 count as a bean. You should wait on it from your main before System.exit(0) or just use the last one in the end of your process:

<outbound-channel-adapter expression="T(System).exit(0)"/>

However you should think more if it really is suitable for your to run the adapter only once and if that max-messages-per-poll="1" is really good option.

There may be no messages in the mail box, so onlyOnceTrigger may finish without good result for you and your app has strained into the void...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!