Camel Components

Kamelet

Since Camel 3.8

Both producer and consumer are supported

The Kamelet Component provides support for interacting with the Camel Route Template engine using Endpoint semantic.

URI format

kamelet:templateId/routeId[?options]

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Kamelet component supports the following options which are listed below.

Name Description Default Type

location (common)

Where to load a Kamelet from when the CamelContext has no route template with its name yet. A location with a file extension is loaded as that file; other locations are directories with a file named after the Kamelet, such as timer-source.kamelet.yaml. Uses the resource syntax (classpath:, file:, http: and so on, classpath when there is no scheme), without wildcards. Several locations can be separated by comma, and the first that exists is used. The location option of an endpoint replaces it.

classpath:kamelets

String

routeProperties (common)

Properties of the Kamelets for one use of a Kamelet, by the route id of the endpoint (kamelet:name/routeId), such as camel.component.kamelet.route-properties[fast].period=1000. They win over templateProperties. Once a templateProperties or routeProperties value applies to a Kamelet, no camel.kamelet.* property is read for it. Environment variables and endpoint parameters win over these.

Map

templateProperties (common)

Properties of the Kamelets for every use of a Kamelet, by the name of the Kamelet, such as camel.component.kamelet.template-properties[timer-source].period=1000. Once a templateProperties or routeProperties value applies to a Kamelet, no camel.kamelet.* property is read for it. Environment variables and endpoint parameters win over these.

Map

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

block (producer)

Whether the producers of the Kamelet endpoints wait, up to the timeout, for the consumer of the endpoint when it has none, such as while the route that consumes from it is not started yet, or is suspended or stopped. When false, or when the timeout passes, the failIfNoConsumers option of the endpoint decides what happens to the message.

true

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

timeout (producer)

The time in milliseconds the producers of the Kamelet endpoints wait for a consumer when block is enabled. A value of 0 or less does not wait.

30000

long

advancedOptions (advanced)

Whether the URI parameters that are neither properties of the Kamelet nor options of the endpoint are also appended to the endpoint the Kamelet wraps, overriding the same option in its URI: the endpoint the route of a source Kamelet consumes from, or the one top-level to() endpoint of a sink or action Kamelet. Creating the route fails when a sink or action Kamelet has no such endpoint or several, or uses toD, enrich or pollEnrich. The advancedOptions option of an endpoint overrides it.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

noErrorHandler (advanced)

Whether the routes of the Kamelets run without an error handler. By default the route of a Kamelet uses a copy of the error handler (and the route configuration) of the route that uses the Kamelet, so its redeliveries and dead letter channel apply inside the Kamelet as well; it has no error handler when the step that uses the Kamelet is not wrapped in an error handler, or when that route is itself the route of a Kamelet. When true, an exception in a source Kamelet is handled by the consumer of the Kamelet route (most consumers log it), and an exception in a sink or action Kamelet fails the exchange, which returns to the calling route.

false

boolean

routeTemplateLoaderListener (advanced)

Autowired A listener that is called with each resource the component loads a Kamelet from (by the location option), before the resource is loaded. An exception it throws is logged and ignored.

RouteTemplateLoaderListener

Endpoint Options

The Kamelet endpoint is configured using URI syntax:

kamelet:templateId/routeId

With the following path and query parameters:

Path Parameters

Name Description Default Type

templateId (common)

Required The name of the Kamelet, which is the id of its route template, such as timer-source. Inside the template of a Kamelet, kamelet:source is the endpoint its route consumes from (the message sent to the Kamelet), and kamelet:sink the endpoint it hands its result to.

String

routeId (advanced)

The id of the route that is created from the Kamelet for this endpoint. It also selects the properties for this use of the Kamelet only: for kamelet:timer-source/fast, the property camel.kamelet.timer-source.fast.period, the environment variable CAMEL_KAMELET_TIMER_SOURCE_FAST_PERIOD and the routeProperties of the component with the key fast. Endpoints with the same route id use one route. Default value notice: The ID will be auto-generated if not provided.

String

Query Parameters

Name Description Default Type

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

block (producer (advanced))

Whether the producer waits, up to the timeout, for the consumer of the Kamelet endpoint when it has none, such as while the route that consumes from it is not started yet, or is suspended or stopped. When false, or when the timeout passes, failIfNoConsumers decides what happens to the message.

true

boolean

failIfNoConsumers (producer (advanced))

Whether the producer fails the exchange with a KameletConsumerNotAvailableException when the Kamelet endpoint has no active consumer (after waiting, when block is enabled). When false, the message is not sent, and the exchange continues unchanged.

true

boolean

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

timeout (producer (advanced))

The time in milliseconds the producer waits for a consumer when block is enabled. A value of 0 or less does not wait.

30000

long

advancedOptions (advanced)

Whether the URI parameters that are neither properties of the Kamelet nor options of this endpoint are also appended to the endpoint the Kamelet wraps, overriding the same option in its URI: the endpoint the route of a source Kamelet consumes from, or the one top-level to() endpoint of a sink or action Kamelet. Creating the route fails when a sink or action Kamelet has no such endpoint or several, or uses toD, enrich or pollEnrich.

false

boolean

location (advanced)

Where to load this Kamelet from, instead of the location of the component. It is read only when the CamelContext has no route template with the name of the Kamelet yet. A location with a file extension is loaded as that file, for example file:/etc/camel/my-source.kamelet.yaml; other locations are directories with a file named after the Kamelet, such as timer-source.kamelet.yaml. Uses the resource syntax (classpath:, file:, http: and so on, classpath when there is no scheme), without wildcards. Several locations can be separated by comma, and the first that exists is used.

String

noErrorHandler (advanced)

Whether the route of the Kamelet runs without an error handler. By default the route of the Kamelet uses a copy of the error handler (and the route configuration) of the route that uses the Kamelet, so its redeliveries and dead letter channel apply inside the Kamelet as well; it has no error handler when the step that uses the Kamelet is not wrapped in an error handler, or when that route is itself the route of a Kamelet. When true, an exception in a source Kamelet is handled by the consumer of the Kamelet route (most consumers log it), and an exception in a sink or action Kamelet fails the exchange, which returns to the calling route.

false

boolean

Message Headers

The Kamelet component supports the following message header(s), which is/are listed below:

Name Description Default Type

Content-Type (consumer)

Constant: CONTENT_TYPE

The content type of the message that a Kamelet source with an output data type hands to the route that consumes it. With the binary output data type and a stream body, the component keeps the stream and sets this header to application/octet-stream; otherwise the transformer of the data type may set it when it converts the body.

String

Message Body

The message body at each side of the Kamelet component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

unknown

The body the Kamelet sends, as its data types or its template say. In the template of a Kamelet, kamelet:source gives the body the caller sent.

Producer input

any

Producer output

unknown

The body the template of the Kamelet ends with.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

The kamelet endpoint is lenient, which means that the endpoint accepts additional parameters that are passed to the Route Template engine and consumed upon route materialization.

Usage

Discovery

If a Route Template is not found, the kamelet endpoint tries to load the related kamelet definition from the location of the component (by default classpath:kamelets). The default resolution mechanism expects Kamelets files to have the extension .kamelet.yaml.

Configuring a Kamelet

The parameters of a Kamelet can be set in four places. When a parameter is set in more than one, the one higher in this list wins:

  1. The endpoint parameters: kamelet:timer-source?message=Hello, or parameters in YAML.

  2. An environment variable CAMEL_KAMELET_<NAME>_<PARAMETER>. The name of the Kamelet and of the parameter are written in capitals, with _ between the words: the parameter bucketNameOrArn of aws-s3-source is CAMEL_KAMELET_AWS_S3_SOURCE_BUCKET_NAME_OR_ARN.

  3. A property camel.kamelet.<name>.<parameter>, such as camel.kamelet.timer-source.message=Hello, for every use of the Kamelet.

  4. The default of the parameter, in the Kamelet.

A use of a Kamelet can be given an id after its name, kamelet:<name>/<id>. The property camel.kamelet.<name>.<id>.<parameter> and the environment variable CAMEL_KAMELET_<NAME>_<ID>_<PARAMETER> then apply to that use only, and win over the ones for every use:

camel.kamelet.timer-source.message=Hello
camel.kamelet.timer-source.fast.period=1000
- route:
    from:
      uri: kamelet:timer-source/fast
      steps:
        - to:
            uri: kamelet:log-sink

The component options template-properties and route-properties hold parameters too: camel.component.kamelet.template-properties[<name>].<parameter> for every use and camel.component.kamelet.route-properties[<id>].<parameter> for one use. Use one style or the other: once any template-properties or route-properties value applies to a Kamelet, no camel.kamelet.* property is read for it, and those parameters fall back to their defaults. The environment variables and the endpoint parameters still apply.

A required parameter that is not set fails the route when it starts, such as Route template timer-source the following mandatory parameters must be provided: message.

These names belong to the kamelet endpoint and are never passed to the Kamelet: templateId, routeId, location, uuid, and the endpoint options block, timeout, failIfNoConsumers, noErrorHandler, advancedOptions, bridgeErrorHandler, exceptionHandler, exchangePattern and lazyStartProducer. A Kamelet should not have a parameter with one of these names.

An optional parameter that is not set, written {{?user}} in the template, is still looked up as a property placeholder, and so also in the environment under its name in capitals: an unset user takes the value of USER.

For the Kamelets of the catalog, see also the page Using Kamelets in the Kamelet Catalog documentation.

Writing a custom Kamelet

You can write your own Kamelets, for a piece of an integration that several routes need. A Kamelet is a .kamelet.yaml file with a route template and a description of its parameters, and it is one of three kinds, set by the camel.apache.org/kamelet.type label:

  • source: produces messages, and is used as the start of a route (from: kamelet:<name>).

  • sink: receives the message of a route and sends it somewhere (to: kamelet:<name>).

  • action: changes the message as a step in the middle of a route (to: kamelet:<name>).

See Writing a custom Kamelet for the file, with an example of each kind.

Error Handling

The error handling when using kamelets are using the same error handling that are from the route where the kamelets are being used.

Suppose you have kamelets that would cause an exception during processing, such as the source below. Now because the route has been configured with a dead letter channel as the error handler, then the exception from the kamelet will be handled by the route error handler. Which means you will se a WARN being logged.

- route:
    errorHandler:
      deadLetterChannel:
        deadLetterUri: log:dead?level=WARN
    id: myRoute
    from:
      uri: kamelet:my-error-source/source
      steps:
        - log:
            message: "${body}"

For sink kamelets then error handling also allows to perform retries.

So suppose you have the following route:

- route:
    errorHandler:
      deadLetterChannel:
        deadLetterUri: log:dead?level=WARN
        redeliveryPolicy:
          maximumRedeliveries: 5
          redeliveryDelay: "5000"
    id: myRoute
    from:
      uri: direct:start
      steps:
        - to:
            uri: kamelet:my-error-sink/sink
        - log:
            message: "${body}"

Then notice the error handler has been configured to do redeliveries up till 5 times with 5 sec delay between. Suppose the sink kamelet is throwing an exception, then Camel will now perform the redelivery attempt at the point of origin, which means inside the Kamelet.

Calling a Kamelet from another Kamelet

this feature is available since version 4.10.0 onward

As a Kamelet behave as any other regular component, you will be able to use it in a nested way. The definition of a Kamelet can contains the reference to another Kamelet which will give you a high level of flexibility when constructing your abstraction.

In the following example, we are creating a Kamelet which is calling a bundled catalog Kamelet log-sink:

apiVersion: camel.apache.org/v1
kind: Kamelet
metadata:
  name: nested-sink
spec:
  definition:
    title: "Kamelet in a Kamelet"
    description: A Kamelet calling another Kamelet
    required:
      - log-level
    properties:
      log-level:
        title: The Kamelet log-sink log level
        description: The Kamelet log-sink log level
        type: string
        example: DEBUG
  dependencies:
  - "camel:core"
  - "camel:kamelet"
  template:
    from:
      uri: kamelet:source
      steps:
      - to:
          uri: kamelet:log-sink
          parameters:
            level: "{{log-level}}"

According to the specification, this Kamelet expects a parameter, log-level which we will use as a further parameter for the downstream call to the log-sink Kamelet.

The usage of this Kamelet into a Camel route is going to be the same as any other Kamelet:

- route:
    from:
      uri: timer:yaml
      parameters:
        period: "5000"
      steps:
        - setBody:
            simple: "Hello Camel from ${routeId}"
        - to:
            uri: kamelet:nested-sink
            parameters:
              log-level: INFO
beware of any potential circular reference you may introduce when using chain of Kamelets, in which case, the runtime will likely be idle consuming a high amount of resources.

Advanced component endpoint options

Kamelets expose a defined set of parameters, but the underlying Camel component may support additional endpoint options. You can forward those options by enabling advancedOptions (disabled by default).

When enabled, extra URI parameters that are not Kamelet template properties and not reserved Kamelet options (routeId, templateId, location, advancedOptions, and the other kamelet endpoint options) are appended to the endpoint wrapped by the Kamelet.

Enable the feature on the component, or on a single endpoint. The endpoint setting overrides the component setting.

camel.component.kamelet.advanced-options=true
  • Java

  • YAML

from("kamelet:aws-s3-source?advancedOptions=true&bucketNameOrArn=x&maxConnections=100")
    .to("log:info");
- route:
    from:
      uri: kamelet:aws-s3-source
      parameters:
        advancedOptions: true
        bucketNameOrArn: x
        maxConnections: 100
      steps:
        - to:
            uri: log:info

In this example, bucketNameOrArn is a template property of the Kamelet and stays a template parameter. maxConnections=100 is forwarded to the wrapped aws2-s3 endpoint. If that endpoint URI already contains the same option, the advanced option overrides its existing value.

Source Kamelets forward extra options to their input endpoint. Sink and action Kamelets forward extra options to the Kamelet’s main to() endpoint.

The options are applied only when the Kamelet has exactly one eligible top-level, statically-defined to() destination. Kamelet endpoints and auxiliary destinations such as wireTap() are excluded. Nested branch destinations, such as those inside choice() or doTry(), are not considered eligible main destinations.

If an action Kamelet has no wrapped endpoint, or the Kamelet contains multiple eligible top-level destinations, or it uses a dynamic destination such as toD(), enrich(), or pollEnrich(), startup fails with an explanatory exception when advanced options are supplied. In these cases, configure the options directly on the intended endpoint URI.

Property placeholders and RAW expressions in endpoint URIs are preserved when advanced options are applied. For example, kafka:{{topic}} or aws2-s3:{{bucket}}?secretKey=RAW({{secret}}) remain intact.

The advanced options are forwarded as they are written in the Kamelet URI. Percent-encoded values, RAW(…​) values and repeated parameters reach the wrapped endpoint the same way as when the options are set on that endpoint directly.

When advancedOptions is disabled or omitted, the Kamelet retains its existing configuration behavior.

Examples

Kamelets can be used as if they were standard Camel components. For example, suppose that we have created a Route Template as follows:

Java-only: programmatic route template definition
routeTemplate("setMyBody")
    .templateParameter("bodyValue")
    .from("kamelet:source")
        .setBody().constant("{{bodyValue}}");

To let the Kamelet component wiring the materialized route to the caller processor, we need to be able to identify the input and output endpoint of the route and this is done by using kamelet:source to mark the input endpoint and kamelet:sink for the output endpoint.

Then the template can be instantiated and invoked as shown below:

  • Java

  • XML

  • YAML

from("direct:setMyBody")
    .to("kamelet:setMyBody?bodyValue=myKamelet");
<route>
  <from uri="direct:setMyBody"/>
  <to uri="kamelet:setMyBody?bodyValue=myKamelet"/>
</route>
- route:
    from:
      uri: direct:setMyBody
      steps:
        - to:
            uri: kamelet:setMyBody
            parameters:
              bodyValue: myKamelet

Behind the scenes, the Kamelet component does the following things:

  1. it instantiates a route out of the Route Template identified by the given templateId path parameter (in this case setMyBody)

  2. it will act like the direct component and connect the current route to the materialized one.

If you had to do it programmatically, it would have been something like:

Java-only: programmatic TemplatedRouteBuilder usage
routeTemplate("setMyBody")
    .templateParameter("bodyValue")
    .from("direct:{{foo}}")
        .setBody().constant("{{bodyValue}}");

TemplatedRouteBuilder.builder(context, "setMyBody")
    .parameter("foo", "bar")
    .parameter("bodyValue", "myKamelet")
    .add();

from("direct:template")
    .to("direct:bar");