userver: gRPC client middlewares
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
gRPC client middlewares

See also
gRPC middleware tutorial.

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.

Default middlewares

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:

components_manager:
components:
grpc-client-middlewares-pipeline:
grpc-client-common:
# some options...
some-client-factory:
# some client options...

Enable/disable middlewares

You can enable or disable any middleware:

components_manager:
components:
grpc-client-common:
grpc-client-middlewares-pipeline:
middlewares:
grpc-client-baggage:
enabled: false # globally disable for all clients
some-client-factory:
middlewares:
# force enable in that client. Or it can be disabled for special clients
grpc-client-baggage:
enabled: true

For more information about enabled:

See also
Enable/disable middlewares.

Static config options of a middleware

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.

How to implement your own middleware

gRPC client middleware implementation.