0

how can I add logs if file is transferred successfully. I want to log file name and some values form my config object

return IntegrationFlows.from(Sftp.inboundAdapter(inboundSftp)
            .localDirectory(this.getlocalDirectory(config.getId()))
            .deleteRemoteFiles(true)
            .autoCreateLocalDirectory(true)
            .remoteDirectory(config.getInboundDirectory()), e -> e.poller(Pollers.cron("0 */1 * ? * *").errorChannel(MessageHeaders.ERROR_CHANNEL).errorHandler((ex) -> {
        try {

            // exception handling here
    })))
            .handle(Sftp.outboundAdapter(outboundSftp)
                    .useTemporaryFileName(false)
                    .autoCreateDirectory(true)
                    .remoteDirectory(config.getOutboundDirectory()), c -> c.advice(startup.deleteFileAdvice())
            )
            .get();

Update after Gary Russell answer, my working code is

return IntegrationFlows.from(Sftp.inboundAdapter(inboundSftp)
            .localDirectory(this.getlocalDirectory(config.getId()))
            .deleteRemoteFiles(true)
            .autoCreateLocalDirectory(true)
            .remoteDirectory(config.getInboundDirectory()), e -> e.poller(Pollers.cron("0 */1 * ? * *").errorChannel(MessageHeaders.ERROR_CHANNEL).errorHandler((ex) -> {
           // action on exceptions are here
        }))).publishSubscribeChannel(s -> s
            .subscribe(f -> f
                .handle(Sftp.outboundAdapter(outboundSftp)
                        .useTemporaryFileName(false)
                        .autoCreateDirectory(true)
                        .remoteDirectory(config.getOutboundDirectory()), c -> c.advice(startup.deleteFileAdvice())
                ))
            .subscribe(f -> f
                .handle(m -> {
                    // all my custom logging logic is here
                })
            ))
            .get();
Umair
  • 119
  • 13

1 Answers1

2

Add a .publishSubscribeChannel() channel with 2 subflows. Docs here.

            .publishSubscribeChannel(s -> s
                    .subscribe(f -> f
                            .handle(...)
                    .subscribe(f -> f
                            .log())
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • 1
    But for this use-case case we need to have those two subscribers in sync and one by one. So, the second one for log won't be called if some failure happens in the first one. So, `publishSubscribeChannel()` should be configured without an `Executor`. – Artem Bilan Oct 17 '18 at 13:17
  • @GaryRussell I am facing an issue. If i give cron of every one hour in poller. it will pick all files after hours and transfer only one file instead of all.Transfer single file every hour. I was thing to check outbound cron but I am not sure its possible or not to give – Umair Aug 07 '19 at 06:48
  • Please don't ask new question in comments on old answers; it doesn't help people find questions/answers; you should always ask a new question. You need to increase `maxMessagesPerPoll` on the `poller` (it defaults to 1). – Gary Russell Aug 07 '19 at 14:26