userver: ugrpc::server::CallAnyBase Class Reference
Loading...
Searching...
No Matches
ugrpc::server::CallAnyBase Class Referenceabstract

#include <userver/ugrpc/server/rpc.hpp>

Detailed Description

A non-typed base class for any gRPC call.

Definition at line 33 of file rpc.hpp.

+ Inheritance diagram for ugrpc::server::CallAnyBase:

Public Member Functions

 CallAnyBase (impl::CallParams &&params)
 
virtual void FinishWithError (const grpc::Status &status)=0
 Complete the RPC with an error.
 
grpc::ServerContext & GetContext ()
 
std::string_view GetCallName () const
 Name of the call. Consists of service and method names.
 
tracing::SpanGetSpan ()
 
utils::AnyStorage< StorageContext > & GetStorageContext ()
 Returns call context for storing per-call custom data.
 
virtual bool IsFinished () const =0
 

Protected Member Functions

ugrpc::impl::RpcStatisticsScope & Statistics ()
 
logging::LoggerRef AccessTskvLogger ()
 
void LogFinish (grpc::Status status) const
 

Constructor & Destructor Documentation

◆ CallAnyBase()

ugrpc::server::CallAnyBase::CallAnyBase ( impl::CallParams && params)
inline

Definition at line 35 of file rpc.hpp.

Member Function Documentation

◆ AccessTskvLogger()

logging::LoggerRef ugrpc::server::CallAnyBase::AccessTskvLogger ( )
inlineprotected

Definition at line 91 of file rpc.hpp.

◆ FinishWithError()

virtual void ugrpc::server::CallAnyBase::FinishWithError ( const grpc::Status & status)
pure virtual

Complete the RPC with an error.

Finish must not be called multiple times for the same RPC.

Parameters
statuserror details
Exceptions
ugrpc::server::RpcErroron an RPC error

Implemented in ugrpc::server::UnaryCall< Response >, ugrpc::server::InputStream< Request, Response >, ugrpc::server::OutputStream< Response >, and ugrpc::server::BidirectionalStream< Request, Response >.

Examples
samples/grpc_middleware_service/src/middlewares/server/middleware.cpp.

◆ GetCallName()

std::string_view ugrpc::server::CallAnyBase::GetCallName ( ) const
inline

Name of the call. Consists of service and method names.

Definition at line 51 of file rpc.hpp.

◆ GetContext()

grpc::ServerContext & ugrpc::server::CallAnyBase::GetContext ( )
inline
Returns
the ServerContext used for this RPC
Note
Initial server metadata is not currently supported
Trailing metadata, if any, must be set before the Finish call
Examples
samples/grpc_middleware_service/src/middlewares/server/middleware.cpp.

Definition at line 48 of file rpc.hpp.

◆ GetSpan()

tracing::Span & ugrpc::server::CallAnyBase::GetSpan ( )
inline

Definition at line 53 of file rpc.hpp.

◆ GetStorageContext()

utils::AnyStorage< StorageContext > & ugrpc::server::CallAnyBase::GetStorageContext ( )
inline

Returns call context for storing per-call custom data.

The context can be used to pass data from server middleware to client handler or from one middleware to another one.

Example usage:

In authentication middleware:

if (password_is_correct) {
// Username is authenticated, set it in per-call storage context
ctx.GetCall().GetStorageContext().Emplace(kAuthUsername, username);
}

In client handler:

const auto& username = rpc.GetStorageContext().Get(kAuthUsername);
auto msg = fmt::format("Hello, {}!", username);

Definition at line 77 of file rpc.hpp.

◆ Statistics()

ugrpc::impl::RpcStatisticsScope & ugrpc::server::CallAnyBase::Statistics ( )
inlineprotected

Definition at line 89 of file rpc.hpp.


The documentation for this class was generated from the following file: