With Clause and the Correlation Property
The first term in a with clause must be a correlation property. It is also sometimes referred to as the subscription property.
Specify a property that will uniquely identify the event or related events. Instances of all the event types in the pattern that are being correlated must have the same property value for the correlation to succeed. For example if the correlation is a.name and b.name then the correlation succeeds if the value of name is Joe in both cases.
Each instance of a pattern has an ID which is derived from this correlation property's value. If multiple pattern instances exist simultaneously, the property values must be unique per pattern instance.
For example:
with order.customerId and shipment.customerId
In the above example, order and shipment events that share the same customerId will be correlated.
Here is an example of simple correlation:
with a.id and b.id
In the above case, the pattern succeeds when the following occurs:
- The value of the id property in an instance of event type b matches the value of the id property in an instance of event type a.
- And the order in which these two events arrives matches the order specified in the starts with... then... clauses.
You can use correlation with one event type. In this case the starts with... then... clauses specify the temporal conditions that instances of that event must meet.