Kamelet
Kamelets (Kamel route snippets) allow users to connect to external systems via a simplified interface, hiding all the low level details about how those connections are implemented.
The Kamelet EIP allows calling Kamelets (i.e. Route Template), for special use-cases.
When a Kamelet is designed for a special use-case such as aggregating messages, and returning a response message only when a group of aggregated message is completed. In other words the kamelet does not return a response message for every incoming message. In special situations like these, then you must use this Kamelet EIP instead of using the kamelet component.
Given the following Kamelet (as a route template):
routeTemplate("my-aggregate")
.templateParameter("count")
.from("kamelet:source")
.aggregate(constant(true))
.completionSize("{{count}}")
.aggregationStrategy(AggregationStrategies.string(","))
.to("log:aggregate")
.to("kamelet:sink")
.end();
Note how the route template above uses kamelet:sink as a special endpoint to send out a result message. This is only done when the Aggregate EIP has completed a group of messages. |
And the following route using the kamelet:
from("direct:start")
// this is not possible, you must use Kamelet EIP instead
.to("kamelet:my-aggregate?count=5")
.to("log:info")
.to("mock:result");
Then this does not work, instead you must use Kamelet EIP instead:
from("direct:start")
.kamelet("my-aggregate?count=5")
.to("log:info")
.to("mock:result");
When calling a Kamelet you may just refer to the name (template id) of the Kamelet in the EIP as shown below:
Options
The Kamelet eip supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
name | Required Name of the Kamelet (templateId/routeId) to call. Options for the kamelet can be specified using uri syntax, eg mynamecount=4&type=gold. | String | |
disabled | Whether to disable this EIP from the route during build time. Once an EIP has been disabled then it cannot be enabled later at runtime. | false | Boolean |
description | Sets the description of this node. | DescriptionDefinition |
Using Kamelet EIP
from("direct:start")
.kamelet("foo")
.to("mock:result");
And in XML
<route>
<from uri="direct:start"/>
<kamelet name="foo"/>
<to uri="mock:result"/>
</route>
Camel will then, when starting:
-
Lookup the Route Template with the given id (in the example above its foo) from the
CamelContext
-
Create a new route based on the Route Template
Dependency
The implementation of the Kamelet EIP is located in the camel-kamelet
JAR, so you should add the following dependency:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-kamelet</artifactId>
<!-- use the same version as your Camel core version -->
<version>x.y.z</version>
</dependency>
See Also
See the example camel-example-kamelet.