The BPEL FlowN activity can be used for parallel execution of activities. Often this activity is used to split up a message into parts and process those parts simultaneously. When using FlowN it is advisable to put a scope inside and use local variables. If you neglect to do that, the results can be different from what you might expect.
To demonstrate this I created a database table and a simple BPEL process. The BPEL process inserts the counter variable of the FlowN activity into a table.
See the below screenshot for an overview of the process.
All variables in this process are global. I let JDeveloper generate a global variable for me when I created the invoke activity. The assign activity consists of the following;
- Assign an empty XML fragment to the variable used for the invoke
- Assign values to the fields of this variable. I used the counter in the FlowN (FlowN1_Variable_1) as one of the values.
When I check the database I see the following;
This is of course behavior to be expected since the assign activities are executed in parallel on a global variable, thus which value the global variable has during the invoke, is not solely determined by what happens in its own FlowN branche, but also by what happens in the other branches.
Fixing this is easy; create a new scope inside the FlowN activity and use local variables inside that scope. This makes the different FlowN branches independent of eachother.
See the last three results (id 4,5,6) below for the results after adding scopes and moving the invoke variable to this scope. The below screenshot also illustrates that the order of execution is not fixed when branches are executed in parallel.
hi, i am a beginner in soa. i am practicing flowN activity and faced the same issue as your mentioned i.e. without using local variables.
ReplyDelete1)created an async process.
2)Getting employee data as a input(name,id,designation and dept)
3)empCount=counted no of 'Name' nodes in the input message.
4)FlowN step: N= getvariabledate(empCount)
index= indexVar (created a variable of type:int)
5) included scope in flowN activity
6) included sequence in scope activity.
7) created a partner link (async hello process)
8) included invoke step in the scope to invoke Async Hello process
9) now, included assign step to assign 'Name' input to Async Hello Process input. (did using expression: getElement fn
after testing the above one with an input having two employee detals i.e. indexVar=2, as your mentioned, i see the index variable is incrementing correctly but all the time first node 'Name' element value is getting passed to Async process. Would you please elaborate, creating a local variable in FlowN scope will fix the issue. Please advise me. Thanks