Skip to content

Using the gRPC ProtoReflectionService in a gRPC Remote Service

Scott Lewis edited this page Apr 14, 2021 · 4 revisions

gRPC added a ProtoReflectionService in version 1.36, allowing special clients such a grpc_cli and evans to provide information at runtime about a remote grpc service.

This distribution provider has been enhanced to allow a ProtoReflectionService to be added to any running server instance so that grpc_cli and/or evans clients can reflect on what other service are available on a running server.

As described in this tutorial it's usually necessary for the server service author to add the ProtoReflectionService to their server application before compilation. Since OSGi is a dynamic environment, we've provided console shell commands that allow the ProtoReflectionService to be added/removed dynamically to an exported remote service.

For example, if the HealthCheck impl example is run in an environment (e.g. Karaf) that has an OSGi console, the following commands are available:

karaf@root()> ecf-grpc:listreflection
Server                                       |Reflection
grpc://localhost:50002                       |inactive

The output indicates that the grpc server running on localhost:50002 currently does not have reflection active. To turn on/activate reflection:

karaf@root()> ecf-grpc:addreflection
Server                                       |Reflection
grpc://localhost:50002                       |active

If reflection is active an evans client can connect to it and get information about the services being exposed

C:\Users\slewis\Downloads>evans -p 50002 -r

  ______
 |  ____|
 | |__    __   __   __ _   _ __    ___
 |  __|   ' ' / /  / _. | | '_ '  / __|
 | |____   ' V /  | (_| | | | | | '__ ,
 |______|   '_/    '__,_| |_| |_| |___/

 more expressive universal gRPC client


grpc.health.v1.HealthCheck@127.0.0.1:50002> show services
+-------------+-------------+--------------------+---------------------+
|   SERVICE   |     RPC     |    REQUEST TYPE    |    RESPONSE TYPE    |
+-------------+-------------+--------------------+---------------------+
| HealthCheck | Check       | HealthCheckRequest | HealthCheckResponse |
| HealthCheck | WatchServer | HealthCheckRequest | HealthCheckResponse |
| HealthCheck | WatchClient | HealthCheckRequest | HealthCheckResponse |
| HealthCheck | WatchBidi   | HealthCheckRequest | HealthCheckResponse |
+-------------+-------------+--------------------+---------------------+

grpc.health.v1.HealthCheck@127.0.0.1:50002>

evans and grpc_cli have other capabilities such as describing the structure of the request and response types, and calling a remote service.

There is also removereflection to make the reflection inactive

karaf@root()> ecf-grpc:removereflection
Server                                       |Reflection
grpc://localhost:50002                       |inactive

Note: the group name of ecf-grpc can usually be ommited, resulting in

karaf@root()> addreflection
Server                                       |Reflection
grpc://localhost:50002                       |active

Also the following synonyms are provided:

addreflection -> ar

listreflection -> lr

removereflection -> rr

so the following will also work

karaf@root()> ar
Server                                       |Reflection
grpc://localhost:50002                       |active
Clone this wiki locally