Chapter 158. YAML DSL


Since Camel 3.9

The YAML DSL provides the capability to define your Camel routes, route templates & REST DSL configuration in YAML.

158.1. Defining a route

A route is a collection of elements defined as follows:

- from: 
1

    uri: "direct:start"
    steps: 
2

      - filter:
          expression:
            simple: "${in.header.continue} == true"
          steps:
            - to:
                uri: "log:filtered"
      - to:
          uri: "log:original"
Copy to Clipboard

Where,

1
Route entry point, by default from and rest are supported.
2
Processing steps
Note

Each step represents a YAML map that has a single entry where the field name is the EIP name.

As a general rule, each step provides all the parameters the related definition declares, but there are some minor differences/enhancements:

  • Output Aware Steps

Some steps, such as filter and split, have their own pipeline when an exchange matches the filter expression or for the items generated by the split expression. You can define these pipelines in the steps field:

filter:
  expression:
    simple: "${in.header.continue} == true"
    steps:
      - to:
          uri: "log:filtered"
Copy to Clipboard
  • Expression Aware Steps

Some EIP, such as filter and split, supports the definition of an expression through the expression field:

Explicit Expression field

filter:
  expression:
    simple: "${in.header.continue} == true"
Copy to Clipboard

To make the DSL less verbose, you can omit the expression field.

Implicit Expression field

filter:
  simple: "${in.header.continue} == true"
Copy to Clipboard

In general, expressions can be defined inline, such as within the examples above but if you need provide more information, you can 'unroll' the expression definition and configure any single parameter the expression defines.

Full Expression definition

filter:
  tokenize:
    token: "<"
    end-token: ">"
Copy to Clipboard

  • Data Format Aware Steps

The EIP marshal and unmarshal supports the definition of data formats:

marshal:
  json:
    library: Gson
Copy to Clipboard
Note

In case you want to use the data-format’s default settings, you need to place an empty block as data format parameters, like json: {}

158.2. Defining endpoints

To define an endpoint with the YAML DSL you have two options:

  • Using a classic Camel URI:
- from:
    uri: "timer:tick?period=1s"
    steps:
      - to:
          uri: "telegram:bots?authorizationToken=XXX"
Copy to Clipboard
  • Using URI and parameters:
- from:
    uri: "timer://tick"
    parameters:
      period: "1s"
    steps:
      - to:
          uri: "telegram:bots"
          parameters:
            authorizationToken: "XXX"
Copy to Clipboard

158.3. Defining beans

In addition to the general support for creating beans provided by Camel Main, the YAML DSL provide a convenient syntax to define and configure them:

- beans:
  - name: beanFromMap  
1

    type: com.acme.MyBean 
2

    properties: 
3

      foo: bar
Copy to Clipboard

Where,

1
The name of the bean which will bound the instance to the Camel Registry.
2
The full qualified class name of the bean
3
The properties of the bean to be set

The properties of the bean can be defined using either a map or properties style, as shown in the example below:

- beans:
  # map style
  - name: beanFromMap
    type: com.acme.MyBean
    properties:
      field1: 'f1'
      field2: 'f2'
      nested:
        field1: 'nf1'
        field2: 'nf2'
  # properties style
  - name: beanFromProps
    type: com.acme.MyBean
    properties:
      field1: 'f1_p'
      field2: 'f2_p'
      nested.field1: 'nf1_p'
      nested.field2: 'nf2_p'
Copy to Clipboard
Note

The beans elements is only used as root element.

158.4. Configuring Options

Camel components are configured on two separate levels:

  • component level
  • endpoint level

158.4.1. 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.

158.4.2. 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.

158.5. Configuring Options on languages

Some languages have additional configurations that you may need to use.

For example, the JSONPath can be configured to ignore JSON parsing errors. This is intended when you use a Content Based Router and want to route the message to different endpoints. The JSON payload of the message can be in different forms, meaning that the JSonPath expressions in some cases would fail with an exception, and other times not. In this situation you must set suppress-exception to true, as shown below:

- from:
    uri: "direct:start"
    steps:
      - choice:
          when:
          - jsonpath:
              expression: "person.middlename"
              suppress-exceptions: true
            steps:
            - to: "mock:middle"
          - jsonpath:
              expression: "person.lastname"
              suppress-exceptions: true
            steps:
            - to: "mock:last"
          otherwise:
            steps:
              - to: "mock:other"
Copy to Clipboard

In the route above, the following message would have failed the JSonPath expression person.middlename because the JSON payload does not have a middlename field. To remedy this, we have suppressed the exception.

{
  "person": {
    "firstname": "John",
    "lastname": "Doe"
  }
}
Copy to Clipboard

158.6. External examples

You can find a set of examples using main-yaml in Camel examples that demonstrate how to create the Camel Routes with YAML. You can also refer to Camel Kamelets where each Kamelet is defined using YAML.

Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat