The gRPC client can be extended by middlewares. Middleware is called on each outgoing RPC request and incoming response. Different middlewares handle the call in the defined order. A middleware may decide to reject the call or call the next middleware in the stack. Middlewares may implement almost any enhancement to the gRPC client including authorization and authentication, ratelimiting, logging, tracing, audit, etc.
There is a ugrpc::client::MiddlewarePipelineComponent
component for configuring the middlewares's pipeline. There are default middlewares:
If you add these middlewares to the components::ComponentList, these middlewares will be enabled by default. To register core gRPC client components and a set of builtin middlewares use ugrpc::client::DefaultComponentList or ugrpc::client::MinimalComponentList. As will be shown below, custom middlewares require additional actions to work: registering in grpc-client-middleware-pipeline
and writing a required static config entry.
ugrpc::client::MiddlewarePipelineComponent
is a global configuration of client middlewares. If you don't want to disable userver middlewares, just take that config:
You can enable or disable any middleware:
For more information about enabled
:
How to override a static config of a middleware: grpc_middlewares_config_override.
How to implement your own middleware with a static config: gRPC middlewares configuration.
gRPC client middleware implementation.