我创建了一个演示项目:https://github.com/imram/si-errorhandling-sleuth。
我遇到的问题是,当我在Spring Integration Application中使用Spring Cloud Sleuth时,错误流就会中断,即网关无限停止/直到给出响应超时的超时为止,然后它将null返回给网关的调用者。
如果没有Sleuth依赖关系而执行相同的应用程序,则没有问题。
如果我的SI设置有问题或已知问题,请有人提供帮助。如果这是一个问题,那么有人可以建议解决方法吗?
仅供引用,我确实想在我的微服务中使用Sleuth生成每笔交易的关联ID,以实现可追溯性。
谢谢!!
最佳答案
侦探有问题了;我有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());
}
关于java - 与Spring Cloud Sleuth一起使用时,Spring Integration错误 channel 处理中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46971098/