【发布时间】:2019-12-20 23:48:24
【问题描述】:
我在 Karaf 中使用蓝图来引导 CamelContext 的启动,这反过来又配置了 Java DSL(Camel 版本 2.21.2)中定义的路由。在 blueprint.xml 中,我定义了一些默认属性占位符来利用配置管理 OSGi 服务:
<cm:property-placeholder persistent-id="foo.MyRoute">
<cm:default-properties>
<cm:property name="log.message" value="Hello world"/>
<cm:property name="response.code" value="200"/>
</cm:default-properties>
</cm:property-placeholder>
在 Java DSL 中,我可以使用 {{log.message}} 占位符,因为它是一个字符串:
from("timer:timer").log("{{log.message}}")
但是,我想弄清楚的是如何设置占位符的类型,以便在以下情况下使用它们:
.setHeader(Exchange.HTTP_RESPONSE_CODE).constant("{{response.code}}")
这是一个人为的例子,但我在这里尝试将标头设置为 int/Integer 类型。
占位符是否专门用于端点 URI 定义?或者我应该将解析的字符串转换为我需要的类型?我假设我在这里遗漏了一些东西,或者没有按预期使用占位符......
我已阅读 https://camel.apache.org/manual/latest/using-propertyplaceholder.html,尤其是后面的部分:在 XML DSL 中为任何类型的属性使用属性占位符,我看到支持自动类型转换,但它似乎只适用于 EIP 选项:
from("direct:start")
.multicast()
.placeholder("stopOnException", "stop")
.to("mock:a")
.throwException(new IllegalAccessException("Damn"))
.to("mock:b");
任何帮助都将不胜感激,因为我经常阅读文档,现在这些词已经不再有意义了!
【问题讨论】:
标签: apache-camel blueprint-osgi