Apache Thrift Explained
Apache Thrift |
Author: | Facebook, Inc. |
Developer: | Apache Software Foundation |
Latest Release Version: | 0.19.0 |
Latest Release Date: | [1] |
Programming Language: | ActionScript, C, C#, C++, D, Dart, Delphi, Erlang, Go, Haskell, Haxe, Java, JavaScript, Node.js, OCaml, Perl, PHP, Python, Rust, Scala, Smalltalk |
Genre: | Remote procedure call framework |
License: | Apache 2.0 |
Thrift is an IDL (Interface Definition Language) and binary communication protocol[2] used for defining and creating services for programming languages.[3] It was developed by Facebook. Since 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. Thrift can connect applications written in a variety of languages and frameworks, including ActionScript, C, C++,[4] C#,[5] Cocoa, Delphi, Erlang, Go, Haskell, Java, JavaScript, Objective-C, OCaml, Perl, PHP, Python, Ruby, Elixir, 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 such as blocking, non-blocking, and multi-threaded servers. The underlying I/O part of the stack is implemented differently for different programming languages.
Thrift supports a number of protocols:[9]
- TBinaryProtocol – A binary format not optimized for space efficiency. Faster to process than the text protocol.
- TCompactProtocol – More compact binary format.
- TJSONProtocol – Uses JSON for the 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 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.
- 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.
Thrift is written in C++, but can create code for some other programming 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. An example of such a description file:
enum PhoneType
struct Phone
service PhoneService
Thrift will generate the code out of this descriptive information. For instance, in Java, the PhoneType
will be enum
inside the Phone
class.
See also
Notes and References
- Web site: Apache Thrift - Downloads. 6 January 2024.
- Web site: Installing and using Apache Cassandra With Java Part 4 (Thrift Client) . live . https://web.archive.org/web/20220331115308/http://www.sodeso.nl/?p=251 . March 31, 2022 . 2011-03-30 . Sodeso – Software Development Solutions . Thrift is a separate Apache project which is a binary communication protocol.
- Web site: Prunicki . Andrew . Apache Thrift: Introduction . dead . https://web.archive.org/web/20110723051326/http://jnb.ociweb.com/jnb/jnbJun2009.html . 2011-07-23 . 2011-04-11 . Object Computing . Using code generation, Thrift creates a set of files which can then be used for creating clients and/or servers..
- Web site: ThriftRequirements . unfit . https://web.archive.org/web/20240226144131/https://cwiki.apache.org/confluence/display/THRIFT/ThriftRequirements . February 26, 2024 . 2024-06-22 . Apache Software Foundation.
- Fred Potter, Using Thrift with Cappuccino, parallel48's posterously luscious blog, 10 June 2010.
- Web site: Andrew Prunicki . Apache Thrift: Code Generation . dead . https://web.archive.org/web/20110723051326/http://jnb.ociweb.com/jnb/jnbJun2009.html . 2011-07-23 . 2011-04-12 . Object Computing.
- Mark Slee, Aditya Agarwal, Marc Kwiatkowski, Thrift: Scalable Cross-Language Services Implementation
- Web site: July 11, 2019 . LibraryFeatures . live . https://wayback-api.archive.org/web/20230503083525/https://cwiki.apache.org/confluence/display/thrift/LibraryFeatures?action=show&redirect=LanguageSupport . May 3, 2024 . 2016-04-21 . Apache Software Foundation.
- Web site: Andrew Prunicki . Apache Thrift: Introduction . dead . https://web.archive.org/web/20110723051326/http://jnb.ociweb.com/jnb/jnbJun2009.html . 2011-07-23 . 2011-04-11 . Object Computing.
- Web site: Skelton . Steven . 3 August 2013 . Developer Friendly Thrift Request Logging . live . https://wayback-api.archive.org/web/20240124062123/https://www.stevenskelton.ca/developer-friendly-thrift-request-logging/ . January 24, 2024 . 3 July 2014 . stevenskelton.ca.