Correlation
Let us assume we have set of BPMN process instances with various values for a given variable "var1". Correlation is a mechanism of identifying the process instance with the given value of variable "var1". Correlation can be done for single/multiple variables.
In other word, correlation is a process of finding the instance with similar set of variables. More information on correlation and how the REST API provided by WSO2 Business Server 3.5.1 can be used to correlate among various process instances can be found here.
In this article we are going to provide further description on a newly introduced API which aggregates both instances startup and correlation on a single API call. This API provides following functionality.
- If the instance with the given variable state exists, API will return with the existing process instance information.
- Or if the instance exist with the searched variable state, API will correlate with the process instance and continue the execution.
- Or if there are no instances exist with defined variable state, new instance will be created and returned back to the client.
This use case can be explained using following BPMN workflow diagram.
This diagram has following properties.
- A start message :- This message is denoted with "startProcess"
- Two intermediate message catching events :- Those are "updateRequest" and "recieveResponse"
Requirements
- WSO2 Business Process Server 3.5.1 ( This can be downloaded over here)
- The BPMN workflow can be downloaded over here.
Once the BPMN Archive file is deployed to the server, BPMN instance can be started by hitting the url https://localhost:9443/bpmn/runtime/process-instances with following request.
Prior to sending the request please make sure to set the following header values.
Those are
Authorization header has to be set with the base64 encoded values of "username:password".
Prior to sending the request please make sure to set the following header values.
Those are
- Content-Type: application/json or application/xml
- Accept: application/json or application/xml
- Authorization: Basic base64encode(username:password)
Authorization header has to be set with the base64 encoded values of "username:password".
This is a sample request used for creating a process instance
If we want to enable the correlation during process instance creation along with the initial json/xml request message following Boolean flags should be enabled. Those are
- skipInstanceCreationIfExist
- correlate
In addition to this, we did a slight modification to the original request to cater correlation support during process instance creation. That change can be briefed shortly in following way.
- In the previous process instance creation message contains all the variables with in the variables json array.
- but with the introduction of correlation, some times not all the variables mentioned within the variables json array is necessary for correlation task.
- Therefore, we introduced a new json array named "additionalVariables" to include the variables which are not relevant to correlation.
- But eventually once the correlation is completed and if the process instance is found, before prior to continuing with the execution of the workflow, the process instance will be updated with the variables inside the json array "additionalVariables".
Last but not least we have included the "messageName" variable to be included in the process instance request message.
Now lets go through the requests.
Scenario 1
As per this scenario we are creating the instance for the first time.
You will get the following response.
Scenario 2
In this scenario, we are not going to correlate with the existing instance. We are just going to look whether are there any instance exist with the given variable state. If there is an instance with the given state, it will return with the instance information.
Note the variable "correlate" has been made false. But "skipInstanceCreationIfExist" has been made true.
So there will be neither instance creation nor correlation.
This is the sample request
You will get the following response
Scenario 3
This scenario mainly focuses on correlation. You can notice that we are only interested in correlating with "corrId" variable. The other both variables are being added to the "additionalVariables" field.
This is the sample request.
And in the successful completion of execution, you will get HTTP Header with 204 (NO-CONTENT) message.
Eventually, you can notice all the variables are being updated in the instance as well.
This method will only work with message based correlation.