Thrift 是Apache下的可擴展,跨語言軟件框架,能夠無縫鏈接C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml Delphi等其餘語言git
目前最新版本: 0.11.0 (released on 2017-DEC-07).github
Maven依賴:apache
<dependency> <groupId>org.apache.thrift</groupId> <artifactId>libthrift</artifactId> <version>0.11.0</version> </dependency>
官方網站: http://thrift.apache.org/服務器
git路徑: git clone https://github.com/apache/thrift.git
框架
安裝網站
1. 安裝Thrift
編碼
2. 安裝Thrift編譯器, 用於自動生成服務器端與客戶端的源碼code
3.編寫 接口定義 .thrift文件, 接口定義文件中包含 類型定義 和服務接口定義server
4. 生成server, client 的源碼 thrift --gen <language> <Thrift filename>
接口
Thrift Types
Thrifty type 基本使用各類語言的基礎抽象類型, Thrift IDL詳細介紹了各類語言的對應Thrift 類型
基礎類型
特殊類型
binary: 未編碼字節流
N.B.: string類型的特殊形式, 更適用於Java.
Services服務
service <name> {
<returntype> <name> (<arguments>) [throws (<exceptions>)]
............
}
關於thrift協議的瞭解,能夠參考 white paper: http://thrift.apache.org/static/files/thrift-20070401.pdf