RequestHandlerRetryAdvice cannot be made to work with Ftp.outboundGateway in Spring Integration

前端 未结 1 1163
梦谈多话
梦谈多话 2021-01-23 08:35

My situation is similar to the one described in this SO question. The difference being that I don\'t use a WebFlux.outboundGateway but an Ftp.outboundGateway<

1条回答
  •  再見小時候
    2021-01-23 09:03

    Sorry for the delay; we are at SpringOne Platform this week.

    The problem is due to the fact that the gateway spec is a bean - the gateway ends up being initialized before the advice is applied.

    I changed your code like this...

    @Bean
    public IntegrationFlow downloadFiles(SessionFactory sessionFactory) {
        return f -> f.handle(getRemoteFile(sessionFactory), getRetryAdvice())
                .channel("gatewayDownloadsOutputChannel");
    }
    
    ...
    
    private RemoteFileOutboundGatewaySpec getRemoteFile(SessionFactory sessionFactory) {
        return Ftp.outboundGateway(sessionFactory,
                AbstractRemoteFileOutboundGateway.Command.GET,
                "payload")
                .fileExistsMode(FileExistsMode.REPLACE)
                .localDirectoryExpression("'/tmp'")
                .autoCreateLocalDirectory(true);
    }
    

    ...and it worked.

    It's generally better to not deal with Specs directly and just have them inlined in the flow definition...

    @Bean
    public IntegrationFlow downloadFiles(SessionFactory sessionFactory) {
        return f -> f.handle(Ftp.outboundGateway(sessionFactory,
                AbstractRemoteFileOutboundGateway.Command.GET,
                "payload")
                .fileExistsMode(FileExistsMode.REPLACE)
                .localDirectoryExpression("'/tmp'")
                .autoCreateLocalDirectory(true), getRetryAdvice())
            .channel("gatewayDownloadsOutputChannel");
    }
    

    0 讨论(0)
提交回复
热议问题