Английская Википедия:Apache Thrift
Шаблон:Short description Шаблон:Multiple issues Шаблон:Infobox software Thrift is an interface definition language and binary communication protocol[1] used for defining and creating services for programming languages.[2] It was developed at Facebook. As of 2020, it is an open source project in the Apache Software Foundation.
It uses a remote procedure call (RPC) framework and combines a software stack with a code generation engine to build cross-platform services. Ultimately, Thrift can connect applications written in a variety of languages and frameworks, including ActionScript, C, C++,[3] C#,[4] Cocoa, Delphi, Erlang, Go, Haskell, Java, JavaScript, Objective-C, OCaml, Perl, PHP, Python, Ruby, Elixir,[5] Rust, Scala, Smalltalk, and Swift.[6] The implementation was described in an April 2007 technical paper released by Facebook, now hosted on Apache.[7][8]
Architecture
Thrift includes a complete stack for creating clients and servers.[9] The top part is generated code from the Thrift definition. From this file, the services generate client and processor codes. In contrast to built-in types, created data structures are sent as a result of generated code. The protocol and transport layer are part of the runtime library. With Thrift, it is possible to define a service and change the protocol and transport without recompiling the code. Besides the client part, Thrift includes server infrastructure to tie protocols and transports together, like blocking, non-blocking, and multi-threaded servers. The underlying I/O part of the stack is implemented differently for different languages.
Thrift supports a number of protocols:[9]
- TBinaryProtocol – A straightforward binary format, simple, but not optimized for space efficiency. Faster to process than the text protocol but more challenging to debug.
- TCompactProtocol – More compact binary format; typically more efficient to process as well
- TJSONProtocol – Uses JSON for encoding of data.
- TSimpleJSONProtocol – A write-only protocol that cannot be parsed by Thrift because it drops metadata using JSON. Suitable for parsing by scripting languages.[10]
The supported transports are:
- TSimpleFileTransport – This transport writes to a file.
- TFramedTransport – This transport is required when using a non-blocking server. It sends data in frames, each preceded by length information.
- TMemoryTransport – Uses memory for I/O. The Java implementation uses a simple Шаблон:Javadoc:SE internally.
- TSocket – Uses blocking socket I/O for transport.
- TZlibTransport – Performs compression using zlib. Used in conjunction with another transport.
Thrift also provides a number of servers, which are
- TNonblockingServer – A multi-threaded server using non-blocking I/O (Java implementation uses NIO channels). TFramedTransport must be used with this server.
- TSimpleServer – A single-threaded server using standard blocking I/O. Useful for testing.
- TThreadedServer – A multi-threaded server using a thread per connection model and standard blocking I/O.
- TThreadPoolServer – A multi-threaded server using a thread pool and standard blocking I/O.
Benefits
Some stated benefits of Thrift include:[11]
- Cross-language serialization with lower overhead than alternatives such as SOAP due to use of binary format.
- No XML configuration files.
- The language bindings feel natural. For example, Java uses Шаблон:Javadoc:SE. C++ uses
std::vector<std::string>. - The application-level wire format and the serialization-level wire format are cleanly separated. They can be modified independently.
- The predefined serialization styles include: binary, HTTP-friendly and compact binary.
- Doubles as cross-language file serialization.
- Шаблон:Clarify span of the protocol. Thrift does not require a centralized and explicit mechanism like major-version/minor-version. Loosely coupled teams can freely evolve RPC calls.
- No build dependencies or non-standard software. No mix of incompatible software licenses.
Creating a Thrift service
Thrift is written in C++, but can create code for a number of languages. To create a Thrift service, one has to write Thrift files that describe it, generate the code in the destination language, write some code to start the server, and call it from the client. Here is a code example of such a description file:
enum PhoneType {
HOME,
WORK,
MOBILE,
OTHER
}
struct Phone {
1: i32 id,
2: string number,
3: PhoneType type
}
service PhoneService {
Phone findById(1: i32 id),
list<Phone> findAll()
}
Thrift will generate the code out of this descriptive information. For instance, in Java, the PhoneType will be a simple enum inside the Phone class.
See also
- Comparison of data serialization formats
- Apache Avro
- Abstract Syntax Notation One (ASN.1)
- Hessian
- Protocol Buffers
- External Data Representation (XDR)
- Internet Communications Engine (Ice)
- gRPC
- SDXF
References
External links
Шаблон:Apache Software Foundation Шаблон:Data Exchange Шаблон:Facebook navbox
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Thrift Requirements, see this issue for Windows support
- ↑ Fred Potter, Using Thrift with Cappuccino Шаблон:Webarchive, parallel48's posterously luscious blog, 10 June 2010.
- ↑ Шаблон:Citation
- ↑ Шаблон:Cite web
- ↑ Mark Slee, Aditya Agarwal, Marc Kwiatkowski, Thrift: Scalable Cross-Language Services Implementation
- ↑ Шаблон:Cite web
- ↑ 9,0 9,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Programmer's Guide to Apache Thrift, Randy Abernathy, Manning Publications, 2019, Шаблон:ISBN
- Английская Википедия
- Страницы с неработающими файловыми ссылками
- Apache Software Foundation projects
- Application layer protocols
- Data serialization formats
- Inter-process communication
- Remote procedure call
- Facebook software
- Страницы, где используется шаблон "Навигационная таблица/Телепорт"
- Страницы с телепортом
- Википедия
- Статья из Википедии
- Статья из Английской Википедии