Using Dynamic Routing in OSB

Dynamic Routing in OSB can be used when we want to determine the business service at runtime in the message flow. To store the information about the business services that can be used, we can use XQuery resource.

Consider a scenario where OSB has to route the incoming requests to 2 different services based on the CustomerType element value sent in the payload. So create a XQuery resource with the following contents. Observe that we are using the absolute path of business service in configuration as required by dynamic routing.

Create the required resources a proxy service based on the above WSDL, 2 business services and a XQuery resource with the contents shown above.

Create the message flow as shown below.

The first assign activity loads the XQuery resource and stores the contents of the file in variable ‘varConfig’. The second assign activity stores the value of customer type element in the payload in ‘varType’ variable using the xpath expression $body/cus:Customer/CustomerType/text().

For the dynamic routing the expression should resolve to the following XML snippet. The attribute isProxy has to be set to ‘true’ if routing the request to proxy service or ‘false’ if routing the request to business service. Operation name is optional as business service might not be WSDL service always.

Related

40 Responses to “Using Dynamic Routing in OSB”

How different is it if instead of doing this way, we use routing options in request action of routing, and pass the URL as $URI. That way also, the URL will be decided at run time only based on the customer type input.

If we create an Xquery, and use dvm look up function to fetch the url and store that url in $uri variable and instead pass that variable in routing options, that way also dynamic routing could be achieved.

could you please confirm if my conceptualization is correct in this regard.

Hi shiva,
We also did route to different business service based on the value in the xml message received at the source. But in our case we did it using if-else conditions in the message flow like fetching the value from xml and assigning it to the xquery gving in the if statement (ex: if($body/Configuration/CustomerType/Service/text() = ‘DynamicRoute/BSSystem1’). Can u please tell me what make this dynamic routing action better than using if-else condition. OSB is new to me, as far i see both way it does dynamic routing to business services based on a value in the incoming message. please light up the advantage of using dynamic routing action in any terms.

One of the advantages is the scalability of the approach when multiple business services are there and how fast you can make the changes. Since the configuration file xml based, we can automate the generation of it using scripts in cases where we have no.of business services.

Hi Sir, i have a small doubt on this scenario ( in OSB PROJECT)let supose ,,

i am taking request from source its a collection of data like files. next i can transform to target streams like in data telugu file is the send to telugu stream if hindi file is the send to hindi stream . so now my question is how we can write code for this in Xquery

Do you have separate Xquery transformations for both the streams? If you have only 1 or 2 cases you can go for conditional branch directly. If you see more cases like this go for dynamic routing as explained in the post.

Hi Siva, If there is an error in one business service, i want to try other business service automatically without being communicate to the requester. The requirement is that the requester need not know which business service has provided the response.

Hi, If that is the case you can actually call another business service from the exception handler when you get the error on first business service. You can create exception handlers on routing node or pipeline pair node.

I am looking for dynamic routing and dynamic publish good tutorial for a long,These blog is really help me a lot to understand.
I appreciate your effort and time to blogging it
Could you please send me the jar file to souvik06@gmail.com

Hi shiva,
I tried with simple Helloworld business and NoHelloworld business services deployed in SOA and imported into Eclipse and I follow the the remaining as article.
When I testing I got error like

The invocation resulted in an error: .

soapenv:Server

BEA-382612: Error preparing message for dispatch

BEA-382612
Error preparing message for dispatch

RouteNode1
request-pipeline

My Query is in your sample your are using same WSDL for BS & PS,for different wsdl (BS) how to call in DyamicRouting.
Can you please any suggestions.

Hi shiva,
Thanks for sending the jar.How to create the xQuery transformation with the sample code,when creating the xQuery,what should I select on the source and target,in your Xquery,there is no source and target.