Chapter 7. Message Construction

download PDF


The message construction patterns describe the various forms and functions of the messages that pass through the system.

7.1. Correlation Identifier


The correlation identifier pattern, shown in Figure 7.1, “Correlation Identifier Pattern”, describes how to match reply messages with request messages, given that an asynchronous messaging system is used to implement a request-reply protocol. The essence of this idea is that request messages should be generated with a unique token, the request ID, that identifies the request message and reply messages should include a token, the correlation ID, that contains the matching request ID.

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

When working with the ActiveMQ or JMS components, the correlation identifier header is called JMSCorrelationID. You can add your own correlation identifier to any message exchange to help correlate messages together in a single conversation (or business process). A correlation identifier is usually stored in a Apache Camel message header.

Some EIP patterns spin off a sub message and, in those cases, Apache Camel adds a correlation ID to the Exchanges as a property with they key, Exchange.CORRELATION_ID, which links back to the source Exchanges. For example, the Section 8.4, “Splitter”, Section 8.13, “Multicast”, Section 8.3, “Recipient List”, and Section 11.3, “Wire Tap” EIPs do this.

Figure 7.1. Correlation Identifier Pattern

Correlation identifier pattern

7.2. Event Message

Event Message

Camel supports the Event Message from the Chapter 3, Introducing Enterprise Integration Patterns by supporting the Exchange Pattern on a Section 5.1, “Message” which can be set to InOnly to indicate a oneway event message. Camel olink:IDU-Components/IDU-Components then implement this pattern using the underlying transport or protocols.

event message solution

The default behavior of many olink:IDU-Components/IDU-Components is InOnly such as for olink:IDU-Components/IDU-JMS, olink:IDU-Components/IDU-File2 or olink:IDU-Components/IDU-SEDA

Explicitly specifying InOnly

If you are using a component which defaults to InOut you can override the the section called “Message exchange patterns” for an endpoint using the pattern property.


From 2.0 onwards on Camel you can specify the the section called “Message exchange patterns” using the dsl.

Using the Fluent Builders


or you can invoke an endpoint with an explicit pattern


Using the Spring XML Extensions

    <from uri="mq:someQueue"/>
    <inOnly uri="bean:foo"/>
    <from uri="mq:someQueue"/>
    <inOnly uri="mq:anotherQueue"/>

7.3. Return Address

Return Address

Apache Camel supports the Return Address from the Chapter 3, Introducing Enterprise Integration Patterns using the JMSReplyTo header.

return address solution

For example when using olink:IDU-Components/IDU-JMS with InOut, the component will by default be returned to the address given in JMSReplyTo.


Requestor Code

 getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
 template.sendBodyAndHeader("direct:start", "World", "JMSReplyTo", "queue:bar");

Route Using the Fluent Builders

 from("activemq:queue:foo").transform(body().prepend("Bye "));

Route Using the Spring XML Extensions

   <from uri="direct:start"/>
   <to uri="activemq:queue:foo?preserveMessageQos=true"/>

   <from uri="activemq:queue:foo"/>
       <simple>Bye ${in.body}</simple>

   <from uri="activemq:queue:bar?disableReplyTo=true"/>
   <to uri="mock:bar"/>

For a complete example of this pattern, see this junit test case

Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.