Hector Rodriguez Baez
Hector Rodriguez Baez

Reputation: 11

How to comunicate two web services through ESB (WSO2)?

I would like to comunicate two web services thorugh an ESB in my case WSo2, for that i have to set and endpoint and a proxy service, but i cant solve it.

Any idea?, Any tutorial?

Upvotes: 0

Views: 591

Answers (1)

RaviU
RaviU

Reputation: 1213

First you should pick between a Proxy Service and API in ESB. A proxy service will give you a SOAP endpoint to work with and an API will give you a RESTful endpoint.

But which ever you chose, the rest is all the same. There will be an inSequence that gets triggered when you invoke your Proxy Service or API. In your inSequence you will have to mix and match a set of mediators and tailor them to your needs. A mediator is a unit of work in your integration flow.

For instance, a service chaining scenario can go something like:

  1. You take an incoming message, take some values out of it create a new payload using the PayloadFactory mediator.
  2. You invoke your first backend using Call mediator.
  3. Then you take the response from this and create a new payload again using the PaylaodFactory mediator.
  4. You call your second backend using Call mediator again.
  5. Finally you use the Respond mediator to respond back to your client.

Have a look at the inSequence below which does the steps above. You can drop this into a proxy or API.

<inSequence>
    <log level="custom">
        <property name="Lets log the incoming payload" expression="$body"/> 
    </log>

    <!-- Payload for first backend -->
    <payloadFactory media-type="json">
      <format>
         "payload":{
            "name":"StackOverflow",
            "value":"SO"
          }
      </format>   
    </payloadFactory>

    <!-- Invoke backend 1 -->
    <call>
      <endpoint>
          <http uri="http://backend1/jsonEndpoint" method="post"/>
      </endpoint>
    </call>

   <!-- At this point we have the response from backend1 in the message context -->
    <log level="custom">
        <property name="Lets log the payload from backend1" expression="$body"/> 
    </log>

    <!-- Payload for second backend. We are using JSONPath to access a value from backend1's payload here -->
    <payloadFactory media-type="json">
      <format>
         "payload":{
            "name":"StackOverflow",
            "value":"SO",
            "id": $1
          }
      </format>   
      <args>
         <arg expression="$.response.from.backend1.id"/>
      </args>
    </payloadFactory>

    <!-- Invoke backend 2 -->
    <call>
      <endpoint>
          <http uri="http://backend2/endpoint" method="post"/>
      </endpoint>
    </call>

   <!-- At this point we have the response from backend2 in the message context -->
    <log level="custom">
        <property name="Lets log the payload from backend2" expression="$body"/> 
    </log>

   <!-- Respond back to client -->
   <respond/>
</inSequence>

I haven't tested the above sequence, but it should be fairly accurate. To get you started, here are the docs to everything we used above.

Upvotes: 2

Related Questions