架构

RouteBuilder

师成师成· 更新于 2026-09-28· 阅读 3 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

RouteBuilder

RouteBuilder 是一个基类,通过继承它来使用 Java DSL 创建路由规则。创建出的 RouteBuilder 实例随后会被添加到 CamelContext 中。

RouteBuilder 示例

以下展示了 Java DSL 中 RouteBuilder 的一个示例:

import org.apache.camel.builder.RouteBuilder;

/**
 * A Camel Java DSL Router
 */
public class MyRouteBuilder extends RouteBuilder {

    /**
     * Let's configure the Camel routing rules using Java code...
     */
    public void configure() {

        // here is a sample which processes the input files
        // (leaving them in place - see the 'noop' flag)
        // then performs content based routing on the message using XPath
        from("file:src/data?noop=true")
            .choice()
                .when(xpath("/person/city = 'London'"))
                    .to("file:target/messages/uk")
                .otherwise()
                    .to("file:target/messages/others");
    }

}

在 configure 方法中,我们可以定义 Camel 路由(Routes)。

更多信息

更多信息请参阅 DSL、Java DSL 和 路由(Routes)。

评论

登录后参与评论

正在加载评论…