Netty实现一个简单的RPC框架
微服务
微服务通讯
API构建需要考虑的因素
通讯协议
文本协议或者二进制协议
支持的调用方式:单向、双向、Streaming
API定义与声明
API容错、可伸缩性
RPC框架
REST
http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
REST即Representational State Transfer的缩写,可译为“表现层状态转化”,是一种软件体系结构架构风格。REST最大的几个特点为:资源、统一接口、URI和无状态。
符合REST的系统具有下述特点:
Client-Server Architecture
Statelessness
Cacheability
Layered System
Code on Demand (Optional)
Uniform Interface
Restful API
HTTP + JSON
RESTFUL API
对于简单的服务, HTTP REST 能够满足要求
HTTP 谓词(GET、POST、PUT、DELETE 等) 能够满足调用需求
REST 语义清晰
对复杂服务系统,RESTful接口不足之处
性能无法满足海量并发请求的需求
文本消息JSON
HTTP协议
接口强类型的需求
RPC
远程过程调用(Remote Procedure Call,简称 RPC)是一个计算机通信协议。 该协议允许运行于一台计算机的程序调用另一台计算机的子程序,而程序员无需额外地为这个交互作用编程。 如果涉及的软件采用面向对象编程,那么远程过程调用亦可称作远程调用或远程方法调用,比如 Java RMI。
gRPC
gRPC发展历史
Google open sourced in Feb 2015
Transport Protocol: HTTP/2
Message format: Protocol Buffers v3 (Binary)
Service definition: Protocol Buffers v3 IDL
Libraries in ~10 languages (native C, C#, Go, Java)
RPC framework
gRPC背景
Google has an internal RPC system, called Stubby
All production applications use RPCs
Over 10^10 RPCs per second in total
4 generations over 13 years (since 2003)
APIs for C++, Java, Python, Go
What's missing
Not suitable for external use (tight coupling with internal tools & infrastructure)
Limited language & platform support
Proprietary protocol and security
No mobile support
gRPC特点
Google has an internal RPC system, called Stubby
All production applications use RPCs
Over 10^10 RPCs per second in total
4 generations over 13 years (since 2003)
APIs for C++, Java, Python, Go
What's missing
Not suitable for external use (tight coupling with internal tools & infrastructure)
Limited language & platform support
Proprietary protocol and security
No mobile support
gRPC原理
A high level service definition to describe the API using Protocol Buffers PB定义服务 – 自动生成代码
Client and server code generated from the service definition in 10+ languages
Efficiency in serialization with PB and connection with HTTP/2 HTTP/2 PB高性能
Connection options: Unary, server-side streaming, client-side Streaming, bi-direction-streaming
Authentication Options: SSL/TLS, token based authentication
HTTP 1.x: Limited Parallelism
每次HTTP请求一个TCP连接
HTTP请求的并发数 = TCP连接数
Keep-alive
HTTP/2历史
Released in 2015. Extend (not replace) the semantics of HTTP/1.1
Improve end-user perceived latency
Address the “head of line blocking”
Not require multiple connections
Minimize protocol overhead
HTTP/2主要特性
Binary Protocol – no more Text
Native Stream Support – no need for WebSocket
Stream Multiplexing – single connection
Header compression – saves more bandwidth
HTTP/2 Binary Framing
Stream is a bidirectional flow of bytes within an established connection, which may carry one or more messages.
Message is a complete sequence of frames that map to a logical request or response message.
Frame is the smallest unit of communication in HTTP/2, each containing a frame header, which at a minimum identifies the stream to which the frame belong
Multipexing多路复用
Interleave multiple requests and responses in parallel without blocking on any one
Use a single TCP connection to deliver multiple requests and responses in parallel.
Enable flow-control, server push, etc
HPACK: Header compression for HTTP/2
Client and server maintain and update an indexed list of previously seen header fields
Indexes are sent for already seen headers
Values are encoded with a static Huffman code
Protocol Buffers
Goole开源的,一个平台无关,语言无关,可扩展的序列化结构数据格式
定义了一种 IDL语言来描述数据格式
支持多种语言,可根据IDL自动生成多种语言的接口
二进制编码
Goole开源的,一个平台无关,语言无关,可扩展的序列化结构数据格式
定义了一种 IDL语言来描述数据格式
支持多种语言,可根据IDL自动生成多种语言的接口
二进制编码
Goole开源的,一个平台无关,语言无关,可扩展的序列化结构数据格式
定义了一种 IDL语言来描述数据格式
支持多种语言,可根据IDL自动生成多种语言的接口
二进制编码
gRPC开发流程
Simple RPC: Request - Response
Server-side streaming RPC
Client-side streaming RPC
Bi-directional streaming RPC
本文地址:https://blog.csdn.net/qq_31977367/article/details/107157717
上一篇: MySQL高级---B站学习总结---MySQL主从复制
下一篇: Redis的三大问题
推荐阅读
-
使用MongoDB和JSP实现一个简单的购物车系统实例
-
用Python实现一个简单的线程池
-
使用.Net Core + Vue + IdentityServer4 + Ocelot 实现一个简单的DEMO +源码
-
C#一个简单的定时小程序实现代码
-
Thinkphp5框架简单实现钩子(Hook)行为的方法示例
-
Python实现同时兼容老版和新版Socket协议的一个简单WebSocket服务器
-
Python的Flask框架中实现简单的登录功能的教程
-
利用Python的Flask框架来构建一个简单的数字商品支付解决方案
-
JavaScript之实现一个简单的Vue示例
-
一个很简单的办法实现TD的加亮效果.