We have currently Spring Boot applications which are using Spring Integration SFTP to send and receive files based on Cron schedule. We are trying to convert the applications to Azure Function using Spring Cloud Function. Just wondering is there any way to invoke the Spring Integration SFTP adapter to run just once when the application receive a http call from Azure Function? From Spring Integration's doc, seems the only options for the poller are either Cron or fixed-rate/fixed-delay. Thanks in advance for any helps or suggestions!
Asked
Active
Viewed 105 times
1 Answers
1
I wonder if you are OK to add an OnlyOnceTrigger
instead of cron or fixed fixed.
It's code could be like this:
public class OnlyOnceTrigger implements Trigger {
private final AtomicBoolean hasRun = new AtomicBoolean();
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
if (this.hasRun.getAndSet(true)) {
return null;
}
return new Date();
}
}
On the other hand, since you have a trigger like an event from that HTTP call, you should consider to use an SftpOutboundGateway
instead with get
or ls
command: https://docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/sftp.html#sftp-outbound-gateway

Artem Bilan
- 113,505
- 11
- 91
- 118
-
Thanks Artem. Our goal was trying to keep the modification to our existing code as less as possible. However, will try both approaches out as you suggested. Really appreciated it! – David Zhou Sep 22 '20 at 15:05
-
Yeah... With such a limitation as only HTTP trigger it is not going to be "as less as possible": you definitely need to adapt this or other way. The point of the `MessageSource` that it doesn't depend on any event and can do an action according its poller configuration periodically. What you have with that HTTP function fully doesn't fit to the poller model, not otherwise. That's why I suggest a gateway approach to align with the function signature. – Artem Bilan Sep 22 '20 at 15:10