Apache Camel endpoints are the sources and sinks of messages in a route. An endpoint is a general sort of building block: the only requirement it must satisfy is that it acts either as a source of messages (a consumer endpoint) or as a sink of messages (a producer endpoint). Hence, there are a great variety of different endpoint types supported in Apache Camel. They range from protocol supporting endpoints, such as HTTP, to simple timer endpoints, such as Quartz, that generate dummy messages at regular time intervals.
Endpoints are identified by endpoint URIs, which have the form:
scheme:contextPath[?queryOptions]
The URI scheme identifies a protocol, such as http,
and the contextPath provides URI details that are interpreted by
the protocol. In addition, most schemes allow you to define query options,
queryOptions, which are specified in the following format:
?option01=value01&option02=value02&...
For example, the following HTTP URI can be used to connect to the Google search engine page:
http://www.google.com
The following File URI can be used to read all of the files appearing under the
C:\temp\src\data directory:
file://C:/temp/src/data
Not every scheme represents a protocol. Sometimes a
scheme just provides access to a useful utility, such as a timer.
For example, the following Timer endpoint URI generates an exchange every second
(1000 milliseconds). You could use this to schedule activity in a route.
timer://tickTock?period=1000
Each URI scheme maps to a Apache Camel
component. A Apache Camel component is an endpoint factory. To use a particular
type of endpoint, you must deploy the corresponding Apache Camel component along with the
route. For example, to use JMS endpoints, you would deploy the JMS component.
Apache Camel provides a large variety of different components that enable you to integrate your application with various transport protocols and third-party products. For example, some of the more commonly used components are: File, JMS, CXF (Web services), HTTP, Jetty, Direct, and Mock. For the full list of supported components, see Component Reference.
Most of the Apache Camel components are packaged separately to the Camel core. If you use Maven to build your application, you can easily add a component (and its third-party dependencies) to your application simply by adding a dependency on the relevant component artifact. Example 1.4 shows the dependency needed to include the HTTP component to a project.
Example 1.4. Adding HTTP component dependency
<!-- Maven POM File -->
<properties>
<camel-version>2.7.1-fuse-00-27</camel-version>
...
</properties>
<dependencies>
...
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>${camel-version}</version>
</dependency>
...
</dependencies>The following components are built-in to the the camel-core artifact, so
they are always available:
Bean
Browse
Dataset
Direct
File
Log
Mock
Properties
Ref
SEDA
Timer
VM
A consumer endpoint is an endpoint that appears at the
start of a route in a from element. The consumer endpoint
is responsible for initiating processing in a route: it creates a new exchange instance, and
provides a thread to process the exchange in the rest of the route.
The JMS consumer endpoint in Example 1.5 pulls messages off
the payments queue and processes them in the route.
Example 1.5. JMS consumer endpoint
<camelContext id="CamelContextID" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="jms:queue:payments"/> <process ref="someProcessorId"/> <to uri="TargetURI"/> </route> </camelContext>
Some components are consumer only and can only be used to define consumer endpoints. For example, the Quartz component is used exclusively to define consumer endpoints.
A producer endpoint is an endpoint that appears in the
middle or at the end of a route. For example, a to
element specifies a producer endpoint. The producer endpoint receives an exchange object
and sends the contents of the exchange to the specified endpoint.
The JMS producer endpoint in Example 1.6 pushes the contents of the current exchange onto the specified JMS queue.
Example 1.6. JMS producer endpoint
<camelContext id="CamelContextID" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="SourceURI"/> <process ref="someProcessorId"/> <to uri="jms:queue:orderForms"/> </route> </camelContext>
Some components are producer only and can only be used to define producer endpoints. For example, the HTTP endpoint is used exclusively to define producer endpoints.
Many of the Fuse Mediation Router components have options whose value is a time period (for example, for specifying timeout values and so on). By default, such time period options are normally specified as a pure number, which is interpreted as a millisecond time period. But Fuse Mediation Router also supports a more readable syntax for time periods, which enables you to express the period in hours, minutes, and seconds. Formally, the human-readable time period is a string that conforms to the following syntax:
[NHour(h|hour)][NMin(m|minute)][NSec(s|second)]
Where each term in square brackets, [], is optional and the notation,
(A|B), indicates that A and B are
alternatives.
Example 1.7 configures a timer
endpoint with a 45 minute period.
You can also use arbitrary combinations of the hour, minute, and second units, as shown in Example 1.8.
Example 1.8. Timers
<route> <from uri="timer:foo?period=1h15m" /> <to uri="log:foo" /> </route> <route> <from uri="timer:bar?period=2h30s" /> <to uri="log:bar" /> </route> <route> <from uri="timer:bar?period=3h45m58s" /> <to uri="log:bar" /> </route>








