Thrift overview and installation

Thrift is an extensible cross-language remote service invocation framework.

 

Thrift uses the interface description language to define the interface and data type of RPC, and then generates codes in different languages ​​(Java, C++, C#, PHP, etc.) through a compiler, and the generated code is responsible for the RPC protocol layer (Protocol) and the transport layer (Transport) implementation. Among them, the protocol layer defines the data transmission format (such as binary, XML, JSON, etc.), and the transport layer defines the data transmission method (such as TCP/IP transmission, memory sharing, file sharing, etc.).

 

Thrift is a concrete implementation of IDL (Interface Definition Language) descriptive language.

 

In Thrift, calling a method that returns a null value directly throws a TApplicationException.

 

Thrift can generate the server-side code in Java language and the client-side code in C++ language from the interface definition file through the code generation tool, so as to realize cross-language support between the server and the client.

 

Download the installation package: http://thrift.apache.org/download

Development package download: http://repo1.maven.org/maven2/org/apache/thrift/libthrift/

 

Steps to install Thrift under Windows:

        Create a new folder named thrift under the D drive, copy the thrift-0.9.3.exe file to the folder, and rename it to thrift.exe

        Configure the Path environment variable and append at the end of the variable; D:\thrift 

        Execute thrift -version in the DOS window, if the version number of Thrift is output, the installation is successful

 

Generate target language code:

        Write Hello.thrift interface description file

        Copy the Hello.thrift file to the D:\thrift directory

        Execute the command thrift --gen java Hello.thrift, the Hello.java file will be generated

 

Thrift communication protocol:

        TBinaryProtocol: binary format

        TCompactProtocol: Compression format

        TJSONProtocol: JSON protocol

        TSimpleJSONProtocol: Provides a JSON write-only protocol, suitable for parsing through scripting languages

 

Thrift transfer method

        TSocket: uses blocking I/O for transmission, the most common mode

        TNonblockingTransport: Use a non-blocking method for building asynchronous clients

        TFramedTransport: transmits in frame units and is used in non-blocking services. Similar to TBufferedTransport, it also buffers related data. At the same time, it supports fixed-length data transmission and reception.

 

        TFileTransport: file (log) transmission class, allowing the client to pass the file to the server, allowing the server to write the received data to the file

        THttpTransport: use Http transport protocol for data transmission

        TZlibTransport: use zlib for compression, used in conjunction with other transports

        TBufferedTransport: Buffer the data operated by a Transport object, that is, read data from the buffer for transmission, or write the data directly to the buffer

        TMemoryTransport: uses memory for I/O. The java implementation actually uses a simple ByteArrayOutputStream internally

 

 Thrift server type

        TSimpleServer: A blocking single-threaded service model, often used for testing

        TThreadedServer: A blocking multi-threaded service model, creating a thread for each request

        TNonblockingServer: non-blocking multi-threaded service model (requires TFramedTransport data transmission method)

        TThreadPoolServer: A blocking thread pool service model that pre-creates a set of threads to process requests

        THsHaServer: Semi-synchronous and semi-asynchronous service model (requires TFramedTransport data transmission method)

        TThreadedSelectorServer:

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326895254&siteId=291194637