Spring集成JavaDSL:处理错误/异常的策略?

Spring集成JavaDSL:处理错误/异常的策略?,java,spring,spring-integration,spring-integration-dsl,Java,Spring,Spring Integration,Spring Integration Dsl,如何处理JavaDSL流中的错误 假设我有一个简单的流,可以写入Rabbit(或数据库) 这样的操作可能会由于数据库问题或中间连接故障而导致错误 如果“publishToRabbit”步骤中发生异常,我如何增强对所采取操作的流声明 如果你谈论重试和类似的问题,你应该考虑一下 另一方面,.handle()有第二个参数-endpoint configurer。您可以指定.advice(): .handle((GenericHandler)(p,h)->{ 抛出新的RuntimeException(“

如何处理JavaDSL流中的错误

假设我有一个简单的流,可以写入Rabbit(或数据库)

这样的操作可能会由于数据库问题或中间连接故障而导致错误


如果“publishToRabbit”步骤中发生异常,我如何增强对所采取操作的流声明

如果你谈论重试和类似的问题,你应该考虑一下

另一方面,
.handle()
有第二个参数-endpoint configurer。您可以指定
.advice()

.handle((GenericHandler)(p,h)->{
抛出新的RuntimeException(“故意”);
},e->e.advice(retryAdvice())
@豆子
public RequestHandlerRetryAdvice retryAdvice(){
RequestHandlerRetryAdvice RequestHandlerRetryAdvice=新建RequestHandlerRetryAdvice();
setRecoveryCallback(新的ErrorMessageSendingRecoverer(recoveryChannel());
返回请求HandlerRetryAdvice;
}

为什么不简单地将异常记录在
publishToRabbit
方法中呢?简单地记录是不够的,我可能想调用一些逻辑来稍后重新尝试发送。另外,如果您的
publishToRabbit
使用
RabbitTemplate
,您可以使用
RetryTemplate
对其进行配置。谢谢,如果我只需要处理一个错误,我如何配置它?关于这个问题,有
expressionevaluationrequesthandleradvice
@Bean
public IntegrationFlow setupRabbitFlow() {
    return IntegrationFlows.from(publishSubscribeChannel)
            .handle((p, h) -> rabbitPublishActivator.publishToRabbit(p))
            .get();
}
.handle((GenericHandler<?>) (p, h) -> {
                    throw new RuntimeException("intentional");
                }, e -> e.advice(retryAdvice()))

    @Bean
    public RequestHandlerRetryAdvice retryAdvice() {
        RequestHandlerRetryAdvice requestHandlerRetryAdvice = new RequestHandlerRetryAdvice();
        requestHandlerRetryAdvice.setRecoveryCallback(new ErrorMessageSendingRecoverer(recoveryChannel()));
        return requestHandlerRetryAdvice;
    }