Correlation
This post would effort to explore the meaning and need of correlating
requests and the best way to do them using Oracle SOA Suite.
What & Why
In common business scenarios it is not possible to have a synchronous
response to each of our requests. Mostly the business has to deal with
vendors, who would need to undergo a detailed process to come up with a
solution. However, this response may not be necessarily binding
business from carrying on its other activities. In such scenarios, the
business enters in to asynchronous communication with these third
parties. The async process necessarily stresses that the response may
come back at a later time, through callback or polling mechanism as is
suitable.
In case of a single instance its quite easy to match the response to
request, however, when there are multiple instances the business would
be wondering which request has been responded to. For example, if a
travel booking agent spawns 10 requests for Frankfurt to Paris, and
after a while airline responds to one of those 10 requests, it would not
be safe to assume that this is a response to first request only. Hence
the travel agent would tag in an ID to segregate one request for
another, and would expect the airline to return this id unaltered to
match the request. This id, which enables requestor to correlate the
response sent by the provider, is called Correlation Id.
How (in Oracle BPEL)
Oracle BPEL provides us with two mechanisms through which an
asynchronous callback message could map to its calling instance in the
crowd.
- WS-Addressing
- Correlation Sets
WS-Addressing
“How does the callback maps to the correct instance out of so many
waiting processes”, it’s a very common surprise to all beginners,
creating first ever Asynchronous Invoke in BPEL Process Manager. The
answer is, any time an asynchronous service is invoked, Oracle BPM,
instills a message UID in WS-Addressing headers that float with SOAP
Packets, which are used internally by the BPEL Server to correlate the
flowing request/response.
This is the default mechanism supported by Oracle BPEL Process Manager,
which is overridden automatically when the user opts to create his own
correlation set.
Correlation Sets
Correlation Sets enable you to correlate asynchronous messages based on message body contents.
Why?
The question now arises, why ever would a BPEL developer like to
over-ride default WS-Addressing correlation and use content-based
correlation. Well, he won’t have to; if the called service is an Oracle
BPEL, or the one, which supports and retains WS-Addressing headers
sent, and returns the same in response.
The reasons, to use content-based correlation, could be many; some of the familiar ones that come to my mind are –
1. The asynchronous web service invoked by BPEL does not support/understand WS-Addressing headers.
2. When BPEL instance is expecting messages from a third party, for example, a file-poller.
3. When asynchronous call has multiple hops and reply is received
directly from end system. For example, Request path is A > B > C
> D and response comes to A directly from D, i.e. D > A.
How?
WE now understand and appreciate, need of correlation and the two
mechanisms to achieve correlation. In WS-Addressing, we, as in
developer, does not bother of how the correlation ID is created and
maintained. However, in content-based correlation the responsibility of
managing correlation set, defining property alias and initializing the
correlation with appropriate value falls on developer.
To understand how to perform these tasks, we would start by
understanding in which activities do we need correlation. The
Correlation is required whenever data is going out or coming in to the
BPEL process, hence Correlation works only with Invoke, Receive, Pick
and Reply activities.
To create a correlation of our own, we need to create the Correlation
Set first. A correlation set is a set of properties shared by all
messages in the correlated group.
The correlation set is normally instantiated on invoke or receive
activity. When correlation is instantiated on receive activity it is
fairly straight forward, you create a correlation set, and select
initiate = “yes”.
However, when you have to create correlation set on invoke, we have one
addition option to understand, it’s the “pattern”. Now before we move
ahead with “pattern”, lets explore what is “initiate” option.
If initiate option is set to “yes” this means that we assign the value
to correlation variable. When initiate option is set to “no” this
means, we want to validate the value against, value stored in
correlation variable.
With this in mind, we would try to understand, the “pattern” option of Correlation tab in invoke activity.
When initiate = “yes”,
Pattern=”in” means the correlation is being instantiated with a value
that is coming into the BPEL, from another service. Clearly, this
invoke is then not the one which is invoking an asynchronous process,
as the pattern suggests a response coming back.
Pattern = “out” means the correlation is being instantiated on the message that is going out of our BPEL.
Pattern = “out-in” means the correlation would be set on a variable
that is part of both outgoing and incoming parameter, in this
synchronous invoke. However, its nature is very much questionable.
When initiate=”no”
The above patterns would reflect which way the variable needs to be validated, inward, outward or both ways.
Creating a Correlation Set
Correlation sets uses correlation tokens available inside messages,
headers or business documents. Correlation tokens are the declarative
properties of messages. A property is an element within a message
identified by a query. Property aliases are the constructs to specify
the queries to identify properties.
To create Correlation Set click the Create icon, and insert the appropriate values. As shown in the diagram below:
Here you would also need to create a Property (not shown in diagram
above, its just beneath Xpath text box. This way we declared one of the
property alias for instantiation, we need to create another one for
validation.
Select the BPEL in diagram, in the adjacent Structure window, you would
see set of properties. Right Click Property Alias, and select “Create
Property Alias…”.
Now, select the appropriate message part, and then enter Xpath query
string in the text box. You can use Ctrl+Space for Autofill.
Now, select the appropriate message part, and then enter Xpath query
string in the text box. You can use Ctrl+Space for Autofill.
References :
Antony Reynold's Correlation
Antony Reynold's on Pattern and Initiate |
0 comments:
Post a Comment