Apache Thrift 白皮书
介绍:
轻量级、跨语言。
简洁的抽象和实现:数据传输、序列化、应用逻辑处理。
IDL及代码生成系统。
基本架构图如下:

28种语言支持:28 programming languages。
支持客户端及服务端版本非原子性升级。
一、IDL
1、基本数据类型:
• bool A boolean value, true or false
• byte A signed byte
• i16 A 16-bit signed integer
• i32 A 32-bit signed integer
• i64 A 64-bit signed integer
• double A 64-bit floating point number
• string An encoding-agnostic text or binary string
2、Structs:通用对象
等同于面向对象语言中的类。
struct Example {
1:i32 number=10,
2:i64 bigNumber
}
3、Containers 容器:
list<>、set<>、map<,>
4、Exceptions 异常:
等同于Structs,区别定义。
5、Services 服务定义:
等同于接口定义(或面型对象语言中的虚拟类)。
基本定义:
service <service-name> {
<return-type> <method-name>() [throws (<exceptions>)]
...
}
示例:
service StringCache {
void set(1:i32 key, 2:string value),
string get(1:i32 key) throws (1:KeyNotFound knf),
void delete(1:i32 key)
}
二、Transport
数据传输
1、接口 TTransport:代码生层及数据传输解耦,主要方法定义如下
• open Opens the tranpsort
• close Closes the tranport
• isOpen Indicates whether the transport is open
• read Reads from the transport
• write Writes to the transport
• flush Forces any pending writes
TServerTransport:接受或创建Transport对象。
2、实现
TSocket:TCP/IP数据流操作。
TFileTransport:文件系统数据流操作。
扩展:TBufferedTransport(提供读写buffer缓冲)、TFramedTransport(提供帧大小头信息,用以批数据传输或非阻塞操作)、TMemoryBuffer(直接从堆栈中读写)
三、Protocol
数据结构和数据传输解耦。
1、接口,双向消息序列化反序列化,基本方法如下:
writeMessageBegin(name, type, seq)
writeMessageEnd()
writeStructBegin(name)
writeStructEnd()
writeFieldBegin(name, type, id)
writeFieldEnd()
writeFieldStop()
writeMapBegin(ktype, vtype, size)
writeMapEnd()
writeListBegin(etype, size)
writeListEnd()
writeSetBegin(etype, size)
writeSetEnd()
writeBool(bool)
writeByte(byte)
writeI16(i16)
writeI32(i32)
writeI64(i64)
writeDouble(double)
writeString(string)
方法操作消息内容:
name, type, seq = readMessageBegin() readMessageEnd()
name = readStructBegin() readStructEnd()
name, type, id = readFieldBegin() readFieldEnd()
k, v, size = readMapBegin() readMapEnd()
etype, size = readListBegin() readListEnd()
etype, size = readSetBegin() readSetEnd()
bool = readBool()
byte = readByte()
i16 = readI16()
i32 = readI32()
i64 = readI64()
double = readDouble()
string = readString()
2、...
四、RPC实现
1、TProcessor
基本定义:
interface TProcessor {
bool process(TProtocol in, TProtocol out) throws TException
}
任何复杂的系统简而来说节课分为两个端客户端、服务端,用于处理输入输出。
process() 用于处理方法调用逻辑。
2、TServer
基本处理逻辑:
->使用TServerTransport接受TTransport
->使用TTransportFactory转换TTransport为实际应用的类型(通常应用TBufferedTransportFactory)
->使用TProtocolFactory为TTransport创建输入输出
->调用TProcessor process()逻辑
server处理连接;processor处理RPC逻辑。
不同实现:
TSimpleServer:单处理线程
TThreadedServer:每个连接一个处理线程
TThreadPoolServer:线程池处理
五、实现细节
。。。
Apache Thrift 白皮书的更多相关文章
- Apache thrift RPC 双向通信
在上一篇介绍Apache thrift 安装和使用,写了一个简单的demo,讲解thrift服务的发布和客户端调用,但只是单向的客户端发送消息,服务端接收消息.而客户端却得不到服务器的响应. 在不涉及 ...
- Apache Thrift 跨语言服务开发框架
Apache Thrift 是一种支持多种编程语言的远程服务调用框架,由 Facebook 于 2007 年开发,并于 2008 年进入 Apache 开源项目管理.Apache Thrift 通过 ...
- Apache Thrift 环境配置
在 Ubuntu 14.04 下Apache Thrift 的安装方法: 1安装依赖包 sudo apt-get install libboost-dev libboost-test-dev libb ...
- Apache Thrift 服务开发框架学习记录
Apache Thrift 是 Facebook 实现的一种高效的.支持多种编程语言的远程服务调用的框架. 前言: 目前流行的服务调用方式有很多种,例如基于 SOAP 消息格式的 Web Servic ...
- Apache Thrift
Baidu Thrift Google Thrift Apache Thrift - 可伸缩的跨语言服务开发框架
- Apache Thrift - 可伸缩的跨语言服务开发框架
To put it simply, Apache Thrift is a binary communication protocol 原文地址:http://www.ibm.com/developer ...
- Apache Thrift学习之二(基础及原理)
Apache Thrift 是 Facebook 实现的一种高效的.支持多种编程语言的远程服务调用的框架.本文将从 Java 开发人员角度详细介绍 Apache Thrift 的架构.开发和部署,并且 ...
- Apache Thrift学习之一(入门及Java实例演示)
目录: 概述 下载配置 基本概念 数据类型 服务端编码基本步骤 客户端编码基本步骤 数据传输协议 实例演示(java) thrift生成代码 实现接口Iface TSimpleServer服务模型 T ...
- Apache Thrift入门(安装、测试与java程序编写)
安装Apache Thrift ubuntu linux运行: #!/bin/bash #下载 wget http://mirrors.cnnic.cn/apache/thrift/0.9.1/thr ...
- Apache Thrift的简单使用
Apache Thrift的简单使用 ---------------------- 1. 简介 Thrift是Facebook的一个开源项目,主要是一个跨语言的服务开发框架.它有一个代码生成器来对它所 ...
随机推荐
- 【LeetCode排序专题02】最小k个数,关于快速排序的讨论
最小k个数 https://leetcode.cn/problems/smallest-k-lcci/ 输入整数数组 arr ,找出其中最小的 k 个数.例如,输入4.5.1.6.2.7.3.8这8个 ...
- 论文《Attention is all you need》阅读笔记
Attention is all you need Transformer模型 Model Architecture Transformer结构上和传统的翻译模型相同,拥有encoder-decode ...
- 关于Cortex-M3报错解决方法总结:Flash Download failed错误
事情原因:在一次使用ST-LINK v2下载程序时,突然出现 Error:Flash Download Failed-"Cortex-M3"这个错误,显示没有错误,没有警告.芯片型 ...
- 使用Order By NULL 解决 group by后自动排序,优化Sql性能
使用Order By NULL 解决 group by后自动排序,优化Sql性能 对于 Group by 后的结果,Mysql搜索引擎会将结果按照Group by 的字段按照升序,自动排序,例如: t ...
- 如何将应用一键部署至多个环境?丨Walrus教程
在 Walrus 平台上,运维团队在资源定义(Resource Definition)中声明提供的资源类型,通过设置匹配规则,将不同的资源部署模板应用到不同类型的环境.项目等.与此同时,研发人员无需关 ...
- Spring事务(六)-只读事务
@Transactional(readOnly=true)就可以把事务方法设置成只读事务.设置了只读事务,事务从开始到结束,将看不见其他事务所提交的数据.这在某种程度上解决了事务并发的问题.一个方法内 ...
- clickhouse快速上手和问题记录
clickhouse官方中文社区实战经验:手把手教你搭建单机clickhouse开发环境 我是用的是centOS7的虚拟机, 官方教程中的:sudo /etc/init.d/clickhouse-se ...
- 摆脱鼠标系列 vscode 向右拆分编辑器 ctrl + 右箭头
摆脱鼠标系列 vscode 向右拆分编辑器 ctrl + 右箭头 为什么 今天看见一个两栏工作的,左侧放的是目录大纲,右侧是代码内容 用快捷键 ctrl + 右箭头 快速扩展一个,关闭可以ctrl + ...
- CMake 用法总结(转载)
原文地址 什么是 CMake All problems in computer science can be solved by another level of indirection. David ...
- Java-求根号n
平方,开根号在java中是很简单的,Math.sqrt(double n)或者 Math.pow(double a, double b),求a的b次方.但是我们可以自己想想,这些方法到底是怎么实现的. ...