#include <userver/ugrpc/server/generic_service_base.hpp>
Allows to handle RPCs with dynamic method names.
To use:
YourGenericService
;YourGenericService
in a descendent of ServiceComponentBase, e.g. YourGenericServiceComponent
Alternatively, just inherit from GenericServiceBase::Component, with the disadvantage that the service will not be unit-testable.
The API is mainly intended for proxies, where the request-response body is passed unchanged, with settings taken solely from the RPC metadata. In cases where the code needs to operate on the actual messages, serialization of requests and responses is left as an exercise to the user.
Middlewares are customizable and are applied as usual, except that no message hooks are called, meaning that there won't be any logs of messages from the default middleware.
Statically-typed services, if registered, take priority over generic services. It only makes sense to register at most 1 generic service.
Metrics are accounted for "Generic/Generic"
fake call name by default. This is the safe choice that avoids potential OOMs. To use the real dynamic RPC name for metrics, use CallAnyBase::SetMetricsCallName in conjunction with CallAnyBase::GetCallName.
For a more complete sample, see grpc_generic_api.
Definition at line 59 of file generic_service_base.hpp.
Public Types | |
using | Component = impl::ServiceComponentBase<GenericServiceBase> |
using | GenericCallContext = ugrpc::server::GenericCallContext |
using | GenericReaderWriter = ugrpc::server::ReaderWriter<grpc::ByteBuffer, grpc::ByteBuffer> |
using | GenericResult = ugrpc::server::StreamingResult<grpc::ByteBuffer> |
Public Member Functions | |
GenericServiceBase (GenericServiceBase &&)=delete | |
GenericServiceBase & | operator= (GenericServiceBase &&)=delete |
virtual GenericResult | Handle (GenericCallContext &context, GenericReaderWriter &stream)=0 |
Override this method in the derived class to handle all RPCs. RPC name can be obtained through GenericCallContext::GetCallName. | |
using ugrpc::server::GenericServiceBase::Component = impl::ServiceComponentBase<GenericServiceBase> |
Inherits from both GenericServiceBase and ServiceComponentBase. Allows to implement the service directly in a component. The disadvantage is that such services are not unit-testable.
Definition at line 64 of file generic_service_base.hpp.
Definition at line 66 of file generic_service_base.hpp.
using ugrpc::server::GenericServiceBase::GenericReaderWriter = ugrpc::server::ReaderWriter<grpc::ByteBuffer, grpc::ByteBuffer> |
Definition at line 68 of file generic_service_base.hpp.
using ugrpc::server::GenericServiceBase::GenericResult = ugrpc::server::StreamingResult<grpc::ByteBuffer> |
Definition at line 69 of file generic_service_base.hpp.