目录
1 IDL
Thrift 采用IDL(Interface Definition Language)来定义通用的服务接口,然后通过Thrift提供的编译器,可以将服务接口编译成不同语言编写的代码,通过这个方式来实现跨语言的功能。
-
基本字段类型如下(括号内对应的是 Java 类型):
-
bool (boolean)
-
byte (byte)
-
i16 (short)
-
i32 (int)
-
i64 (long)
-
double (double)
-
string (String)
-
binary (byte)
注:thrift不支持无符号整型。
-
-
容器类型
-
list (List)
-
set (Set)
-
map (Map)
-
结构体 struct,等同于 Java 中的类
struct Student { 1: i32 age, 2: string name }
-
服务 service
//“Twitter”与“{”之间需要有空格!!! service Twitter { // 参数列表和异常列表定义方式与结构体中域定义方式一致. void ping(), bool postTweet(1:Tweet tweet); // ”oneway”标识符表示client发出请求后不必等待回复(非阻塞)直接进行下面的操作, // ”oneway”方法的返回值必须是void oneway void zip() void test() throws (1:GenericException genericException);//声明抛出自定义异常 }
注意,函数中参数列表的定义方式与struct完全一样。Service支持继承,一个service可使用extends关键字继承另一个service
-
其他