Questo contenuto non è disponibile nella lingua selezionata.
Chapter 94. YAML DSL
Since Camel 3.9
The YAML DSL provides the capability to define your Camel routes, route templates & REST DSL configuration in YAML.
94.1. Defining a route Copia collegamentoCollegamento copiato negli appunti!
A route is a collection of elements defined as follows:
Where,
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:
- 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"
filter:
expression:
simple: "${in.header.continue} == true"
To make the DSL less verbose, you can omit the expression
field.
Implicit Expression field
filter: simple: "${in.header.continue} == true"
filter:
simple: "${in.header.continue} == true"
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: ">"
filter:
tokenize:
token: "<"
end-token: ">"
- Data Format Aware Steps
The EIP marshal
and unmarshal
supports the definition of data formats:
marshal: json: library: Gson
marshal:
json:
library: Gson
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: {}
94.2. Defining endpoints Copia collegamentoCollegamento copiato negli appunti!
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"
- from:
uri: "timer:tick?period=1s"
steps:
- to:
uri: "telegram:bots?authorizationToken=XXX"
- Using URI and parameters:
94.3. Defining beans Copia collegamentoCollegamento copiato negli appunti!
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 type: com.acme.MyBean properties: foo: bar
- beans:
- name: beanFromMap
type: com.acme.MyBean
properties:
foo: bar
Where,
The properties of the bean can be defined using either a map or properties style, as shown in the example below:
The beans
elements is only used as root element.
94.4. Configuring options on languages Copia collegamentoCollegamento copiato negli appunti!
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:
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.
94.5. External examples Copia collegamentoCollegamento copiato negli appunti!
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.