第133章 Ref


ref コンポーネント

ref: コンポーネントは、レジストリーにバインドされる既存のエンドポイントの検索に使用されます。

URI 形式

ref:someName
Copy to Clipboard Toggle word wrap
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);
   ...
Copy to Clipboard Toggle word wrap
また、以下のようなレジストリーでエンドポイントの一覧を定義することも可能です。
  <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>
Copy to Clipboard Toggle word wrap

以下の例では、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>
Copy to Clipboard Toggle word wrap
当然ながら、代わりに ref 属性を使用できます。
      <to ref="endpoint2"/>
Copy to Clipboard Toggle word wrap
これは、記述のより一般的な方法です。
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat