Announcement Announcement Module
Collapse
No announcement yet.
Wait HTTP-response from async splitter-aggregator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wait HTTP-response from async splitter-aggregator

    Hello, guys
    I need help with SI-configuration.
    It is my configuration:
    HTML Code:
      <http:inbound-channel-adapter name="/foo" channel="fooRequestChannel"/>
    
        <channel id="fooRequestChannel"/>
    
        <channel id="splittFooChannel">
            <queue/>
        </channel>
    
        <channel id="getBarGatewayChannel"/>
    
        <channel id="routeToBarServiceChannel"/>
    
        <channel id="processBarChannel"/>
    
        <channel id="aggregateBarChannel"/>
    
        <chain input-channel="fooRequestChannel">
            <gateway request-channel="getBarGatewayChannel"/>
        </chain>
    
        <splitter input-channel="getBarGatewayChannel" output-channel="splittFooChannel"/>
    
        <chain input-channel="splittFooChannel" output-channel="processBarChannel">
            <gateway request-channel="routeToBarServiceChannel"/>
        </chain>
    
        <transformer input-channel="processBarChannel" output-channel="aggregateBarChannel"/>
    
        <aggregator input-channel="aggregateBarChannel"/>
    So, I want to make some business logic in splitted threads and wait response after aggregation.
    When my aggregator completes his work he sends me error:
    MessageHandlingException: no replyChannel header available
    What am I doing wrong? Or what can I do to implement such solution?

    thanks in advance,
    Artem Bilan

  • #2
    If you want the HTTP response to be generated only after aggregation, then you should use an HTTP "inbound-gateway" (which is request/reply) instead of the channel adapter (which is one-way). That would then add the "replyChannel" header to the original Message so that it gets passed along until the end of the flow (aggregator in your case). Otherwise, if you want something else to happen after aggregation (a one-way flow instead of request/reply), then add an "output-channel" to the aggregator element.

    Hope that helps.
    -Mark

    Comment


    • #3
      Ok, Mark, thanks
      <http:inbound-gateway/> works fine.
      And now my new question:
      What can I do if I don't want to send my payload into HttpResponse? I want send only Exception with HTTP 500 and only HTTP 200.

      Note: about <http:inbound-channel-adapter/> is written that he sends only HTTP 200 for OK and not sends paylod.

      Thanks again

      Comment


      • #4
        You can add one more component (e.g. transformer) after the aggregator, and that can create the payload (or even throw an Exception). You should be able to use the HttpStatus enum as the payload itself. If you need some other payload (or prefer an empty String or whatever), you can also set the header whose key is the value of our HttpHeaders.STATUS_CODE constant (which is "http_statusCode"). That can be an instance of the HttpStatus enum, or a String, or an Integer.

        Comment


        • #5
          Thanks, Mark
          That works very well.
          I added after aggregator transformer:
          HTML Code:
          <transformer input-channel="prepareBarResponseChannel" output-channel="barResponseChannel"
                           expression="T(org.springframework.http.HttpStatus).OK"/>

          Comment

          Working...
          X