dongshao4207 2018-04-19 15:35
浏览 1641

如何从Go客户端获取gRPC服务器IP

I use docker-compose or kubernetes to deploy my gRPC servers, and want to get the server IP address in the go client. Does the gRPC library provides the get server-side IP method?

BTW, the scenario here is that i want to log the server ip to check whether nginx, envoy and other L7 load balancers make correct routing decisions.

  • 写回答

1条回答 默认 最新

  • dpt62283 2018-04-20 04:05
    关注

    It's an interesting question, as you already have knowledge about the gRPC server address prior to a client creation

    conn, err := grpc.Dial(*serverAddr)
    if err != nil {
        ...
    }
    defer conn.Close()
    client := pb.NewRouteGuideClient(conn)
    

    I don't believe there is a method for getting server IP in the standard gRPC library. If you use external load balancers/proxies (e.g. Nginx or Envoy) you can add the end server IP to the metadata on the server side

    md := metadata.Pairs(
        "serverIP", "127.0.0.1",
    )
    

    The LB distributes the RPC call to one of the available backend servers that implement the actual logic for serving the call. The LB keeps track of load on each backend and implements algorithms for distributing load fairly. The clients themselves do not know about the backend servers. read more https://grpc.io/blog/loadbalancing

    Remote Procedure Call (RPC) is a higher level abstraction, you shouldn't deal with networking using RPC.

    If you're trying to implement client side load balancing you should consider load balancing within gRPC (https://github.com/grpc/grpc/blob/master/doc/load-balancing.md), which is a special protocol you have to implement.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料