Red Hat Training

A Red Hat training course is available for Red Hat Fuse

5.3. Message Endpoint


A message endpoint is the interface between an application and a messaging system. As shown in Figure 5.3, “Message Endpoint Pattern”, you can have a sender endpoint, sometimes called a proxy or a service consumer, which is responsible for sending In messages, and a receiver endpoint, sometimes called an endpoint or a service, which is responsible for receiving In messages.

Figure 5.3. Message Endpoint Pattern

Message endpoint pattern

Types of endpoint

Apache Camel defines two basic types of endpoint:
  • Consumer endpoint — Appears at the start of a Apache Camel route and reads In messages from an incoming channel (equivalent to a receiver endpoint).
  • Producer endpoint — Appears at the end of a Apache Camel route and writes In messages to an outgoing channel (equivalent to a sender endpoint). It is possible to define a route with multiple producer endpoints.

Endpoint URIs

In Apache Camel, an endpoint is represented by an endpoint URI, which typically encapsulates the following kinds of data:
  • Endpoint URI for a consumer endpoint — Advertises a specific location (for example, to expose a service to which senders can connect). Alternatively, the URI can specify a message source, such as a message queue. The endpoint URI can include settings to configure the endpoint.
  • Endpoint URI for a producer endpoint — Contains details of where to send messages and includes the settings to configure the endpoint. In some cases, the URI specifies the location of a remote receiver endpoint; in other cases, the destination can have an abstract form, such as a queue name.
An endpoint URI in Apache Camel has the following general form:
Where ComponentPrefix is a URI prefix that identifies a particular Apache Camel component (see "Apache Camel Component Reference" for details of all the supported components). The remaining part of the URI, ComponentSpecificURI, has a syntax defined by the particular component. For example, to connect to the JMS queue, Foo.Bar, you can define an endpoint URI like the following:
To define a route that connects the consumer endpoint, file://local/router/messages/foo, directly to the producer endpoint, jms:Foo.Bar, you can use the following Java DSL fragment:
Alternatively, you can define the same route in XML, as follows:
<camelContext id="CamelContextID" xmlns="">
    <from uri="file://local/router/messages/foo"/>
    <to uri="jms:Foo.Bar"/>

Dynamic To

The <toD> parameter allows you to send a message to a dynamically computed endpoint using one or more expressions that are concatenated together.
By default, the Simple language is used to compute the endpoint. The following example sends a message to an endpoint defined by a header:
  <from uri="direct:start"/>
  <toD uri="${}"/>
In Java DSL the format for the same command is:
The URI can also be prefixed with a literal, as shown in the following example:
  <from uri="direct:start"/>
  <toD uri="mock:${}"/>
In Java DSL the format for the same command is:
In the example above, if the value of is orange, the URI will resolve as mock:orange.
To use a language other than Simple, you need to define the language: parameter. See Part II, “Routing Expression and Predicate Languages”.
The format for using a different language is to use language:languagename: in the URI. For example, to use Xpath use the following format:
  <from uri="direct:start"/>
  <toD uri="language:xpath:/order/@uri/">
Here is the same example in Java DSL:
If you do not specify language: then the endpoint is a component name. In some cases a component and a language have the same name, such as xquery.
You can concatenate multiple languages using a + sign. In the example below, the URI is a combination of Simple and Xpath languages. Simple is the default so the language does not have to be defined. After the + sign is the Xpath instruction, indicated by language:xpath.
  <from uri="direct:start"/>
  <toD uri="jms:${header.base}+language:xpath:/order/@id"/>
In Java DSL the format is as follows:
Many languages can be concatenated at one time, just separate each with a + and specify each language with language:languagename.
The following options are available with toD:
Name Default Value Description
uri Mandatory: The URI to use.
pattern Set a specific Exchange Pattern to use when sending to the endpoint. The original MEP is restored afterwards.
cacheSize Configure the cache size of the ProducerCache, which caches producers for reuse. The default cache size is 1000, which will be used if no other value is specified. Setting the value to -1 turns off the cache completely.
ignoreInvalidEndpoint false Specifies whether to ignore an endpoint URI that could not be resolved. If disabled, Camel will throw an exception identifying the invalid endpoint URI.