Announcement Announcement Module
Collapse
No announcement yet.
outbound-gateway: How to keep request message to be combined with the response obtain Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • outbound-gateway: How to keep request message to be combined with the response obtain

    Hi!

    I've a doubt about the best design in cases when I must call to an outbound-gateway and I need to maintain the request message in order to be combined with the response obtained from the gateway.

    As a first approach I've tried this:

    Code:
        ..........
    
        <int:channel id="inputChannel"/>
    
        <int:chain input-channel="inputChannel" output-channel="outputChannel">
    
    <!-- Save my request payload object in a header --> <int:header-enricher> <int:header name="request" expression="payload"/> </int:header-enricher> <int:header-enricher> <int:header name="Accept" value="application/json"/> </int:header-enricher> <int-http:outbound-gateway id="whateverGateway" url="whateverGatewayUrl" http-method="GET" expected-response-type="myResponseType" mapped-request-headers="HTTP_REQUEST_HEADERS" mapped-response-headers="avoidParseExpireHeader(EQ)One" /> <!-- In this transformer I'm getting the request meesage from headers and the response from the payload --> <int:transformer ref="responseTransformer"/> <!-- Remove header that contains the original request. Not necessary beyond this point. --> <int:header-filter header-names="request"/>
    </int:chain> .......
    This is working fine, however it seems to be an ugly solution. Is there a better option?? Maybe a publish subscriber to create two routes for the request message (one of them do nothing and the other one goes through the outbound gateway) and a final aggregator to combine both???

    Thanks in advance

  • #2
    Hi!

    Definitely, the <aggregator> is a main component for your case.
    1. You should add some custom message header for Correlation Key
    2. Send request to the aggregator and to the service
    3. Send response to the aggregator
    HTML Code:
    	<channel id="requestChannel">
    		<interceptors>
    			<wire-tap channel="responseChannel"/>
    		</interceptors>
    	</channel>
    
    	<channel id="responseChannel"/>
    	
    	<header-enricher input-channel="inputChannel" output-channel="requestChannel">
    		<header name="requestCorrelationKey" expression="T(java.util.UUID).randomUUID()"/>
    	</header-enricher>
    	
    	<http:outbound-gateway
    			request-channel="requestChannel"
    			reply-channel="responseChannel"
    			/>
    
    	<aggregator input-channel="responseChannel"
    				correlation-strategy-expression="headers.requestCorrelationKey"
    				release-strategy-expression="size() == 2"/>
    Take care,
    Artem

    Comment


    • #3
      Great! That's exactly what I was thinking.... done and working fine.
      Thanks.

      Comment

      Working...
      X