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.