第91章 Kestrel


Kestrel コンポーネント

Kestrel コンポーネントを使用すると、Kestrel キューへメッセージを送信したり、Kestrel キューからメッセージを消費したりできます。このコンポーネントは、Kestrel サーバーとの memcached プロトコル通信に spymemcached クライアントを使用します。
警告
そのため、Kestrel プロジェクトは非アクティブであるため、このコンポーネントは が 非推奨になりました

URI 形式

kestrel://[addresslist/]queuename[?options]
Copy to Clipboard Toggle word wrap
queuename は Kestrel 上のキューの名前です。URI の addresslist 部分には、1 つ以上の host:port ペアが含まれる場合があります。たとえば、kserver01:22133 のキュー foo に接続するには、以下を使用します。
kestrel://kserver01:22133/foo
Copy to Clipboard Toggle word wrap
addresslist を省略すると、localhost:22133 が想定されます。つまり、以下のようになります。
kestrel://foo
Copy to Clipboard Toggle word wrap
同様に、addresslist の host:port ペアからポートを省略すると、デフォルトのポート 22133 が想定されます。以下に例を示します。
kestrel://kserver01/foo
Copy to Clipboard Toggle word wrap
以下は、クラスター化されたキューの生成に使用される Kestrel エンドポイント URI の例です。
kestrel://kserver01:22133,kserver02:22133,kserver03:22133/massive
Copy to Clipboard Toggle word wrap
以下は、キューから同時に消費するために使用される Kestrel エンドポイント URI の例です。
kestrel://kserver03:22133/massive?concurrentConsumers=25&waitTimeMs=500
Copy to Clipboard Toggle word wrap

オプション

各 Kestrel エンドポイントでプロパティーを個別に設定するには、エンドポイント URI の ?parameters の部分でプロパティーを指定します。省略された ?parameters はデフォルトで KestrelComponent のベース KestrelelConfiguration で設定される内容に設定されます。以下のプロパティーは KestrelConfiguration や各エンドポイントに設定できます。
Expand
オプション デフォルト値 説明
concurrentConsumers 1 同時コンシューマースレッドの数を指定します。
waitTimeMs 100 /t=... を指定します。GET リクエストで Kestrel に渡される待機時間を指定します。
注記: waitTimeMs がゼロ(または負の値)に設定されている場合、/t=... 指定子は GET 要求時にサーバーに渡され ません。キューが空の場合、GET 呼び出しは値なしで即座に返します。ポーリングフェーズで "tight looping" が発生しないように、このコンポーネントは、GET リクエストから何も返されない場合は常に Thread.sleep (100 )を実行します(何も返されない場合のみ)。waitTimeMs に 正の値以外の値を設定することを強く推奨 します。

Spring XML を使用した Kestrel コンポーネントの設定

明示的な設定の最も単純な形式は次のとおりです。
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <bean id="kestrel" class="org.apache.camel.component.kestrel.KestrelComponent"/>

  <camelContext xmlns="http://camel.apache.org/schema/spring">
  </camelContext>

</beans>
Copy to Clipboard Toggle word wrap
これにより、すべてのデフォルト設定で Kestrel コンポーネントが有効になります。つまり、デフォルトで localhost:22133、100ms の待機時間、および同時でないコンシューマー 1 つを使用します。
ベース設定で特定のオプション( ?properties が指定されていないエンドポイントに設定を提供する)を使用するには、以下のように KestrelConfiguration POJO を設定します。
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <bean id="kestrelConfiguration" class="org.apache.camel.component.kestrel.KestrelConfiguration">
    <property name="addresses" value="kestrel01:22133"/>
    <property name="waitTimeMs" value="100"/>
    <property name="concurrentConsumers" value="1"/>
  </bean>

  <bean id="kestrel" class="org.apache.camel.component.kestrel.KestrelComponent">
    <property name="configuration" ref="kestrelConfiguration"/>
  </bean>

  <camelContext xmlns="http://camel.apache.org/schema/spring">
  </camelContext>

</beans>
Copy to Clipboard Toggle word wrap

使用例

例 1: 消費

from("kestrel://kserver02:22133/massive?concurrentConsumers=10&waitTimeMs=500")
  .bean("myConsumer", "onMessage");
Copy to Clipboard Toggle word wrap
public class MyConsumer {
    public void onMessage(String message) {
        ...
    }
}
Copy to Clipboard Toggle word wrap

例 2: 生成

public class MyProducer {
    @EndpointInject(uri = "kestrel://kserver01:22133,kserver02:22133/myqueue")
    ProducerTemplate producerTemplate;

    public void produceSomething() {
        producerTemplate.sendBody("Hello, world.");
    }
}
Copy to Clipboard Toggle word wrap

例 3: Spring XML 設定

  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="kestrel://ks01:22133/sequential?concurrentConsumers=1&waitTimeMs=500"/>
      <bean ref="myBean" method="onMessage"/>
    </route>
    <route>
      <from uri="direct:start"/>
      <to uri="kestrel://ks02:22133/stuff"/>
    </route>
  </camelContext>
Copy to Clipboard Toggle word wrap
public class MyBean {
    public void onMessage(String message) {
        ...
    }
}
Copy to Clipboard Toggle word wrap

Dependencies

Kestrel コンポーネントには、以下の依存関係があります。
  • Spymemcached 2.5 (以上)

spymemcached

クラスパスに spymemcached jar が 必要 です。以下は、pom.xml で使用できるスニペットです。
<dependency>
  <groupId>spy</groupId>
  <artifactId>memcached</artifactId>
  <version>2.5</version>
</dependency>
Copy to Clipboard Toggle word wrap
または、jar を直接ダウンロード できます。
制限事項
注記: JVM アサーションが有効になっていると、spymemcached クライアントライブラリーが kestrel で適切に動作し ません。アサーションが有効で、要求されたキーに /t=... エクステンションが含まれる場合に spymemcached には既知の問題があります(例:エンドポイント URI で waitTimeMs オプションを使用している場合は、強く推奨されます)。
ただし、JVM アサーションを 明示的に有効にしない限り、JVM アサーションは デフォルトで無効 なっているため、通常の状況では問題は発生しません。
注意すべき点は、Maven の Surefire テストプラグインがアサーションを 有効 にすることです。Maven テスト環境でこのコンポーネントを使用している場合は、enableAssertionsfalse に設定する必要がある場合があります。詳細は、surefire:test を参照 してください。
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

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

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

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

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

会社概要

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

Theme

© 2025 Red Hat