Search code examples
spring-integrationspring-integration-dslspring-integration-sftp

Spring Integration Flow Logging When No File Found


I already have a working IntegrationFlow

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) -> {
               }))).publishSubscribeChannel(s -> s
                .subscribe(f -> {
                    ............
                })
                .subscribe(f -> {
                    .......

                })
                .subscribe(f -> f
                        .......
                ))
                .get();

I am trying to log when there is no file exists on source directory. I tried to use LastModifiedLsEntryFileListFilter but its fired only when it found a file on server.


Solution

  • Although the question Spring Integration Flow API does not response when empty remote directory comes from another user, it looks like you both talk about the same project and the same problem.

    I can't close this your question because there is no vote on my answer over there yet, so I just copy/paste my answer here as well.

    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