【问题标题】:Use Properties File with Apache Camel在 Apache Camel 中使用属性文件
【发布时间】:2017-09-17 12:57:42
【问题描述】:

如何在 Apache Camel 中使用属性文件来引用可配置的属性。例如,如果有一个从文件夹中读取文件的路由,那么如何在属性文件中配置该文件夹的位置。我正在使用 Java DSL。

【问题讨论】:

    标签: apache-camel properties-file


    【解决方案1】:

    Camel 具有广泛的属性支持。

    在非常简单的情况下,您可以执行以下操作:

    PropertiesComponent pc = new PropertiesComponent();
    pc.setLocation("classpath:com/mycompany/myprop.properties");
    context.addComponent("properties", pc);
    

    myprop.properties:

    route.start=file:///tmp/myfile
    route.to=direct:whatever
    

    在您的路由中,您可以使用{{..}} 占位符语法来引用属性。

    from("{{route.start}}")
        .split()
        .process(whatever)
        .to("{{route.to}}")
    

    如果您使用的是 spring 并且您的属性文件已经加载,您可以跳过属性组件定义并直接引用属性。

    阅读documentation了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      相关资源
      最近更新 更多