I've configured an imap channel-adapter to receive mail with 20000 fixed delay. So it's working as expected. But the problem is, it's running continuously. So I have a couple of questions:
Thanks in advance for your help.
<int-mail:imap-idle-channel-adapter id="customAdapter"
store-uri="imaps://[userid]:[pasword]@imap.gmail.com:993/inbox"
channel="receiveChannel"
auto-startup="true"
should-delete-messages="false"
should-mark-messages-as-read="false"
java-mail-properties="javaMailProperties"auto-startup="false">
<int:poller max-messages-per-poll="10" fixed-delay="20000"/>
Start and stop can be controlled via Control Bus component.
You can even stop that adapter from downstream flow by some condition and sending a message to the same Control Bus channel.
If you need to run it only once, you can consider a trigger
option instead of fixed-delay
and implement it like:
private final AtomicBoolean invoked = new AtomicBoolean();
public Date nextExecutionTime(TriggerContext triggerContext) {
return this.invoked.getAndSet(true) ? null : new Date();
}
Return something to main you can via simple CountDonwLatch
and some AtomicBoolean
(or Reference
) bean.
Sorry, so much questions in one topic... That isn't appropriate for SO.