Route EndPoints (Technical Guide)
Endpoints are the sources and destinations of messages in our route. An endpoint is a very general sort of building block: the only requirement it must satisfy is that it acts either as a source of messages (a producer endpoint) or as a sink of messages (a consumer endpoint). Hence, there are a great variety of different endpoint types supported in Apache Camel, ranging from protocol supporting endpoints, such as HTTP, to simple timer endpoints, such as Quartz, that generate dummy messages at regular time intervals. One of the major strengths of Apache Camel is that it is relatively easy to add a custom component that implements a new endpoint type.
Endpoint URIs
Endpoints are defined by endpoint URIs, which have the following form:
scheme:contextPath
NOTE: The URI scheme will identify 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.
Examples of URIs:
http://www.google.com
file://c:/temp/src/data
NOTE: In the above example, HTTP URI is used to connect to Google and File URI will be used to read all files related to that file directory.
Configure Endpoints
Sometimes our endpoint URIs can become quite long since there may be accompanying configuration information that must be applied. There are two approaches to endpoint configuration:
Â
Configure Endpoints Separately
We can configure our endpoints separately, and then refer to them from within the route:
<endpoint id="myEndpoint" uri="ftp://foo@myserver">
<property name="password" value="secret"/>
<property name="recursive" value="true"/>
<property name="ftp.dataTimeout" value="50000"/>
</endpoint>
<route>
<from uri="ref:myEndPoint"/>
...
</route>
Â
Use of Property Attribute
We can configure options in the URI and then use a property attribute to define more options or to possibly override any options for URI).
Â
Apache Camel Components
Each of the different types of URI schemes will map to an Apache Camel component, where an Apache Camel component is essentially an endpoint factory. Therefore, to use a particular type of endpoint, you must also deploy the correct Apache Camel component into the runtime container. For example, to use JMS endpoints, you will need to deploy the JMS component into your container.
Apache Camel provides a wide variety of components that will allow you to integrate your application with various well-known transport protocols and third-party products (ie. for example, File, JMS, CXF (Web services), HTTP, Jetty, Direct, and Mock).
Most of these components are packaged separately from the Camel core. If Maven is used to build your application, then you can easily add a component (and its third-party dependencies) to your application by adding a dependency on the relevant artifact.
The following components are built-in to the Camel core (in the camel-core artifact), so they are always available:
Bean
Browse
Dataset
Direct
File
Log
Mock
Properties
Ref
SEDA
Timer
VM
Consumer endpoints
This is an endpoint that appears at the start of a route (that is, in a from()
DSL command). The consumer endpoint is responsible for initiating processing in a route: it will create a new exchange instance (based on a message received or obtained), and then provides a thread to process the exchange in the rest of the route.
Producer endpoints
This is an endpoint that appears in the middle or at the end of a route (ie., in a to()
DSL command). The producer endpoint receives an existing exchange object and then proceeds to send the contents of the exchange to the specified endpoint.