问题
I am using spring integration SFTP protocol to transfer files on remote inbound and outbound servers.It works fine when my remote inbound server directory contains any file but it does not response when my remote server directory is empty means there is no file.I am using following piece of code
IntegrationFlows.from(Sftp.inboundAdapter(inboundSftp)
.localDirectory(this.getlocalDirectory(config.getId()))
.deleteRemoteFiles(true)
.autoCreateLocalDirectory(true)
.filter(new CompositeFileListFilter().addFilter(new LastModifiedLsEntryFileListFilter(config.getRegexFilter())))
.remoteDirectory(config.getInboundDirectory())
, e -> e.poller(Pollers.cron(config.getCron())
.errorChannel(MessageHeaders.ERROR_CHANNEL).errorHandler((ex) -> {
})))
I just want to put on console log message such that when there is empty remote directory it must says that Empty Remote Directory or No Files Found. I have wasted a lot of my time on this issue and nothing is fruitful thing found. Please help me is there any way we can check that directory.empty() and prints our message.
回答1:
The Sftp.inboundAdapter(inboundSftp)
is a SourcePollingChannelAdapter
based on a scheduled task according poller configuration. It really produces nothing into an outputChannel
if there is no data from the source to build a message. But the point is that a task on trigger is still performed and we have some hooks how to catch that phase.
For this purpose we have an AbstractMessageSourceAdvice
component for its afterReceive()
implementation. This is a place where you can perform your "Empty Remote Directory" logic. Such an Advice
then has to be injected in the poller(Pollers...advice())
.
See more info in Docs: https://docs.spring.io/spring-integration/docs/5.3.0.M4/reference/html/core.html#conditional-pollers
回答2:
Use the outbound gateway (with LS command) to get a list of remote files. You will get an empty list if there are none.
来源:https://stackoverflow.com/questions/61201149/spring-integration-flow-api-does-not-response-when-empty-remote-directory