Golang 学习笔记

gRPC in Golang

2019-10-12  本文已影响0人  与蟒唯舞

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

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

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

源码地址
https://github.com/happy-python/grpc-golang
参考连接
上一篇 下一篇

猜你喜欢

热点阅读