douzhuang1900 2019-06-05 18:44
浏览 34

GRPC:何时获得新客户?

I am using grpc in my project, if i have a grpc service call helloService, should i use GetNewHelloServiceClient to get a new client in every function? Or just get once in start program?

// for example:

c.GET("/hello", SayHello)

func SayHello() {
    c := pb.GetNewHelloServiceClient()
    res, err := c.SayHello(context.Background(), &request)

    if err != nil {
     return
    }
    fmt.print(res.Hello)
}
  • 写回答

1条回答 默认 最新

  • dou1908 2019-06-06 03:55
    关注

    Create a gRPC client just once.

    Lots of networking concepts in go are designed for reuse: http clients, http transports, sql.DB connection pools etc. They are all go-routine safe & should only be created once but reused many times.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算