spring-integrationspring-integration-dslspring-integration-http

processing multiple http outbound gateways


I am working on the spring integration http. Wanted to make multiple http calls and collect the response to one common java object. I am facing an issues which says no output/reply channel at the end of the aggregator. This is the xml definition

<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>

But, I have specified the output channel in the aggregator. Below is the exception and even if I add the reply-channel in headers, application is going for stackoverflow. org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:452) ~[spring-integration-core-5.5.13.jar:5.5.13] at org.springframework.integration.handler.AbstractMessageProducingHandler.doProduceOutput(AbstractMessageProducingHandler.java:325) ~[spring-integration-core-5.5.13.jar:5.5.13] at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:268) ~[spring-integration-core-5.5.13.jar:5.5.13] at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:232) ~[spring-integration-core-5.5.13.jar:5.5.13]


Solution

  • The transformer is different from other endpoints that it does not modify a Message we return from its method call. It is counted as transformer has a full control over the reply message creation. So, if there is a need to preserve some request message headers, it is recommended to use a MessageBuilder.copyHeadersIfAbsent() API. This way in request-reply scenario, the necessary replyChannel header is present in the reply message.

    We probably have to mention shouldCopyRequestHeaders() behavior for the transformer in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/message-transformation.html#messaging-transformation-chapter. Feel free to raise a GH issue.