Thursday, August 12, 2010

Dynamic Routing in Oracle SErvice BUS

Dynamic routing means based on input request your business process will be invoked.
In the exercise we will create two business service which will be writing data to two different folder.

Depending upon the input request one of the business service will be chosen at run time and the file will be written to that folder.

I am using the following document to create this process

As per the document i am using following xml document for query

<routing>
<row>
<logical>Oracle</logical>
<physical>default/goldservice</physical>
</row>
<row>
<logical>ABC Corp</logical>
<physical>default/silverservice</physical>
</row>
</routing>

As per the xml document we need to create two service silverservice and goldservice with default folder so i have created two business service in default folder as shown below




These business process are a simple file processing business process,they are writing the data to two different folder.

Now i have created a xquery resource for the xml document as shown below



Now again create a proxy service and edit the message flow as shown below



Now add a pipeline pair



Now add a stage.



Now edit the stage

Add a log message we will first log the body .

Its syntax is $body.This will provide us the input result in command console.



I am using the following input in my case

<routing>
<row>
<logical>
Oracle
</logical>
</row>
</routing>




Now add an assign activity




In this assign activity we will assign the input xquery table to some variable

I will use routingtable as the variable name.


now once selected click on expression ,go to xquery resources and choose the xquery resource which you have created as shown



nog log this routing table also and again create one more assign activity.

In this assign activity you get the input data

i.e.

$body will fetch us the result of input that we have passed.

<routing>
<row>
<logical>
Oracle
</logical>
</row>
</routing>

So if we have to get to the value we will be using the xpath to reach to input so it will
be something like this

$body/routing/row/logical

We will again assign it to a variable called as logicalidentifier




Now i will again create a assign activity ,will go to expression and copy paste the following

<ctx:route>
<ctx:service isProxy=â'false'> {$routingtable/row[logical/text()=$logicalidentifier]/physical/text()}
</ctx:service>
</ctx:route>


After that i clicked on validate and i got following exception

line 1, column 5: {err}XP0003: Invalid expression: unexpected token: :

This is because we have a space in between ctx: route and ctx: service

it should be ctx:route and ctx:service there should not be any space in between them

so i reomved the space and then said validate

then i again got an error like this

line 2, column 22: {err}XP0003: Invalid expression: unexpected token: ’

this is becasue false should be quoted in single inverted comma and when i copied it from

the document it was some other comma,so i just deleted the two commas and then again put

it inside the single inverted comma and then said validate and it worked for me this time



Again assign this to one more variable.I have assigned it to output variable.


{$routingtable/row[logical/text()=$logicalidentifier]/physical/text()}







We will just use the command

$routingtable/row[1]/physical/text()

It will fetch us the result

default/goldservice

Similarly if we will make it

$routingtable/row[2]/physical/text()

it will fetch us result

default/silverservice

As we know that in xquery the element count start from zero but

i believe in OSB it starts from 1 Because when i do

$routingtable/row[0]/physical/text() it doesn't fetch me any result.

so now we will see what is exaclty being used in our command



$routingtable/row[logical/text()=$logicalidentifier]/physical/text()


if we will just change this code to

$routingtable/row[logical/text()="Oracle"]/physical/text()

This will also fetch us the result

default/goldservice

In our scenario $logicalidentifier will fetch us the result Oracle so this command

$routingtable/row[logical/text()=$logicalidentifier]/physical/text()

mean that give the physical address for the input whose logical message is Oracle.

I hope it will be clear by now.


Now stop the flow by adding a rotuing service at the end




In add action add dynamic routing



Finally add your output in the expression $output




Save all the project activate and now check it.i am checking it with following input

<routing>
<row>
<logical>Oracle</logical>
</row>
</routing>



and you can see it is routed to correct destination


No comments: