264.17. 在 Camel 路由中使用 Blueprint 属性占位符
从 Camel 2.7 开始提供
Camel 支持蓝图,其也提供属性占位符服务。Camel 支持对配置的惯例,因此您必须做的是在 XML 文件中定义 OSGi Blueprint 属性占位符,如下所示:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<!-- OSGI blueprint property placeholder -->
<cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint">
<!-- list some properties as needed -->
<cm:default-properties>
<cm:property name="result" value="mock:result"/>
</cm:default-properties>
</cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- in the route we can use {{ }} placeholders which will lookup in blueprint
as Camel will auto detect the OSGi blueprint property placeholder and use it -->
<route>
<from uri="direct:start"/>
<to uri="mock:foo"/>
<to uri="{{result}}"/>
</route>
</camelContext>
</blueprint>
264.17.1. 在 Camel 路由中使用 OSGi 蓝图属性占位符 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
默认情况下,Camel 会检测并使用 OSGi 蓝图属性占位符服务。您可以通过在 < camelContext > 定义中将属性 useBlueprintPropertyResolver 设置为 false 来禁用。
264.17.2. 关于占位符语法 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
请注意,我们如何将 Camel 语法用于 Camel 路由中的占位符 {{ 和 }},这将从 OSGi 蓝图中查找值。
占位符的蓝图语法为 ${ }。因此,在 & lt;camelContext& gt; 之外,必须使用 ${ } 语法。如 < camelContext> 中一样,您必须使用 { { 和 }} 语法。
OSGi 蓝图允许您配置语法,因此,如果需要,您可以实际对齐它们。
您还可以明确引用其 id 的特定 OSGi 蓝图属性占位符。为此,您需要使用 Camel 的 < propertyPlaceholder& gt;,如下例所示:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<!-- OSGI blueprint property placeholder -->
<cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint">
<!-- list some properties as needed -->
<cm:default-properties>
<cm:property name="prefix.result" value="mock:result"/>
</cm:default-properties>
</cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- using Camel properties component and refer to the blueprint property placeholder by its id -->
<propertyPlaceholder id="properties" location="blueprint:myblueprint.placeholder"
prefixToken="[[" suffixToken="]]"
propertyPrefix="prefix."/>
<!-- in the route we can use {{ }} placeholders which will lookup in blueprint -->
<route>
<from uri="direct:start"/>
<to uri="mock:foo"/>
<to uri="[[result]]"/>
</route>
</camelContext>
</blueprint>