gRPC in Golang

aside section ._1OhGeD · · 515 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

gRPC is a new and modern framework for building scalable, modern and fast API. It is leveraged by many top tech companies such as Google, Square & Netflix and enables programmers to write micro-services in any language they want while keeping the ability to easily create communications between these services. It relies on Protocol Buffers for the transport mechanism and Service Definition language.

Better than REST API! Build a fast scalable HTTP/2 API for a Golang micro service with gRPC, Protocol Buffers (protobuf)

HTTP2 和 HTTP1.1 比较

https://imagekit.io/demo/http2-vs-http1

安装

go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go

四种使用方式

image
Unary

Unary RPC calls are the basic Request/Response
The client will send one message to the server and will receive one response from the server.

Server Streaming

The client will send one message to the server and will receive many response from the server.

server streaming are well suited for

  • when the server needs to send a lot of data (big data)
  • when the server needs to "PUSH" data to the client without having the client request for more (think live feed, chat etc)
Client Streaming

The client will send many message to the server and will receive one response from the server.
client streaming are well suited for

  • when the client needs to send a lot of data (big data)
  • when the server processing is expensive and should happen as the client sends data
  • when the client needs to "PUSH" data to the server without really expecting a response
Bi Directional Streaming

The client will send many message to the server and will receive many response from the server.

the number of requests and responses does not have to match.

Bi Directional Streaming are well suited for

  • when the client and the server needs to send a lot of data asynchronously
  • "Chat" protocol
  • Long running connections
源码地址
https://github.com/happy-python/grpc-golang
参考连接

有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:aside section ._1OhGeD

查看原文:gRPC in Golang

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

515 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传