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

Chapter 333. Thrift Component


Available as of Camel version 2.20

The Thrift component allows you to call or expose Remote Procedure Call (RPC) services using Apache Thrift binary communication protocol and serialization mechanism.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-thrift</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

333.1. URI format

thrift://service[?options]

333.2. Endpoint Options

The Thrift component supports 2 options which are listed below.

NameDescriptionDefaultType

useGlobalSslContext Parameters (security)

Determine if the thrift component is using global SSL context parameters

false

boolean

resolveProperty Placeholders (advanced)

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.

true

boolean

The Thrift endpoint is configured using URI syntax:

thrift:host:port/service

with the following path and query parameters:

333.2.1. Path Parameters (3 parameters):

NameDescriptionDefaultType

host

The Thrift server host name. This is localhost or 0.0.0.0 (if not defined) when being a consumer or remote server host name when using producer.

 

String

port

Required The Thrift server port

 

int

service

Required Fully qualified service name from the thrift descriptor file (package dot service definition name)

 

String

333.2.2. Query Parameters (12 parameters):

NameDescriptionDefaultType

compressionType (common)

Protocol compression mechanism type

NONE

ThriftCompressionType

exchangeProtocol (common)

Exchange protocol serialization type

BINARY

ThriftExchangeProtocol

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

clientTimeout (consumer)

Client timeout for consumers

 

int

maxPoolSize (consumer)

The Thrift server consumer max thread pool size

10

int

poolSize (consumer)

The Thrift server consumer initial thread pool size

1

int

exceptionHandler (consumer)

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer)

Sets the exchange pattern when the consumer creates an exchange.

 

ExchangePattern

method (producer)

The Thrift invoked method name

 

String

synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

false

boolean

negotiationType (security)

Security negotiation type

PLAINTEXT

ThriftNegotiationType

sslParameters (security)

Configuration parameters for SSL/TLS security negotiation

 

SSLContextParameters

333.3. Thrift method parameters mapping

Parameters in the called procedure must be passed as a list of objects inside the message body. The primitives are converted from the objects on the fly. In order to correctly find the corresponding method, all types must be transmitted regardless of the values. Please see an exmaple below, how to pass different parameters to the method with the Camel body

List requestBody = new ArrayList();

requestBody.add((boolean)true);
requestBody.add((byte)THRIFT_TEST_NUM1);
requestBody.add((short)THRIFT_TEST_NUM1);
requestBody.add((int)THRIFT_TEST_NUM1);
requestBody.add((long)THRIFT_TEST_NUM1);
requestBody.add((double)THRIFT_TEST_NUM1);
requestBody.add("empty"); // String parameter
requestBody.add(ByteBuffer.allocate(10)); // binary parameter
requestBody.add(new Work(THRIFT_TEST_NUM1, THRIFT_TEST_NUM2, Operation.MULTIPLY)); // Struct parameter
requestBody.add(new ArrayList<Integer>()); // list paramater
requestBody.add(new HashSet<String>()); // set parameter
requestBody.add(new HashMap<String, Long>()); // map parameter

Object responseBody = template.requestBody("direct:thrift-alltypes", requestBody);

Incoming parameters in the service consumer will also be passed to the message body as a list of objects.

333.4. Thrift consumer headers (will be installed after the consumer invocation)

Header nameDescriptionPossible values

CamelThriftMethodName

Method name handled by the consumer service

 

333.5. Examples

Below is a simple synchronous method invoke with host and port parameters

from("direct:thrift-calculate")
.to("thrift://localhost:1101/org.apache.camel.component.thrift.generated.Calculator?method=calculate&synchronous=true");

Below is a simple synchronous method invoke for the XML DSL configuration

<route>
    <from uri="direct:thrift-add" />
    <to uri="thrift://localhost:1101/org.apache.camel.component.thrift.generated.Calculator?method=add&synchronous=true"/>
</route>

Thrift service consumer with asynchronous communication

from("thrift://localhost:1101/org.apache.camel.component.thrift.generated.Calculator")
.to("direct:thrift-service");

It’s possible to automate Java code generation for .thrift files using thrift-maven-plugin, but before start the thrift compiler binary distribution for your operating system must be present on the running host.

333.6. For more information, see these resources

Thrift project GitHubhttps://thrift.apache.org/tutorial/java [Apache Thrift Java tutorial]

333.7. See Also

  • Getting Started
  • Configuring Camel
  • Component
  • Endpoint
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

© 2024 Red Hat, Inc.