#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 excercise 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 57 of file generic_service_base.hpp.
Public Types | |
using | Component = impl::ServiceComponentBase<GenericServiceBase> |
using | Call = BidirectionalStream<grpc::ByteBuffer, grpc::ByteBuffer> |
Public Member Functions | |
GenericServiceBase (GenericServiceBase &&)=delete | |
GenericServiceBase & | operator= (GenericServiceBase &&)=delete |
virtual void | Handle (Call &call)=0 |
Override this method in the derived class to handle all RPCs. RPC name can be obtained through CallAnyBase::GetCallName. | |
using ugrpc::server::GenericServiceBase::Call = BidirectionalStream<grpc::ByteBuffer, grpc::ByteBuffer> |
Definition at line 64 of file generic_service_base.hpp.
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 62 of file generic_service_base.hpp.
|
pure virtual |
Override this method in the derived class to handle all RPCs. RPC name can be obtained through CallAnyBase::GetCallName.
Finish
or FinishWithError
, otherwise the server will respond with an "internal
server error" status.