이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 84. Kestrel


Kestrel Component

The Kestrel component allows messages to be sent to a Kestrel queue, or messages to be consumed from a Kestrel queue. This component uses the spymemcached client for memcached protocol communication with Kestrel servers.
Warning
The Kestrel project is inactive and this component is therefore deprecated.

URI format

kestrel://[addresslist/]queuename[?options]
Copy to Clipboard Toggle word wrap
Where queuename is the name of the queue on Kestrel. The addresslist part of the URI may include one or more host:port pairs. For example, to connect to the queue foo on kserver01:22133, use:
kestrel://kserver01:22133/foo
Copy to Clipboard Toggle word wrap
If the addresslist is omitted, localhost:22133 is assumed, i.e.:
kestrel://foo
Copy to Clipboard Toggle word wrap
Likewise, if a port is omitted from a host:port pair in addresslist, the default port 22133 is assumed, i.e.:
kestrel://kserver01/foo
Copy to Clipboard Toggle word wrap
Here is an example of a Kestrel endpoint URI used for producing to a clustered queue:
kestrel://kserver01:22133,kserver02:22133,kserver03:22133/massive
Copy to Clipboard Toggle word wrap
Here is an example of a Kestrel endpoint URI used for consuming concurrently from a queue:
kestrel://kserver03:22133/massive?concurrentConsumers=25&waitTimeMs=500
Copy to Clipboard Toggle word wrap

Options

You can configure properties on each Kestrel endpoint individually by specifying them in the ?parameters portion of the endpoint URI. Any ?parameters that are omitted will default to what is configured on the KestrelComponent's base KestrelConfiguration. The following properties may be set on KestrelConfiguration and/or each individual endpoint:
Expand
Option Default Value Description
concurrentConsumers 1 Specifies the number of concurrent consumer threads.
waitTimeMs 100 Specifies the /t=... wait time passed to Kestrel on GET requests.
NOTE: If waitTimeMs is set to zero (or negative), the /t=... specifier does not get passed to the server on GET requests. When a queue is empty, the GET call returns immediately with no value. In order to prevent "tight looping" in the polling phase, this component will do a Thread.sleep(100) whenever nothing is returned from the GET request (only when nothing is returned). You are highly encouraged to configure a positive non-zero value for waitTimeMs.

Configuring the Kestrel component using Spring XML

The simplest form of explicit configuration is as follows:
<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
That will enable the Kestrel component with all default settings, i.e. it will use localhost:22133, 100ms wait time, and a single non-concurrent consumer by default.
To use specific options in the base configuration (which supplies configuration to endpoints whose ?properties are not specified), you can set up a KestrelConfiguration POJO as follows:
<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

Usage Examples

Example 1: Consuming

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

Example 2: Producing

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

Example 3: Spring XML Configuration

  <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

The Kestrel component has the following dependencies:
  • spymemcached 2.5 (or greater)

spymemcached

You must have the spymemcached jar on your classpath. Here is a snippet you can use in your pom.xml:
<dependency>
  <groupId>spy</groupId>
  <artifactId>memcached</artifactId>
  <version>2.5</version>
</dependency>
Copy to Clipboard Toggle word wrap
Alternatively, you can download the jar directly.
Limitations
NOTE: The spymemcached client library does not work properly with kestrel when JVM assertions are enabled. There is a known issue with spymemcached when assertions are enabled and a requested key contains the /t=... extension (i.e. if you're using the waitTimeMs option on an endpoint URI, which is highly encouraged).
Fortunately, JVM assertions are disabled by default, unless you explicitly enable them, so this should not present a problem under normal circumstances.
Something to note is that Maven's Surefire test plugin enables assertions. If you're using this component in a Maven test environment, you may need to set enableAssertions to false. Please refer to the surefire:test reference for details.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat