Business Processes are often long-running. These processes usually send messages (or make asynchronous calls) to external systems and then wait for responses from the external systems to come in at a much later time. The Process component of the Oracle Integration Cloud (OIC) supports this type of asynchronous communication with a Send and Receive activity pair. To most efficiently use the system resources, a Process instance goes into a dehydration state when the instance reaches the Receive activity. This means the state of the instance is stored in the OIC run-time database, and the execution thread is released back to the system. When a response message arrives at an OIC server, the Process engine restores the state of the instance and continues executing the instance from the Receive activity.
At any given time, there may be many instances of the same process waiting for response messages from the external systems. So the Process engine needs a way to identify which instance it needs to restore from a given incoming response message. The key to connect an incoming response message to a sleeping process instance is the Correlation.
Correlation is a feature in the OIC Process to support asynchronous communication between Process instances. Please note that correlation only works between Process instances. It does not work when an inbound message is from a non-Process source. To use correlation, we must complete the following three steps.
Create a named correlation key; create one or more properties; add one or more properties to the correlation key. See images below
Before using correlation for inter-process communication, a process must initialize the correlation key properties with values in an activity. The values can come from Input payload *(Input Context) or Output payload (Output Context). The combination of correlation key property values must be unique in the OIC Process engine. An instance of the correlation key can only be initialized and correlated once. See the following image.
In the Receive activity, the same correlation key must be selected and its property values specified from the inbound message payload. See the following image.
Now that we introduced Correlation, we can start building a simple application to demonstrate interactions between OIC Process and OIC Integration via Correlation. In this demo application, we will do the following,
Following the video below to create two integrations.
The image below shows the Integration applications after Step 1. Note that the application DemoIntegrationSync is complete. But the DemoIntegrationAsync is incomplete. It is missing a call back to a process. The process, which will be created in the next step, is dependent on the DemoIntegrationSync as it calls the DemoIntegrationSync. This is the reason we create Integration applications first. The DemoIntegrationAsync is dependent on the Receive activity of the process. So after we create the process, we will come back and complete the DemoIntegrationAsync.
In this step, we will create the main demo process, DemoProcess. Follow the video below to complete the demo process.
Pay special attention to the Send and Receive activity pair to see how correlation is implemented. The following diagram illustrates the main DemoProcess and how it interacts with the Integration applications. Notice the gray line, it indicates the call back from the DemoIntegrationAsync is still missing. This is what we will do in Step 4. But let's do a quick test of the system we just completed in Step 3.
You can see a quick test on what we have built in the following video,
Notice that the Receive activity is highlighted in yellow, which indicates it is active for this instance. Of course, it will never be completed because of no callback from the Integration.
The video below shows details of adding a callback to the DemoIntegrationAsync.
Notice that the callback is not directly to the Receive activity of the DemoProcess. Instead, an additional process is created to take the callback from the DemoIntegrationAsync, and it then passes the payload to the Receive activity of the DemoProcess. This is extra process is necessary because Correlation only works between two processes. The image below shows how messages and correction ID flow through different components.
Step 5, End to End Test with Callback
The following video shows the final end to end test.
We can see the Receive activity in the main DemoProcess is completed (green) after a few seconds of delay. We can also see the two Integration instances. Due to the mock-up delay, we notice the DemoIntegrationAsync instance completed a few seconds later than the DemoIntegrationSync instance, as shown below.
This blog post described the correlation feature in OIC Process and demonstrated how correlation can be used to facilitate communications between the OIC Process and Integration.