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>

默认情况下,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>
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部