Correlation Identifier

Camel supports the Correlation Identifier from the EIP patterns by getting or setting a header on the Message.

When working with the JMS components the correlation identifier header is called JMSCorrelationID, and they handle the correlation automatically.

Other messaging systems, such as Spring RabbitMQ also handles this automatic, and you should generally not have a need for using custom correlation IDs with these systems.

image

You can use your own correlation identifier to any message exchange to help correlate messages together to a single conversation (or business process). For example if you need to correlation messages when using web services.

The use of a correlation identifier is key to working with Distributed Tracing and be useful when using Tracer messages to log, or testing with simulation or canned data such as with the Mock testing framework.

EIPs using correlation identifiers

Some EIP patterns will spin off a sub message, and in those cases, Camel will add a correlation id on the Exchange as a property with they key Exchange.CORRELATION_ID, which links back to the source Exchange and its exchange id.

The following EIPs does this:

Example

The following example uses a request/reply pattern in the JMS component, where correlation identifiers are automatically handled:

from("direct:start")
    .to(ExchangePattern.InOut, "jms:queue:foo")
    .to("mock:result");

And with XML DSL:

<route>
    <from uri="direct:start"/>
    <to pattern="InOut" uri="jms:queue:foo"/>
    <to uri="mock:result"/>
</route>