5. Thrift
● 最全面的 RPC 系统,但不支持本地串行化
● 采用层次结构,支持多种 Protocol , Transport
以及多种 server 架构
● Client 端只支持同步模式
● 需要通过 IDL 来定义 RPC 服务,然后自动生成
调用层代码
●
跨语言调用
● 每种语言都在 IDL 编译器中有自己的代码生成逻辑
● 需要为每种语言实现 Protocol, Transport 和 Server
6. Thrift Types
● Base types: bool, byte, i16, i32, i64, double,
string
● Struct
● Containers: List, Map, Set
● Exceptions
● Services: A set of function declarations
● Struct 的域和函数的每个参数都关联一个 id
7. Thrift 调用层
● Client 端
● 对每个 Service X , IDL 编译器生成一个对应的
XClient 类, RPC 函数作为该类的成员函数
● 用户代码直接调用 XClient 中的成员函数
● 调用层将参数列表封装在一个 Struct 中发送
● Server 端
● 对每个 Service X , IDL 编译器生成一个对应的 XIf
接口类, RPC 函数作为成员函数
●
服务器端的用户代码实现这个接口
10. Thrift 兼容性
●
服务器端的用户代码可以忽略不能识别的域或者
参数
● Thrift 为每个域和函数参数提供了 isset 函数
● 4 种情况
● Added field, old client, new server
● Removed field, old client, new server
● Added field, new client, old server
● Removed field, new client, old server
16. Variant
● Variant
● Each byte in a varint, except the last byte, has the
most significant bit (msb) set – this indicates that
there are further bytes to come. The lower 7 bits of
each byte are used to store the two's complement
representation of the number in groups of 7 bits,
least significant group first.
● 300 → 1010 1100 0000 0010