Why do we need to register reflection service on gRPC server

Naresh picture Naresh · Jan 2, 2017 · Viewed 8.2k times · Source

I was going through this code of gRPC server. Can anyone tell me the need for reflection used here

Code :

func main() {
    lis, err := net.Listen("tcp", port)
    if err != nil {
        log.Fatalf("failed to listen: %v", err)
    }
    s := grpc.NewServer()
    pb.RegisterGreeterServer(s, &server{})
    // Register reflection service on gRPC server.
    reflection.Register(s)
    if err := s.Serve(lis); err != nil {
        log.Fatalf("failed to serve: %v", err)
    }
}

Answer

menghanl picture menghanl · Jan 4, 2017

Server reflection is not necessary to run the helloworld example.

The helloworld example is also used as a server reflection example, that's why you see the reflection registering code there.

More about server reflection: Server reflection is a service defined to provides information about publicly-accessible gRPC services on a gRPC server. Tutorial available here: https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md