Apache Camel : "direct:start" endpoint - what does it mean ?

The "direct:start" above is simply saying that the route starts with a Direct Component named "start".

The direct endpoint provides synchronous invocation of a route. If you want to send an Exchange to the direct:start endpoint you would create a ProducerTemplate and use the various send methods.

ProducerTemplate template = context.createProducerTemplate();

template.sendBody("direct:start", "This is a test message");

There is nothing special about the name start. It is simply the name you are going to use when referring to the endpoint and could have just as easily been direct:foo.


Assume like the direct route as a method with name start , so we need to call the start method /direct route to perform certain operation. The below example will help .

The first route will be triggered when an input file is available in XXXX location and when it reaches line , the actual flow will go to second route. Basically the direct route with from endpoint will be triggered by some producer endpoint.

<route id="fileRoute">
   <from uri="file:XXXX">
      ..
   <to uri="direct:start">
</route>

<route id="directStartRoute">
    <from uri="direct:start">
    <to uri="http://myhost/mypath">
</route>

Apache Camel direct is basically for sending Exchange from one route to another in SAME Camel context. So let’s say you are getting message from AMQ and you want to populate headers for every message you get and then send it to mail recipient list. So here you need to create new router which has following description

from(“direct:populateHeaders”)
.setHeader(“myHeader”, “myHeaderValue”)
.end()

And from any route you can send your Exchange object to this route by writing

...

.to(“direct:populateHeaders”)

...

Its important to keep in mind that this will not work out of your Camel Context.