userver: ugrpc::server::OutputStream< Response > Class Template Reference
Loading...
Searching...
No Matches
ugrpc::server::OutputStream< Response > Class Template Referencefinal

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

Detailed Description

template<typename Response>
class ugrpc::server::OutputStream< Response >

Controls a single request -> response stream RPC.

This class is not thread-safe except for GetContext.

The RPC is cancelled on destruction unless the stream has been finished.

If any method throws, further methods must not be called on the same stream, except for GetContext.

Definition at line 131 of file rpc.hpp.

+ Inheritance diagram for ugrpc::server::OutputStream< Response >:

Public Member Functions

void Write (Response &response) override
 Write the next outgoing message.
 
void Write (Response &&response) override
 Write the next outgoing message.
 
void Finish ()
 Complete the RPC successfully.
 
void FinishWithError (const grpc::Status &status) override
 Complete the RPC with an error.
 
void WriteAndFinish (Response &response)
 Equivalent to Write + Finish
 
void WriteAndFinish (Response &&response)
 Equivalent to Write + Finish
 
 OutputStream (impl::CallParams &&call_params, impl::RawWriter< Response > &stream)
 For internal use only.
 
 OutputStream (OutputStream &&)=delete
 
OutputStreamoperator= (OutputStream &&)=delete
 
bool IsFinished () const override
 Useful for generic error reporting via FinishWithError.
 
grpc::ServerContext & GetContext ()
 
std::string_view GetCallName () const
 Name of the RPC in the format full.path.ServiceName/MethodName
 
std::string_view GetServiceName () const
 Get name of gRPC service.
 
std::string_view GetMethodName () const
 Get name of called gRPC method.
 
tracing::SpanGetSpan ()
 Get the span of the current RPC. Span's lifetime covers the Handle call of the outermost middleware.
 
CallKind GetCallKind () const
 Get RPCs kind of method.
 
utils::AnyStorage< StorageContext > & GetStorageContext ()
 Returns call context for storing per-call custom data.
 
void SetMetricsCallName (std::string_view call_name)
 Set a custom call name for metric labels.
 

Protected Member Functions

ugrpc::impl::RpcStatisticsScope & GetStatistics ()
 
logging::LoggerRef AccessTskvLogger ()
 
void LogFinish (grpc::Status status) const
 
void ApplyRequestHook (google::protobuf::Message *request)
 
void ApplyResponseHook (google::protobuf::Message *response)
 

Constructor & Destructor Documentation

◆ OutputStream()

template<typename Response >
ugrpc::server::OutputStream< Response >::OutputStream ( impl::CallParams && call_params,
impl::RawWriter< Response > & stream )

For internal use only.

Definition at line 385 of file rpc.hpp.

◆ ~OutputStream()

template<typename Response >
ugrpc::server::OutputStream< Response >::~OutputStream ( )
override

Definition at line 389 of file rpc.hpp.

Member Function Documentation

◆ AccessTskvLogger()

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

Definition at line 105 of file call.hpp.

◆ Finish()

template<typename Response >
void ugrpc::server::OutputStream< Response >::Finish ( )

Complete the RPC successfully.

Finish must not be called multiple times.

Exceptions
ugrpc::server::RpcErroron an RPC error

Definition at line 418 of file rpc.hpp.

◆ FinishWithError()

template<typename Response >
void ugrpc::server::OutputStream< Response >::FinishWithError ( const grpc::Status & status)
overridevirtual

Complete the RPC with an error.

Finish must not be called multiple times.

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

Implements ugrpc::server::CallAnyBase.

Definition at line 430 of file rpc.hpp.

◆ GetCallKind()

CallKind ugrpc::server::CallAnyBase::GetCallKind ( ) const
inlineinherited

Get RPCs kind of method.

Definition at line 58 of file call.hpp.

◆ GetCallName()

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

Name of the RPC in the format full.path.ServiceName/MethodName

Definition at line 45 of file call.hpp.

◆ GetContext()

grpc::ServerContext & ugrpc::server::CallAnyBase::GetContext ( )
inlineinherited
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 42 of file call.hpp.

◆ GetSpan()

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

Get the span of the current RPC. Span's lifetime covers the Handle call of the outermost middleware.

Definition at line 55 of file call.hpp.

◆ GetStatistics()

ugrpc::impl::RpcStatisticsScope & ugrpc::server::CallAnyBase::GetStatistics ( )
inlineprotectedinherited

Definition at line 103 of file call.hpp.

◆ GetStorageContext()

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

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 82 of file call.hpp.

◆ IsFinished()

template<typename Response >
bool ugrpc::server::OutputStream< Response >::IsFinished ( ) const
overridevirtual

Useful for generic error reporting via FinishWithError.

Implements ugrpc::server::CallAnyBase.

Definition at line 467 of file rpc.hpp.

◆ Write() [1/2]

template<typename Response >
void ugrpc::server::OutputStream< Response >::Write ( Response && response)
overridevirtual

Write the next outgoing message.

Parameters
responsethe next message to write
Exceptions
ugrpc::server::RpcErroron an RPC error

Implements ugrpc::server::Writer< Response >.

Definition at line 397 of file rpc.hpp.

◆ Write() [2/2]

template<typename Response >
void ugrpc::server::OutputStream< Response >::Write ( Response & response)
overridevirtual

Write the next outgoing message.

Parameters
responsethe next message to write
Exceptions
ugrpc::server::RpcErroron an RPC error

Implements ugrpc::server::Writer< Response >.

Definition at line 402 of file rpc.hpp.

◆ WriteAndFinish() [1/2]

template<typename Response >
void ugrpc::server::OutputStream< Response >::WriteAndFinish ( Response && response)

Equivalent to Write + Finish

This call saves one round-trip, compared to separate Write and Finish.

Finish must not be called multiple times.

Parameters
responsethe final response message
Exceptions
ugrpc::server::RpcErroron an RPC error

Definition at line 441 of file rpc.hpp.

◆ WriteAndFinish() [2/2]

template<typename Response >
void ugrpc::server::OutputStream< Response >::WriteAndFinish ( Response & response)

Equivalent to Write + Finish

This call saves one round-trip, compared to separate Write and Finish.

Finish must not be called multiple times.

Parameters
responsethe final response message
Exceptions
ugrpc::server::RpcErroron an RPC error

Definition at line 446 of file rpc.hpp.


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