第133章 Ref
ref コンポーネント リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
ref: コンポーネントは、レジストリーにバインドされる既存のエンドポイントの検索に使用されます。
URI 形式 リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
ref:someName
someName はレジストリー内のエンドポイントの名前です(通常は、常に Spring レジストリーではありません)。Spring レジストリーを使用している場合、
someName は Spring レジストリー内のエンドポイントの Bean ID になります。
ランタイムルックアップ リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
このコンポーネントは、実行時に URI を計算できるレジストリーのエンドポイントの動的検出が必要な場合に使用できます。次に、以下のコードを使用してエンドポイントを検索できます。
// lookup the endpoint
String myEndpointRef = "bigspenderOrder";
Endpoint endpoint = context.getEndpoint("ref:" + myEndpointRef);
Producer producer = endpoint.createProducer();
Exchange exchange = producer.createExchange();
exchange.getIn().setBody(payloadToSend);
// send the exchange
producer.process(exchange);
...
また、以下のようなレジストリーでエンドポイントの一覧を定義することも可能です。
<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
<endpoint id="normalOrder" uri="activemq:order.slow"/>
<endpoint id="bigspenderOrder" uri="activemq:order.high"/>
...
</camelContext>
例 リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
以下の例では、URI の
ref: を使用して、Spring ID endpoint2 でエンドポイントを参照します。
<bean id="mybean" class="org.apache.camel.spring.example.DummyBean">
<property name="endpoint" ref="endpoint1"/>
</bean>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<jmxAgent id="agent" disabled="true"/>
<endpoint id="endpoint1" uri="direct:start"/>
<endpoint id="endpoint2" uri="mock:end"/>
<route>
<from ref="endpoint1"/>
<to uri="ref:endpoint2"/>
</route>
</camelContext>
当然ながら、代わりに
ref 属性を使用できます。
<to ref="endpoint2"/>
これは、記述のより一般的な方法です。