1gRPC Reflection Example 2================ 3 4The reflection example has a Hello World server with `ProtoReflectionService` registered. 5 6### Build the example 7 8To build the example server, from the `grpc-java/examples/examples-reflection` 9directory: 10``` 11$ ../gradlew installDist 12``` 13 14This creates the scripts `build/install/example-reflection/bin/reflection-server`. 15 16### Run the example 17 18gRPC Server Reflection provides information about publicly-accessible gRPC services on a server, 19and assists clients at runtime to construct RPC requests and responses without precompiled 20service information. It is used by gRPCurl, which can be used to introspect server protos and 21send/receive test RPCs. 22 231. To start the reflection example server on its default port of 50051, run: 24``` 25$ ./build/install/example-reflection/bin/reflection-server 26``` 27 282. After enabling Server Reflection in a server application, you can use gRPCurl to check its 29services. Instructions on how to install and use gRPCurl can be found at [gRPCurl Installation](https://github.com/fullstorydev/grpcurl#installation) 30 31After installing gRPCurl, open a new terminal and run the commands from the new terminal. 32 33### List all the services exposed at a given port 34 35 ``` 36 $ grpcurl -plaintext localhost:50051 list 37 ``` 38 39Output 40 41 ``` 42 grpc.reflection.v1alpha.ServerReflection 43 helloworld.Greeter 44 ``` 45 46### List all the methods of a service 47 ``` 48 $ grpcurl -plaintext localhost:50051 helloworld.Greeter 49 ``` 50Output 51 ``` 52 helloworld.Greeter.SayHello 53 ``` 54 55### Describe services and methods 56 57The describe command inspects a method given its full name(in the format of 58`<package>.<service>.<method>`). 59 60 ``` 61$ grpcurl -plaintext localhost:50051 describe helloworld.Greeter.SayHello 62 ``` 63 64Output 65 66 ``` 67 helloworld.Greeter.SayHello is a method: 68 rpc SayHello ( .helloworld.HelloRequest ) returns ( .helloworld.HelloReply ); 69 ``` 70 71### Inspect message types 72 73We can use the describe command to inspect request/response types given the full name of the type 74(in the format of `<package>.<type>`). 75 76Get information about the request type: 77 78 ``` 79$ grpcurl -plaintext localhost:50051 describe helloworld.HelloRequest 80 ``` 81 82Output 83 84 ``` 85 helloworld.HelloRequest is a message: 86 message HelloRequest { 87 string name = 1; 88 } 89 ``` 90 91### Call a remote method 92 93We can send RPCs to a server and get responses using the full method name 94(in the format of `<package>.<service>.<method>`). The `-d <string>` flag represents the request data 95and the -format text flag indicates that the request data is in text format. 96 97 ``` 98 $ grpcurl -plaintext -format text -d 'name: "gRPCurl"' \ 99 localhost:50051 helloworld.Greeter.SayHello 100 ``` 101 102Output 103 104 ``` 105 message: "Hello gRPCurl" 106 ``` 107