-1

I'm using ESB and Camel to provide an endpoint to my mobile apps. From there, I need to call multiple web services in such way that the response from the previous call determines whether the next should be called or not and need to pass the same request parameters to the multiple calls.

Additionally, I need to save those response in the database.

I would like to know the best pattern by which we can implement this particular use case using Camel.

рüффп
  • 5,172
  • 34
  • 67
  • 113
RageshAK
  • 103
  • 1
  • 4
  • 12

1 Answers1

1

there are many ways to do it - just think how you'd like to do such logic as example in pure Java then move it to Camel. From actions flow prospective there is no difference. You have condition - you have to have IF or SWITCH operations that's it.

  1. Straight-forward way. After calling previous service you have a response in body with attribute that is a decision factor for next call. So, use Camel "choice-when-otherwise" structure (analog of Java "switch" statement) and in "when" use any available ways to check condition from body (i.e. "simple", "xpath", "xquery" etc.)

  2. If logic to identify next call is more complex - create your custom processor which will identify next call, set special exchange property and then go to the same "choice-when-otherwise" block For that case as example you can have some map with <"previous-result","next-call"> or do it as you'd like to.

and your route may look like (I use Spring):

<cml:to uri="previous_uri"/>
<cml:processor ref="my_selector"/> <!-- it sets Exchange property "next_call" based on result from previous -->
<cml:choice>
    <cml:when>
       <cml:simple>${exchangeProperty.next_call} =="SERVICE1"/>
       <cml:to uri="next_service1_uri"/>
       ... process Service1 result logic ...
    </cml:when>
    <cml:when>
       <cml:simple>${exchangeProperty.next_call} =="SERVICE2"/>
       <cml:to uri="next_service2_uri"/>
       ... process Service2 result logic ...
    </cml:when>

and so on...

Vadim
  • 4,027
  • 2
  • 10
  • 26