Announcement Announcement Module
No announcement yet.
Spring Integration Asynchronize Gateway Exception callback Problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration Asynchronize Gateway Exception callback Problem

    Hi All, I have a spring Rabbitmq integration project.

    A system send request message to RabbitmqExchange then go to B system. This logic flow is using Asynchronize Gateway. Message from A's outboundGateway is able to reach B . B receive it will access to a server C then do the business job and then return the result msg back to A by using Asynchronize gateway config. [show in below diagram]

    Now, A send request --> Rabbitmq --> B, B access another system C but throws a LoginException. I need B's exception return to A. How can I receive Exception from B which pass through rabbitmq(using async callback)? ps. Without exception, A is able to get callback from B.

    Anyone can help me ? : )
    Attached Files
    Last edited by ericaZ; Apr 25th, 2013, 06:04 AM.

  • #2
    I assume you are using an <int-amqp:inbound-gateway/> on B and an <int-amqp:outbound-gateway/> on A.

    If so, the solution to this problem is to put an error-channel on the inbound gateway on B; on that channel add a transformer to create some message content that will tell A that the exception occurred.

    Something like...

    <int:transforner input-channel="errorChannel" expression="'FAILED:' + payload.cause.message" />
    You would then have to detect this result in the response to system A.


    • #3
      Thanks for your help. You are right. I just add your sugesstion. But I stuck at how to let system A auto-detect it. I used async-gateway pattern for outbound[A] and inbound[B]. It seems message will auto callback to outbound[A] once inbound[B] got the returned value. When B got exception, it keeps hanging at error-channel.

      outboundGateway[A] ---->Rabbitmq---->inboundGateway[B] (How to do the error-handling for async-gateway?)

      Would you tell me details how to make system A receive the exception from B using same thread? How the transformer created message will send back through rabbit and back to outboundGateway[A] ?

      How system A can detect the result in the response? Configure outboundGateway[A]'s reply-channel property?


      • #4
        You need to show System A's configuration.

        Basically, it will either get a "good" result, or the error result generated by the transformer.

        It just needs to examine the response and decide which one it is.


        • #5
          System A's configuration:
          <!-- rabbit connection factory, rabbit template, and rabbit admin -->
            <import resource="A-amqp-config-xml.xml" />
            <!-- spring integration flow -->
            <int:gateway id="client4Sync"
              default-request-channel="syncChannel" default-reply-timeout="20000" >
              <int:method name="callSyncVsphere" request-channel="syncChannel" />
            <!-- For Synchronize VSphere Service -->
            <int:channel id="syncChannel" />
            <int:header-enricher input-channel="syncChannel"
              output-channel="enrichedSync" id="syncEnricher">
              <int:header name="NAME" expression="payload.getType()" />
            <int:channel id="enrichedSync" />
            <int-amqp:outbound-gateway request-channel="enrichedSync"
              exchange-name="ARequests" routing-key-expression="'request.'+headers.NAME"
              amqp-template="amqpTemplate" reply-timeout="60000" />
          System A's Gateway interface:
          public interface EngineVsphereGateway {
               * EngineVsphereGateway used to call sync vSphere worker.
               * @param cloud
               * @return LinkedMultiValueMap<String, Object>
              @Gateway(requestChannel = "syncChannel")
              LinkedMultiValueMap<String, ArrayList<Object>> callSyncVsphere(
                      final CloudDTO cloudDto);


          • #6
            Well, if you want to retain that signature, the transformer on the error channel will have to transform the error message to a LinkedMultiValueMap containing the error. The calling code can then test the contents of the map to see if it's an error.

            By the way, it's not good practice to use concrete return types; better to use MultiValueMap.


            • #7
              Gary, thank you very much. And sorry for the delayed feedback. Few days ago, I have another projet cut in which need quickly fix. So I just return back this project today. Luckily solved it with your suggestion.

              Before I misunderstand the problem it is. I tried wrong direction thinking that I need special configuration for Asynchronous Gateway. After digest your advice again and agin, finally know how careless I am and how to solve it. Before I throw that exception and did not do any exception handling let it return, now I just wrapped the message from catch, it automatically return back to System A.