Yaml Dsl
Since Camel 3.9
Defining a route
A route is collection of elements defined as follows:
- from: (1)
uri: "direct:start"
steps: (2)
- filter:
expression:
simple: "${in.header.continue} == true"
steps: (2)
- to:
uri: "log:filtered"
- to:
uri: "log:original"
| 1 | route entry point, by default from and rest are supported |
| 2 | processing steps |
|
Each step is represented by a YAML map that has a single entry where the field name is the EIP name |
As general rule each step provide all the parameters the related definition declares but there are some minor differences/enhancements:
-
Output Aware Steps
Some steps such as
filterandsplithave their own pipeline when an exchange matches the filter expression or for the items generated by the split expression, such pipeline can be defined by thestepsfield:filter: expression: simple: "${in.header.continue} == true" steps: - to: uri: "log:filtered" -
Expression Aware Steps
Some EIP such as
filterandsplitsupports the definition of an expression through theexpressionfield:Explicit Expression fieldfilter: expression: simple: "${in.header.continue} == true"To make the DSL less verbose, the
expressionfield can be omitted:Implicit Expression fieldfilter: simple: "${in.header.continue} == true"In general expression can be defined inline like in the examples above but in case you need provide more information, you can 'unroll' the expression definition and configure any single parameter the expression defines.
Full Expression definitionfilter: tokenize: token: "<" end-token: ">" -
Data Format Aware Steps
Some EIP such as
set-bodyandmarshalsupports the definition of data formats through thedata-formatfield:Explicit Data Format fieldset-body: data-format: json: library: GsonTo make the DSL less verbose, the
data-formatfield can be omitted:Implicit Data Format fieldset-body: json: library: GsonIn case you want to use the data-format’s default settings, you need to place an empty block as data format parameters, like
json: {}
Defining endpoints
To define an endpoint with the YAML dsl you have three options:
-
Using a classic Camel URI:
- from: uri: "timer:tick?period=1s" steps: - to: uri: "telegram:bots?authorizationToken=XXX" -
Using URI and parameters:
- from: uri: "timer://tick" parameters: period: "1s" steps: - to: uri: "telegram:bots" parameters: authorizationToken: "XXX" -
Using the YAML implementation of the Endpoint DSL:
- from: timer: name: "tick" period: "1s" steps: - telegram: type: "bots" authorizationToken: "XXX"
|
Support for the Endpoint DSL with YAML is experimental and subject to changes. |
|
Support for Endpoint DSL auto completion is not yet available. |
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
| 1 | the name of the bean which will be used to 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'
|
The |
Examples
You can find a set of examples using camel-yaml-dsl in Camel Examples
which demonstrate creating Camel Routes with YAML.