Spring集成。出站异常时的网关回复错误

时间:2017-09-11 12:17:48

标签: spring spring-integration

我有下一个配置:

入站

<int:gateway id="inGateway" service-interface="XXX"  
    error-channel="errorChannel" 
    default-request-channel="requestChannel" 
    default-reply-channel="replyChannel" />

出站:

<ws:outbound-gateway id="ws-outbound-gateway"
request-channel="inbound" reply-channel="outbound"      uri="XXX" />

第1链:

<int:chain input-channel="requestChannel" output-channel="inbound">
XXX </int:chain>

链2:

<int:chain input-channel="outbound" output-channel="replyChannel"> XXX
</int:chain>

错误:

<int:chain input-channel="errorChannel" output-channel="replyChannel">

        <int:transformer ref="logicTransformers" method="errorTransformerMethod"></int:transformer>


    </int:chain>
</beans>

Java Transformer:

final GenericError errorCatalog = errorCatalog(errorMessage);
LOGGER.warn("Transformed error from catalog: {}", errorCatalog);
final MessageBuilder<Document> builder =
MessageBuilder.withPayload(XmlUtil.parseToDocument(errorCatalog)).copyHeaders(errorMessage.getHeaders()).copyHeadersIfAbsent(errorMessage.getHeaders());

当outbound的web服务停止时,错误进入errorChannel转换器但是为了响应我们有下一个错误:

  

o.s.m.c.GenericMessagingTemplate $ TemporaryReplyChannel#242回复   收到的消息但是接收线程已经退出了   发送请求消息时发生异常:GenericMessage   [payload = [#document:null],headers = {spanTraceId = 8bf90ea9ff4266c8,   spanId = 598680bae5f913d5,spanParentSpanId = 8bf90ea9ff4266c8,   replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@76c751de,   functionalId = PRUEBASOA12,   errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@76c751de,   messageSent = true,id = 2108386f-99db-98b9-3d30-3bcf45335424,   spanSampled = 1,spanName = message:requestChannel}]

我们不明白......因为我们有同样的流程

1 个答案:

答案 0 :(得分:0)

如果服务级别出现错误,原始邮件将被包裹到MessagingException,而ErrorMessage的{​​{1}}会被发送到payload。即使您明确使用errorChannel,仍然必须确保replyChannel标头,该标头由入站网关填充。确切地说,此标头在该网关的请求 - 回复行为中起主要作用。

您的错误流中仍然存在replyChannel,但它已经是replyHeader有效负载中failedMessage的一部分。

因此,您的MessagingException应该从此方法中提取真实回复的logicTransformers.errorTransformerMethod标头,以便发送到显式replyChannel。或者您可以省略此replyChannel,因为真实replyChannel的任何方式都基于sendAndReceive标题。

请阅读参考手册中的更多信息:

https://docs.spring.io/spring-integration/docs/4.3.11.RELEASE/reference/html/messaging-endpoints-chapter.html#gateway

https://docs.spring.io/spring-integration/docs/4.3.11.RELEASE/reference/html/configuration.html#namespace-errorhandler