gRPC naming and discovery

    etcd provides a gRPC resolver to support an alternative name system that fetches endpoints from etcd for discovering gRPC services. The underlying mechanism is based on watching updates to keys prefixed with the service name.

    The etcd client provides a gRPC resolver for resolving gRPC endpoints with an etcd backend. The resolver is initialized with an etcd client:

    Managing service endpoints

    The etcd resolver treats all keys under the prefix of the resolution target following a “/” (e.g., “foo/bar/my-service/“) with JSON-encoded (historically go-grpc ) values as potential service endpoints. Endpoints are added to the service by creating new keys and removed from the service by deleting keys.

    1. ETCDCTL_API=3 etcdctl put foo/bar/my-service/1.2.3.4 '{"Addr":"1.2.3.4","Metadata":"..."}'

    The etcd client’s endpoints.Manager method can also register new endpoints with a key matching the Addr:

    Hosts can be deleted from the service through :

    1. ETCDCTL_API=3 etcdctl del foo/bar/my-service/1.2.3.4

    The etcd client’s endpoints.Manager method also supports deleting endpoints:

    1. lease=`ETCDCTL_API=3 etcdctl lease grant 5 | cut -f2 -d' '`

    In the golang:

    If it’s desired to modify multiple endpoints in a single transaction, endpoints.Manager can be used directly:

    1. em := endpoints.NewManager(c, "foo")
    2. err := em.Update(context.TODO(), []*endpoints.UpdateWithOpts{
    3. endpoints.NewAddUpdateOpts("foo/bar/my-service/e1", endpoints.Endpoint{Addr: "1.2.3.14"})})