examples: reflection (#2594)
This commit is contained in:
@ -1,16 +1,19 @@
|
||||
# gRPC Server Reflection Tutorial
|
||||
|
||||
gRPC Server Reflection provides information about publicly-accessible gRPC
|
||||
services on a server, and assists clients at runtime to construct RPC
|
||||
requests and responses without precompiled service information. It is used by
|
||||
gRPC CLI, which can be used to introspect server protos and send/receive test
|
||||
RPCs.
|
||||
services on a server, and assists clients at runtime to construct RPC requests
|
||||
and responses without precompiled service information. It is used by gRPC CLI,
|
||||
which can be used to introspect server protos and send/receive test RPCs.
|
||||
|
||||
## Enable Server Reflection
|
||||
|
||||
gRPC-go Server Reflection is implemented in package [reflection](https://github.com/grpc/grpc-go/tree/master/reflection). To enable server reflection, you need to import this package and register reflection service on your gRPC server.
|
||||
gRPC-go Server Reflection is implemented in package
|
||||
[reflection](https://github.com/grpc/grpc-go/tree/master/reflection). To enable
|
||||
server reflection, you need to import this package and register reflection
|
||||
service on your gRPC server.
|
||||
|
||||
For example, to enable server reflection in `example/helloworld`, we need to make the following changes:
|
||||
For example, to enable server reflection in `example/helloworld`, we need to
|
||||
make the following changes:
|
||||
|
||||
```diff
|
||||
--- a/examples/helloworld/greeter_server/main.go
|
||||
@ -33,12 +36,15 @@ For example, to enable server reflection in `example/helloworld`, we need to mak
|
||||
}
|
||||
```
|
||||
|
||||
We have made this change in `example/helloworld`, and we will use it as an example to show the use of gRPC server reflection and gRPC CLI in this tutorial.
|
||||
An example server with reflection registered can be found at
|
||||
`examples/features/reflection/server`.
|
||||
|
||||
## gRPC CLI
|
||||
|
||||
After enabling Server Reflection in a server application, you can use gRPC CLI to check its services.
|
||||
gRPC CLI is only available in c++. Instructions on how to use gRPC CLI can be found at [command_line_tool.md](https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md).
|
||||
After enabling Server Reflection in a server application, you can use gRPC CLI
|
||||
to check its services. gRPC CLI is only available in c++. Instructions on how to
|
||||
use gRPC CLI can be found at
|
||||
[command_line_tool.md](https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md).
|
||||
|
||||
To build gRPC CLI:
|
||||
|
||||
@ -55,7 +61,7 @@ First, start the helloworld server in grpc-go directory:
|
||||
|
||||
```sh
|
||||
$ cd <grpc-go-directory>
|
||||
$ go run examples/helloworld/greeter_server/main.go
|
||||
$ go run examples/features/reflection/server/main.go
|
||||
```
|
||||
|
||||
Open a new terminal and make sure you are in the directory where grpc_cli lives:
|
||||
@ -76,8 +82,9 @@ $ cd <grpc-cpp-dirctory>/bins/opt
|
||||
|
||||
output:
|
||||
```sh
|
||||
helloworld.Greeter
|
||||
grpc.examples.echo.Echo
|
||||
grpc.reflection.v1alpha.ServerReflection
|
||||
helloworld.Greeter
|
||||
```
|
||||
|
||||
- List one service with details
|
||||
|
Reference in New Issue
Block a user