【问题标题】:processing multiple http outbound gateways处理多个 http 出站网关
【发布时间】:2022-07-06 04:09:13
【问题描述】:

我正在研究 Spring 集成 http。想要进行多个 http 调用并收集对一个常见 java 对象的响应。我面临一个问题,即在聚合器末尾没有输出/回复通道。 这是xml定义

<int:channel id="intermediateWChannel">
<int:interceptors>
<int:wire-tap channel="intermediateWLogger" />
</int:interceptors>
</int:channel>
    <int:channel id="intermediateSChannel">
        <int:interceptors>
            <int:wire-tap channel="intermediateSLogger" />
        </int:interceptors>
    </int:channel>
    <int:logging-channel-adapter id="intermediateWLogger" expression="'Fetch Wtms Trip : '.concat(payload)" level="INFO" />
    <int:logging-channel-adapter id="intermediateSLogger" level="INFO" />
    <int:chain input-channel="intermediateSChannel" output-channel="publishsubscribechannel">
        <int-http:outbound-gateway 
            id="outboundGateway"
            url="{url2}"
            http-method="GET" 
            request-factory="requestFactory"
            charset="UTF-8"
            mapped-request-headers="Accept:application/json"
            expected-response-type="java.lang.String"></int-http:outbound-gateway>
        <int:object-to-json-transformer/>
    </int:chain>
    <int:chain id="chain2" input-channel="publishsubscribechannel" output-channel="aggregatorChannel">
        <int:transformer ref="fetchTransformer" method="process" />
    </int:chain>
    <int:chain id="request-chain" input-channel="publishsubscribechannel" output-channel="aggregatorChannel">
        <int-http:outbound-gateway 
            id="strideOutboundGateway1"
            url="url3"
            http-method="GET" 
            request-factory="requestFactory"
            charset="UTF-8"
            mapped-request-headers="Accept:application/json"
            expected-response-type="java.lang.String"></int-http:outbound-gateway>
        <int:transformer ref="fetchTransformer" method="process1" />
    </int:chain>
    <int:chain id="chain3" input-channel="aggregatorChannel" output-channel="outputChannel">
        <int:aggregator id="tAggregator" 
        ref="tDataAggregator"
        method="processAggregator"
        correlation-strategy-expression="headers['id']" 
        release-strategy="aggregatorReleaseStrategy" 
        expire-groups-upon-completion="true"/>
    </int:chain>

但是,我已经在聚合器中指定了输出通道。 下面是一个例外,即使我在标题中添加回复通道,应用程序也会使用 stackoverflow。 org.springframework.messaging.core.DestinationResolutionException:没有可用的输出通道或回复通道标头 在 org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:452) ~[spring-integration-core-5.5.13.jar:5.5.13] 在 org.springframework.integration.handler.AbstractMessageProducingHandler.doProduceOutput(AbstractMessageProducingHandler.java:325) ~[spring-integration-core-5.5.13.jar:5.5.13] 在 org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:268) ~[spring-integration-core-5.5.13.jar:5.5.13] 在 org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:232) ~[spring-integration-core-5.5.13.jar:5.5.13]

【问题讨论】:

  • 可能你fetchTransformer返回一个Message不是基于请求…
  • @ArtemBilan 我可以看到汇总数据。但是,一旦 processAggregator 被返回,它会再次调用 AbstractMessageProducingHandler 中的produceOutput。不知道为什么。我在这里有什么遗漏吗
  • 请展示一下你的变压器在做什么
  • outputChannel 订阅者是什么?
  • @ArtemBilan 你是对的。我正在修改变压器中的标题。我认为这就是我遇到问题的原因。我避免修改标题。现在它正在工作。谢谢

标签: spring-integration spring-integration-dsl spring-integration-http


【解决方案1】:

转换器与其他端点不同,它不会修改我们从其方法调用返回的Message。它被认为是转换器可以完全控制回复消息的创建。因此,如果需要保留一些请求消息头,建议使用MessageBuilder.copyHeadersIfAbsent() API。这样,在请求-回复场景中,回复消息中会出现必要的replyChannel 标头。

我们可能不得不在文档中提到 shouldCopyRequestHeaders() 的变压器行为:https://docs.spring.io/spring-integration/docs/current/reference/html/message-transformation.html#messaging-transformation-chapter。随意提出 GH 问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    相关资源
    最近更新 更多