gRPC-Go

gRPC 的 Go 语言实现。基于 HTTP/2 的 RPC。「The Go language implementation of gRPC. HTTP/2 based RPC」

Github stars Tracking Chart

gRPC-Go

gRPCGo 实现。一个高性能、开源、通用的 RPC 框架,将移动和 HTTP/2 放在首位。更多信息请参见 Go gRPC 文档,或者直接跳转到 快速入门

先决条件

  • Go:最新 三大版本 发布 中的任何一个。

安装

如果支持 Go module(Go 1.11+),只需添加以下导入即可:

import "google.golang.org/grpc"

到你的代码中,然后 go [build|run|test] 会自动获取必要的依赖关系。

否则,要安装 grpc-go 包,请运行以下命令。

$ go get -u google.golang.org/grpc

了解更多

常见问题

编译错误,undefined:grpc.SupportPackageIsVersion

如果你使用的是 Go 模块:

确保你的 gRPC-Go 版本在包含生成的 .pb.go 文件的同一个模块中需要适当的版本。例如,SupportPackageIsVersion6 需要 v1.27.0,所以在你的 go.mod 文件中。

module <your module name>
require (
    google.golang.org/grpc v1.27.0
)

如果你没有使用 Go 模块:

更新 proto 包,gRPC 包,并重建 .proto 文件。

go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
go get -u google.golang.org/grpc
protoc --go_out=plugins=grpc:. *.proto

如何开启记录功能

默认的记录器由环境变量控制。像这样打开一切:

$ export GRPC_GO_LOG_VERBOSITY_LEVEL=99
$ export GRPC_GO_LOG_SEVERITY_LEVEL=info

RPC 失败,出现错误 "code = Unavailable desc = transport is closing"

  • 这个错误意味着 RPC 所使用的连接被关闭,有很多可能的原因,包括:
  • 传输凭证配置错误,连接在握手时失败了。
  • 字节被中断,可能是被中间的代理所破坏。
  • 服务器关机
  • Keepalive 参数导致连接关闭,例如,如果你已经配置服务器定期终止连接以 触发 DNS 查找。如果是这种情况,你可能想增加你的 MaxConnectionAgeGrace,以允许更长的 RPC 调用完成。

调试这个问题可能很棘手,因为错误发生在客户端,但连接被关闭的根本原因是在服务器端。在客户端和服务器上同时开启日志记录,看看是否有传输错误。


(The second edition revised by vz on 2020.12.26)

Overview

Name With Ownergrpc/grpc-go
Primary LanguageGo
Program languageShell (Language Count: 4)
PlatformLinux, Mac, Windows
License:Apache License 2.0
Release Count181
Last Release Namev1.63.2 (Posted on )
First Release Namev1.0.0 (Posted on 2016-07-11 16:19:59)
Created At2014-12-08 18:59:34
Pushed At2024-05-05 19:29:52
Last Commit At2024-05-03 19:13:26
Stargazers Count19.9k
Watchers Count482
Fork Count4.2k
Commits Count5k
Has Issues Enabled
Issues Count2493
Issue Open Count123
Pull Requests Count3883
Pull Requests Open Count16
Pull Requests Close Count781
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

gRPC-Go

Build Status
GoDoc
GoReportCard

The Go implementation of gRPC: A high performance, open
source, general RPC framework that puts mobile and HTTP/2 first. For more
information see the gRPC Quick Start:
Go
guide.

Installation

To install this package, you need to install Go and setup your Go workspace on
your computer. The simplest way to install the library is to run:

$ go get -u google.golang.org/grpc

With Go module support (Go 1.11+), simply import "google.golang.org/grpc" in
your source code and `go [build

To the top