Chapter 83. YAML DSL


A YAML stack for parsing YAML route definitions

83.1. What’s inside

Please refer to the above link for usage and configuration details.

83.2. Maven coordinates

Create a new project with this extension on code.quarkus.redhat.com

Or add the coordinates to your existing project:

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-yaml-dsl</artifactId>
</dependency>
Copy to Clipboard Toggle word wrap

83.3. Usage

83.3.1. Native mode

The following constructs when defined within Camel YAML DSL markup, require you to register classes for reflection. Refer to the Native mode guide for details.

83.3.1.1. Bean definitions

The YAML DSL provides the capability to define beans as follows.

- beans:
    - name: "greetingBean"
      type: "org.acme.GreetingBean"
      properties:
        greeting: "Hello World!"
- route:
    id: "my-yaml-route"
    from:
      uri: "timer:from-yaml?period=1000"
      steps:
        - to: "bean:greetingBean"
Copy to Clipboard Toggle word wrap

In this example, the GreetingBean class needs to be registered for reflection. This applies to any types that you refer to under the beans key in your YAML routes.

@RegisterForReflection
public class GreetingBean {
}
Copy to Clipboard Toggle word wrap

83.3.1.2. Exception handling

Camel provides various methods of handling exceptions. Some of these require that any exception classes referenced in their DSL definitions are registered for reflection.

on-exception

- on-exception:
    handled:
      constant: "true"
    exception:
      - "org.acme.MyHandledException"
    steps:
      - transform:
          constant: "Sorry something went wrong"
Copy to Clipboard Toggle word wrap
@RegisterForReflection
public class MyHandledException {
}
Copy to Clipboard Toggle word wrap

throw-exception

- route:
    id: "my-yaml-route"
    from:
      uri: "direct:start"
      steps:
        - choice:
            when:
              - simple: "${body} == 'bad value'"
                steps:
                  - throw-exception:
                      exception-type: "org.acme.ForcedException"
                      message: "Forced exception"
            otherwise:
              steps:
                - to: "log:end"
Copy to Clipboard Toggle word wrap
@RegisterForReflection
public class ForcedException {
}
Copy to Clipboard Toggle word wrap

do-catch

- route:
    id: "my-yaml-route2"
    from:
      uri: "direct:tryCatch"
      steps:
        - do-try:
            steps:
              - to: "direct:readFile"
            do-catch:
              - exception:
                  - "java.io.FileNotFoundException"
                steps:
                  - transform:
                      constant: "do-catch caught an exception"
Copy to Clipboard Toggle word wrap
@RegisterForReflection(targets = FileNotFoundException.class)
public class MyClass {
}
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat