Red Hat Training

A Red Hat training course is available for Red Hat Fuse

250.17. Camel ルートで Blueprint プロパティープレースホルダーを使用する

Camel 2.7 以降で利用可能

Camel は、プロパティープレースホルダーサービスも提供する Blueprint をサポートしています。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>

250.17.1. Camel ルートでの OSGi Blueprint プロパティープレースホルダーの使用

デフォルトでは、Camel は OSGi Blueprint プロパティープレースホルダーサービスを検出して使用します。<camelContext> 定義で属性 useBlueprintPropertyResolver を false に設定することで、これを無効にすることができます。

250.17.2. プレースホルダー構文について

Camel ルートのプレースホルダー {{ および }} に Camel 構文を使用する方法に注目してください。これは、OSGi ブループリントから値を検索します。

プレースホルダーの blueprint 構文は ${ } です。<camelContext> の外では、${ } 構文を使用する必要があります。<camelContext> の内部では、{{ および }} 構文を使用する必要があります。

OSGi blueprint を使用すると構文を設定できるため、必要に応じて実際にそれらを調整できます。

特定の OSGi blueprint プロパティープレースホルダーをその ID で明示的に参照することもできます。そのためには、次の例に示すように、Camel の <propertyPlaceholder> を使用する必要があります。

<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>