Dynamic Routing in OSB

In this post we will see how to use OSB dynamic routing feature to Route Request to different proxy/business service at run time. 

To demonstrate how Dynamic Routing works, we will first create two proxy service with Mocked response indicating which proxy service got called.

We will have customer creation service, which creates the customer either in CRMOD or OCH based on the parameter passed in request.

There will be 3 proxy services:

1.     OCH proxy service :
a.      URI : /proxy/ochCreateCustomer
This proxy will return the mocked response i.e. “customer created in OCH”
2.     CRMOD proxy service:
a.      URI : /proxy/crmodCreateCustomer
This proxy will return the mocked response i.e. “customer created in CRMOD”
3.     Create Customer Orchestration service:
a.      URI: /proxy/createCustomer
This proxy receives request in any XML format, with the parameter indication where customer must be created.



 

The createCustomer proxy service route the request based on the value in <destination> element i.e. OCH or CRMOD.

Now let’s create OCHCreateCustomer proxy service:
1.     Create the project DynamicRouting.
2.     Create folder proxyservice
3.     Create Any XML proxy service as we are creating sample service.









4.     Set Endpoint URI :













5.     Create a message flow and add the sample response stating the OCH proxy is called.














6.     Duplicate the OCHCreateCustomer.proxy to CRMODCreateCustomer.proxy
7.     Change the URI to /proxy/CRMODCreateCustomer and output to “Customer created in CRMOD”
Next step is to create the XSD schema “CreateCustomer.xsd”
Now let’s create the orchestration proxy service i.e. CreateCustomer.proxyservice
Create this proxy service as Messaging Service with request type as XML i.e. createCustomer and response as “text” as we just want to check which service is called.













Now let’s add code to Dynamically route the request based on the input.

1.     Add route node
2.     Add Dynamic Routing option
3.     Add below code in the expression of the dynamic routing
<ctx:route>
<ctx:service isProxy="true">{data($body/cre:CreateCustomer/cre:destination)}</ctx:service>
</ctx:route>




4.     Export the project to sbconfig.jar and import the same on OSB server.




















Testing:

Now let’s test the sample proxy service.
Send request with full proxy URI

Request:

<cre:CreateCustomer xmlns:cre="http://www.example.org/CreateCustomer">
    <cre:fullName>John Smith</cre:fullName>
    <cre:destination>DynamicRouting/proxyservice/CRMODCreateCustomer</cre:destination>
</cre:CreateCustomer>

Response:

<?xml version="1.0" encoding="UTF-8"?>
<cre:CreateCustomer xmlns:cre="http://www.example.org/CreateCustomer"><output>Customer created in CRMOD</output></cre:CreateCustomer>
Request:
<cre:CreateCustomer 
xmlns:cre="http://www.example.org/CreateCustomer">

<cre:fullName>John Smith</cre:fullName>

<cre:destination> 
DynamicRouting/proxyservice/OCHCreateCustomer
</cre:destination>

</cre:CreateCustomer>

Response:

<?xml version="1.0" encoding="UTF-8"?>
<cre:CreateCustomer xmlns:cre="http://www.example.org/CreateCustomer"><output>Customer created in OCH</output></cre:CreateCustomer>



As we can see the request is routed dynamically based on the proxy service URL send in the request.
The sample code can be downloaded here : DynamicRouting

Popular posts from this blog

JAVA embedding in Oracle SOA 12c

Passing/Receiving HTTP header in SOA BPEL

Integrating Weblogic with IBM MQ over JMS