grpc-go

GRPC Connection Management in Golang

一世执手 提交于 2021-02-18 22:11:48
问题 I am relatively new to GRPC and want to be sure that I am doing connection management correctly with golang. I don't want to have to create a new connection for every call but I also don't want to create bottlenecks as I scale. What I did was to create a single connection in the init function: var userConn *grpc.ClientConn var userServiceName string func init() { userServiceName := os.Getenv("USER_SERVICE_URL") if userServiceName == "" { userServiceName = "localhost" } logging.LogDebug(

golang grpc keepalive

只谈情不闲聊 提交于 2021-02-12 09:18:51
最近遇到 grpc 客户端报错 rpc error: code = Unavailable desc = transport is closing ,原因是连接长时间没有使用,被服务端断开,这种情况通过简单粗暴的重试策略可以解决,更加优雅的解决方案是增加保持连接策略 服务端 var kaep = keepalive.EnforcementPolicy{ MinTime: 5 * time.Second, // If a client pings more than once every 5 seconds, terminate the connection PermitWithoutStream: true, // Allow pings even when there are no active streams } var kasp = keepalive.ServerParameters{ MaxConnectionIdle: 15 * time.Second, // If a client is idle for 15 seconds, send a GOAWAY MaxConnectionAge: 30 * time.Second, // If any connection is alive for more than 30 seconds, send a GOAWAY

golang grpc keepalive

折月煮酒 提交于 2021-02-12 05:43:52
最近遇到 grpc 客户端报错 rpc error: code = Unavailable desc = transport is closing ,原因是连接长时间没有使用,被服务端断开,这种情况通过简单粗暴的重试策略可以解决,更加优雅的解决方案是增加保持连接策略 服务端 var kaep = keepalive.EnforcementPolicy{ MinTime: 5 * time.Second, // If a client pings more than once every 5 seconds, terminate the connection PermitWithoutStream: true, // Allow pings even when there are no active streams } var kasp = keepalive.ServerParameters{ MaxConnectionIdle: 15 * time.Second, // If a client is idle for 15 seconds, send a GOAWAY MaxConnectionAge: 30 * time.Second, // If any connection is alive for more than 30 seconds, send a GOAWAY

GRPC - nodejs DNS resolution failed

ぐ巨炮叔叔 提交于 2021-02-08 06:57:21
问题 I'm working with a GRPC service hosted with HTTPS and self-signed cert. When I connect using syntax like: const client = new productService('https://grpc-server-xxx.com:9090', grpc.credentials.createInsecure()) I am getting the error like this { Error: 14 UNAVAILABLE: DNS resolution failed at Object.exports.createStatusError (C:\grpc\node_modules\grpc\src\common.js:91:15) at Object.onReceiveStatus (C:\grpc\node_modules\grpc\src\client_interceptors.js:1209:28) at InterceptingListener._callNext

Go语言初探gRPC服务

混江龙づ霸主 提交于 2020-10-18 06:33:39
原文链接: https://www.jianshu.com/p/20ed82218163 环境:2018-05-12 protoc 3.5.1 go1.10.1 windows gRPC: Google主导开发的RPC框架,这里不再赘述。 准备工作 先安装Protobuf 编译器 protoc,下载地址: https://github.com/google/protobuf/releases 我的是windows,将压缩包bin目录下的exe放到环境PATH目录中即可。 然后获取插件支持库 // gRPC运行时接口编解码支持库 go get -u github.com/golang/protobuf/proto // 从 Proto文件(gRPC接口描述文件) 生成 go文件 的编译器插件 go get -u github.com/golang/protobuf/protoc-gen-go 获取go的gRPC包(网络问题可参阅 https://www.jianshu.com/p/6392cb9dc38f ) go get google.golang.org/grpc 接口文件 /src/ 新建 test.proto 示例: syntax = "proto3"; // 定义包名 package test; // 可以定义多个服务,每个服务内可以定义多个接口 service

Relative import in Go for protobuf , cannot find module path

扶醉桌前 提交于 2020-07-31 06:05:36
问题 I'm trying to write a service in go with gRPC, and when i import the protobuff file , getting an error. i tried removing all the modules in my go path and reinitialising the go modules build _/Users/tibinlukose/cart-service/pb: cannot find module for path _/Users/tibinlukose/cart-service/pb Code package main import ( pbcart "../pb/" "log" "fmt" "google.golang.org/grpc" "net" ) var ( port = 1000; ) type CartServiceServer struct { } func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) fmt

How to close all grpc server streams using gracefulStop?

时光总嘲笑我的痴心妄想 提交于 2020-04-11 06:17:28
问题 I'm trying to stop all clients connected to a stream server from server side. Actually I'm using GracefulStop method to handle it gracefully. I am waiting for os.Interrupt signal on a channel to perform a graceful stop for gRPC. but it gets stuck on server.GracefulStop() when the client is connected. func (s *Service) Subscribe(_ *empty.Empty, srv clientapi.ClientApi_SubscribeServer) error { ctx := srv.Context() updateCh := make(chan *clientapi.Update, 100) stopCh := make(chan bool) defer

Docker Build Failing google.golang.org/api/option

て烟熏妆下的殇ゞ 提交于 2020-01-23 08:57:29
问题 In my docker file , I have following Lines RUN go get -v -u go.mongodb.org/mongo-driver/mongo RUN go get -d -v ./... RUN go get google.golang.org/api/option I am getting following error . Everything was working fine 3 days before. Step 9/17 : RUN go get google.golang.org/api/option ---> Running in ec36bafa25aa # google.golang.org/api/option ../google.golang.org/api/option/option.go:153:14: undefined: grpc.RoundRobin ../google.golang.org/api/option/option.go:154:42: undefined: grpc

How can I get the client IP address and user-agent in Golang gRPC?

旧城冷巷雨未停 提交于 2019-12-13 03:06:15
问题 I set up a series of gRPC requests and responses which all work fine, but I'm stuck when I try to get the client IP address and user-agent who is calling my gRPC APIs. I read the Go gRPC documentation and other sources, but didn't find much valuable information. Few of them are talking about gRPC in Golang. Should I set up a key-value to store the IP address in the context when setting up the gRPC APIs? 回答1: The way to get the IP address was already answered pretty well here: Correct way of