Example of Using Correlation with Send and Receive
Correlations are typically used with send and receive activities to communicate between processes. Send and receive activities use correlations to make sure that incoming messages are properly correlated with the right process instances at run time.
Let's explore with a simple use case how we can use correlation with send and receive activities to design processes that communicate with each other. Suppose we configure two processes: Order process and Vendor process. The Order process initiates order for an item. It calls the Vendor process to check if the ordered item is available and gets a quote for the item. If the ordered item is available in the vendor's inventory, then the Vendor process sends a message to the Order process with a quote for the item. To ensure that the response sent by the called process is received by the correct calling process instance, correlation is set up.
- When the Order process is started, the correlation key with the
order id
is initialized. Theorder id
is a data object of the Order process. The engine will store the key for that instance of the Order process. - The Order process uses a Send activity to send the
order id
to the Vendor process. - The Vendor process uses a Send activity to callback with the
order id
. - A Receive activity in the Order process checks if the
order id
that was sent by the Vendor process matches the correlation key that was initialized when the Order process instance was started. If theorder id
matches the correlation key then that confirms that the response received by the Order process instance is from the corresponding Vendor process instance that was called.