Spring Integration FTP Outbound: How to multiple FTP host sequentially in case of failure

Refresh

April 2019

Views

30 time

1

I have a primary ftp host A and secondary ftp host B. If the ftp outbound A fails then I need to perform ftp outbound to B. Currently my IntegraitonFlow DSL performs the following logic * Perform FTP to primary host A -> On SUCCESS expression advice delete local temp files -> On FAILURE expression advice display error message

How do i tweak the failure advice to perform FTP to host B

My DSL looks like this

@Bean
public IntegrationFlow jmsInboundFlow(DefaultMessageListenerContainer myJmsListenerContainerFactory,
        SessionFactory<FTPFile> sessionFactory) {
    return IntegrationFlows.from(Jms.messageDrivenChannelAdapter(myJmsListenerContainerFactory))
            .handle(generateFilesToFtp())
            .split(splitEachFileToSeperateMessage)
            .channel(c -> c.executor(Executors.newCachedThreadPool()))
            .handle(Ftp.outboundAdapter(sessionFactory)
                    .remoteDirectory("/")
                    .useTemporaryFileName(false),
                    c -> c.advice(expressionAdvice(c))
            )
            .get();
}

@Bean
public Advice expressionAdvice(GenericEndpointSpec<FileTransferringMessageHandler<FTPFile>> c) {
    ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
    advice.setOnSuccessExpressionString("payload.delete()");
    advice.setOnFailureExpressionString("payload + ' failed to upload'");
    advice.setTrapException(true);
    return advice;
}

0 answers