douchi2022 2018-05-11 13:31
浏览 1034

使用golang gRPC客户端拨打多个IP地址

I have grpc server 192.168.1.12:8800 and 192.168.1.13:8800, I want to connect them use grpc.Dial with ip list, not server discover, How can I do?

conn, err = grpc.Dial("192.168.1.12:8800,192.168.1.13:8800", grpc.WithInsecure())

with error

rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = \"transport: Error while dialing dial tcp: too many colons in address 192.168.1.12:8800,192.168.1.13:8800
  • 写回答

1条回答 默认 最新

  • dongqin1861 2018-05-12 02:14
    关注

    Unfortunately, you aren't able to pass multiple IP addresses using grpc.Dial(...), it only takes a single argument.

    gRPC in Go does have an "experimental" load balancer api that you should be able to take advantage of.

    An example of the resolver you would need to write can be found here. It creates a fake resolver that will load balance across the multiple IP addresses.

    So once you have a resolver such as that, the code you would want would look something like this:

    conn, err := grpc.Dial(
        "",
        grpc.WithInsecure(),
        grpc.WithBalancer(grpc.RoundRobin(resolver.NewPseudoResolver([]string{
            "10.0.0.1:10000",
            "10.0.0.2:10000",
        }))),
    )
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作