Skip to content

layout: post title: "title" subtitle: "thrift" date: 2019-04-23 16:24:35 author: "soaringsoul" header-img: "img/posts/default_post.jpg" catalog: true tags: - tag


thrift 使用

.thrift thrift -r --gen cpp .thrift 会在gen-cpp生成4个文件 _constants.h _constants.cpp _types.h _types.cpp

.thrift文件中包含service时,会生成额外的文件

thrift 接口

service - 定义rpc调用接口

类型

基本类型(不支持无符号类型, 容器类型: list, set, map

option 和 required option 设置的字段, 发送方赋值时需要使用__set_xxx()函数来赋值,否则不能被接收方接收到

https://wiki.apache.org/thrift/ThriftUsageC++ * TNonblockingServer with a thread pool is the c++ alternative of the JAVA THsHaServer; * TNonblockingServer withOUT a thread pool is the c++ alternative of the JAVA TNonblockingServer;

thrift 的client 不是线程安全的

TNonblockingServer with a thread pool

one thread - network I/O

thread pool for request processing

thrift 组件

server: thrift提供的几个服务器模型,包括nonblocking server(多线程非阻塞IO), thread poll server(多线程阻塞IO)等

concurrency:主要是thrift封装的对线程的创建、监控、管理等的支持。

processor:对task的具体业务逻辑处理,与IDL方法定义自动生成的代码相关

protocol:对IDL数据序列化/反序列化处理,与IDL对象定义自动生成的代码相关

transport:通信协议传输层,涉及到TCP,HTTP等协议,PIPE方式通信,SSL协议等