Spring 集成网关退出 "due to an exception" 并且在处理错误后未收到回复

Spring Integration Gateway exiting "due to an exception" and not receiving reply after error is handled

嘿,我正在将消息发送到 http 端点,因为我必须在选择性失败时触发错误流,所以我通过网关发送消息,然后最终通过 http 出站网关路由它。

@MessagingGateway(errorChannel="invocationFailureChannel")
public interface Invocator {
    @Gateway(requestChannel="invocationChannel")
    public Boolean invokeService(Message<String> invocation);
}

@Bean
public IntegrationFlow errorHandlingFlow() {
    return IntegrationFlows
            .from("invocationFailureChannel")
            .transform("payload.getFailedMessage()")
            .handle(new GenericHandler<Object>() {
                @Override
                public Object handle(Object payload, Map<String, Object> headers) {
                    //Do Stuff
                    return false;
                }
            })
            .get();
}

来自错误通道的回复应该波及回实际调用网关的 bean,对吗?但是我得到了这个奇怪的异常:

o.s.m.c.GenericMessagingTemplate$TemporaryReplyChannel - Reply message received but the receiving thread has exited due to an exception while sending the request message

我尝试为请求和回复设置超时,但这并没有真正帮助。我试图在调用网关的代码上放置一个 try-catch,但我也没有在那里收到错误。

我什至尝试了一个与所示示例相同的示例:

https://www.youtube.com/watch?v=mF2uq4DnVCg

我不知道为什么它对我不起作用。即使在示例中,我也会遇到同样的错误。

当网关将错误发送到错误通道时,它有一个新的'replyChannel` header;旧的是 "spent" - 当网关收到错误时使用它。

这一行...

.transform("payload.getFailedMessage()")

把事情搞砸了,因为 return 消息的转换器会覆盖 headers,所以新的回复通道会被用过的通道替换。

您可以使用

.transform("payload.failedMessage.payload")

框架将负责维护 header。如果您需要访问 failedMessage headers,您将需要一个自定义转换器,并且您需要确保保留 "new" replyChannel header。

或者,您可以在 .transform().

之前使用 header enricher - .enrichHeaders(s -> s.headerExpression("foo", "payload.failedMessage.headers['foo']")) 从失败的消息中复制单个 headers