Camel XML 路由:我可以给 <from> 元素中的 "uri" 属性一个 Java 常量的值吗?
Camel XML routes: can I give a "uri" attribute in a <from> element the value of a Java constant?
如果我有一个字符串 Java 常量 com.example.Constants.MY_URI
,我可以用它来为 Camel XML 文件中的 uri
属性赋值吗?
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="aaa" /> <-- how to use MY_URI here?
<to uri="bbb"/>
</route>
</camelContext>
特别是,有没有办法为此使用 Camel languages 之一?
非常感谢!
编辑
在与骆驼进行更多合作之后,我们会更好地了解它。可以使用一种骆驼语言来定义消息应该去哪里,使用 recipient-list。但是你不能用它来代替 from
- 它必须是硬编码的或从属性文件中获取,如下所述。
结束编辑
我不知道这是否可行,但还有另一种选择:
你可以使用 propertyPlaceholder:
<camelContext ...>
<propertyPlaceholder id="properties" location="com/mycompany/myprop.properties"/>
</camelContext>
并且您需要将常量放入 myprop.properties 文件中:
example.from.property.name=direct:start
然后你可以在里面使用那个 属性 from:
<from uri="{{example.from.property.name}}" />
如果我有一个字符串 Java 常量 com.example.Constants.MY_URI
,我可以用它来为 Camel XML 文件中的 uri
属性赋值吗?
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="aaa" /> <-- how to use MY_URI here?
<to uri="bbb"/>
</route>
</camelContext>
特别是,有没有办法为此使用 Camel languages 之一?
非常感谢!
编辑
在与骆驼进行更多合作之后,我们会更好地了解它。可以使用一种骆驼语言来定义消息应该去哪里,使用 recipient-list。但是你不能用它来代替 from
- 它必须是硬编码的或从属性文件中获取,如下所述。
结束编辑
我不知道这是否可行,但还有另一种选择:
你可以使用 propertyPlaceholder:
<camelContext ...>
<propertyPlaceholder id="properties" location="com/mycompany/myprop.properties"/>
</camelContext>
并且您需要将常量放入 myprop.properties 文件中:
example.from.property.name=direct:start
然后你可以在里面使用那个 属性 from:
<from uri="{{example.from.property.name}}" />