Showing posts with label FlowN. Show all posts
Showing posts with label FlowN. Show all posts

Sunday, September 21, 2008

Arrays in BPEL

Why it made itself into my Project?

What else but FlowN. That was the culprit.
FlowN will use index to create separate flows for each of the parallel flows using the index variable.
And the index was used to read data from where else but array.

How to create a array?

Actually it is not as complex as I originally though it to be.
Array in XML can be any element that can store multiple repetition of some data.

For example if A represents sequence of element B then A can be used as array for B.

What is that I am going to show you below?

In short this is what I am attempting to show you.

1. Add elements into the array using BPEL append. 
Most of the cases people already have a array from the source system.
Use this when you want to build your ow array i the fly.

2. Build the XPath 
If you have decided to use array then build a dynamic XPath.
Store that in a temporary variable.
And use that XPath temporary variable while reading elements from the array.
If you ask me what type of variable, I prefer String type.

2. Read data from array 
Just as plain as use the temporary XPath variable and read data from the array element.
Just like saying A[X] i ay other lang. Here A is the array and X is the temporary XPath.
Movig in rounds to read like A[1], A[2] etc.

How to add value into the array?

What else but use append. I you have not seen this, it looks like a + in the assign activity. Just see an assign.

Behind the scenes the bpel code looks like:

<assign name="Assign_CDM_Contents_Append">
<bpelx:append>
<bpelx:from variable="Variable_Add_Array_Element"
query="/ns1:ABC"/>
<bpelx:to variable="Variable_Array"
part="payload"
query="/ns1:ArrayList"/>
</bpelx:append>
</assign>


Here Variable_Array is the variable to hold the array of Variable_Add_Array_Element
I am trying to add elements into the Array (Variable_Array).
I am doing this by appending the elements to be end of it.

Whatz with XPath?

There are 2 options to read data from XML arrays.
One is to use another XPath variable to build the dynamic XPath query.
Second option is to not use a new variable but dynamically insert the XPath in the bpws:getVariableData()

I prefer the first option as it gives a little clarity over the second option.

Why Dynamically build XPath?

Well what ever the case be you need to build XPath dynamically.
But why? Just to use the changing index into the Array.

How to Read data?

If you have a running index over either a flowN or a while loop that does this for you, either way you need the index to access the array.

Now the way to read is through dynamic XPath. That need to be built.
Here I have used option 1.

The below code shows how to use assign to build the dynamic XPath.

<assign name="Assign_XPath_For_Array">
<copy>
<from expression="concat('/ns1:ArrayList/ns2:ArrayElem[',bpws:getVariableData('Variable_Index_Counter'),']') "/>
<to variable="Variable_Xpath"/>
</copy>
</assing>


Note have used [index] to represent index element here in the array.
Here Variable_Xpath acts as a temporary string variable that holds the intermediate Xpath as string.

Now use this XPath string Variable while reading array index elements.
This would look like
<assign name="Assign_Read_Array">
<copy>
<from expression="bpws:getVariableData('Variable_Array','payload',bpws:getVariableData('Variable_Xpath'))"/>
<to variable="Variable_Read_Array_Element"
query="/ns1: ABC"/>
</copy>
</assign>


How to do with out another variable?

Just do not use the new variable. Build your XPath dynamically right in the bpws:getVariableData() 3rd parameter.

Thursday, August 21, 2008

Correlation for what? What forced it?

Is it complex?

Well correlation is not as complex as it seems.
Well when I first looked at it, it did not make any sense.
But this is what my experience with correlation is, and it was not as hard as I though it would be.
Though it was not difficult to get it working, I had to do a lot of ground work basically read a couple of articles before I understood what it was all about.
But once I did understand, it was a cake walk.

Whatz correlation? What does it correlate?

What correlation meant to me as a maths student was linear relationship between two random variables.
I initially understood it was to relate two seemly unrelated instances in BPEL, that are related in business sense. And it did turn out that way.

Where to use?

When BPEL is in synchronous mode, the caller waits for the response, so caller instance does the correlation in the background using WS-Addressing, basically add its own correlation to the message header send out.

Itz the asynchronous execution where the BPEL instance fires and forgets who received it. That when you want to say to BPEL which instance to go back to. Here is where BPEL correlation kicks in. What is basically does is use the data in the message to relate the instance. And so the correlation should be unique to the instance.
It does not always need to be A --> B --> C --> A but can be A --> B --> A if BPEL fires and forgets and wants to send back to the caller.

What forced it?

First of all correlation has force itself into my workspace in 2 of the projects that I was involved in. And both of these were for different reasons.

Circular call

Firstly was for the generally known and widely written about one i.e. A--calls -> B --> C --> A, basically a transitive calls that ends up on the caller, and the caller needs to figure out which instance of A --> C should return to.

If canonical data model id used to pass data across then one or more of the elements in the message will be used to build the correlation else one of the those fields in the message will be used for correlation.

FlowN

Second was for a entirely different scenario.
I tried to use FlowN to spawn 'N' 'ProcessB' from a master 'ProcessA'.
Call from 'ProcessA' to 'ProcessB' was asynchronous call. After ProcessB was complete it would return status back to ProcessA.

Without any correlation I was getting

"Conflicting receive.Another receive activity or equivalent (currently, onMessage branch in a pick activity) has already been enabled with the partnerLink "Process", operation name "onResult" and correlation set "" (or conversation id). Appendix A - Standard Faults in the BPEL 1.1 specification specifies a fault should be thrown under these conditions."

To solve this I had to create correlation. The reason being each of the branches in FlowN created exactly the same asynchronous call, but the receiving instance had to identify which spawn in the FlowN was the response coming back to. And yes creation of correlation did solve the problem.

But making correlation in FlowN to work was not straight forward as there were scope issues that I had to address, and I initially did not see coming. I only found explanations about FlowN in oracle forums from the Google I did. Hopefully I would write another blog post for the correlation in FlowN.

Where to setup correlation?

Only the receiver should perform the correlation.
And the sender should only worry about sending enough data to perform correlation.

Related Articles that helped me:


There was another very good article that helped me but I am unable to find that now.