Spring 与 Spring Cloud Sleuth 一起使用时集成错误通道处理中断

Spring Integration Error Channel Handling Broken when used with Spring Cloud Sleuth

我创建了一个演示项目:https://github.com/imram/si-errorhandling-sleuth

我遇到的问题是,当我在我的 Spring 集成应用程序中使用 Spring Cloud Sleuth 时,错误流被破坏,即网关无限停止/直到超时(如果给出回复超时)然后它returns 对网关的调用者为 null。

如果在没有 Sleuth Dependency 的情况下执行相同的应用程序,则没有问题。

如果我的 SI 设置或已知问题有问题,有人可以提供帮助吗?如果这是一个问题,那么有人可以建议解决方法吗?

仅供参考,我确实想使用 Sleuth 为每笔交易生成 Correlation Id b/w 我的微服务用于可追溯性目的。

谢谢!!

这是 Sleuth 的问题;我有 raised an issue there.

编辑

这里有一个解决方法 - 有点俗气但它有效...

public class SleuthWorkAroundInterceptor extends ChannelInterceptorAdapter {

    @Override
    public Message<?> preSend(Message<?> message, MessageChannel channel) {
        if (!(message instanceof ErrorMessage)) {
            return message;
        }
        MessagingException payload = (MessagingException) message.getPayload();
        Message<?> failedMessage = payload.getFailedMessage();
        failedMessage = MessageBuilder.fromMessage(failedMessage)
                .removeHeader(MessageHeaders.REPLY_CHANNEL)
                .removeHeader(MessageHeaders.ERROR_CHANNEL)
                .build();
        return new ErrorMessage(new MessagingException(failedMessage, payload), message.getHeaders());
    }

}

@Bean
public SmartInitializingSingleton ecInterceptorConfigurer(AbstractMessageChannel errorChannel) {
    return () -> errorChannel.addInterceptor(0, new SleuthWorkAroundInterceptor());
}