userver: ugrpc::client Namespace Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
ugrpc::client Namespace Reference

Detailed Description

Client-side utilities.

Namespaces

namespace  middlewares
 

Classes

class  AbortedError
 
class  AlreadyExistsError
 
class  BaseError
 Base exception for all the client errors. More...
 
class  BidirectionalStream
 Controls a request stream -> response stream RPC. More...
 
class  CallAnyBase
 Base class for any RPC. More...
 
class  CancelledError
 Concrete errors for all the error codes. More...
 
class  ClientFactory
 Creates gRPC clients. More...
 
class  ClientFactoryComponent
 Provides a ClientFactory in the component system. More...
 
struct  ClientFactorySettings
 Settings relating to the ClientFactory. More...
 
struct  ClientInfo
 Client meta info for a middleware construction. More...
 
struct  ClientQos
 
struct  ClientSettings
 Settings relating to creation of a code-generated client. More...
 
class  CommonComponent
 Contains common machinery that's required for all ugrpc clients. More...
 
class  DataLossError
 
class  DeadlineExceededError
 
class  ErrorWithStatus
 Error with grpc::Status details. More...
 
class  FailedPreconditionError
 
class  GenericClient
 Allows to talk to gRPC services (generic and normal) using dynamic method names. More...
 
struct  GenericOptions
 
struct  GlobalQos
 
class  InputStream
 Controls a single request -> response stream RPC. More...
 
class  InternalError
 
class  InvalidArgumentError
 
class  MiddlewareBase
 Base class for client gRPC middleware. More...
 
class  MiddlewareCallContext
 Context for middleware-specific data during gRPC call. More...
 
class  MiddlewarePipelineComponent
 Component to create middlewares pipeline. More...
 
class  NotFoundError
 
class  OutOfRangeError
 
class  OutputStream
 Controls a request stream -> single response RPC. More...
 
class  PermissionDeniedError
 
struct  Qos
 Per-RPC quality-of-service config. Taken from ugrpc::client::ClientQos. Can also be passed to ugrpc client methods manually. More...
 
class  ResourceExhaustedError
 
class  ResponseFuture
 Controls a single request -> single response RPC. More...
 
class  RpcCancelledError
 RPC failed due to task cancellation. More...
 
class  RpcError
 Error during an RPC. More...
 
class  RpcInterruptedError
 RPC failed without a status. This means that either the call got cancelled using TryCancel, the deadline has expired, or the channel is broken. More...
 
class  SimpleClientComponent
 Template class for a simple gRPC client. More...
 
class  StreamReadFuture
 StreamReadFuture for waiting a single read response from stream. More...
 
class  UnauthenticatedError
 
class  UnavailableError
 
class  UnimplementedError
 
class  UnknownError
 

Typedefs

using MiddlewareFactoryComponentBase
 Factory that creates specific client middlewares for clients.
 
template<typename Middleware>
using SimpleMiddlewareFactoryComponent
 The alias for a short-cut client factory.
 
using DedicatedMethodsConfig = std::unordered_map<std::string, std::size_t>
 
using Middlewares = std::vector<std::shared_ptr<const MiddlewareBase>>
 A chain of middlewares.
 

Functions

void ThrowErrorWithStatus (std::string_view call_name, grpc::Status &&status)
 
std::shared_ptr< grpc::Channel > MakeChannel (engine::TaskProcessor &blocking_task_processor, std::shared_ptr< grpc::ChannelCredentials > channel_credentials, const std::string &endpoint)
 Create a new gRPC channel (connection pool) for the endpoint.
 
template<typename Client>
bool TryWaitForConnected (Client &client, engine::Deadline deadline, engine::TaskProcessor &blocking_task_processor)
 Wait until the channel state of client is READY. If the current state is already READY, returns true immediately. In case of multiple underlying channels, waits for all of them.
 
std::shared_ptr< grpc::ChannelCredentials > GetClientCredentials (const ClientFactorySettings &client_factory_settings, const std::string &client_name)
 
bool operator== (const GlobalQos &lhs, const GlobalQos &rhs) noexcept
 
GlobalQos Parse (const formats::json::Value &value, formats::parse::To< GlobalQos >)
 
formats::json::Value Serialize (const GlobalQos &, formats::serialize::To< formats::json::Value >)
 
bool operator== (const ClientQos &lhs, const ClientQos &rhs) noexcept
 
ClientQos Parse (const formats::json::Value &value, formats::parse::To< ClientQos >)
 
formats::json::Value Serialize (const ClientQos &client_qos, formats::serialize::To< formats::json::Value >)
 
std::size_t GetMethodChannelCount (const DedicatedMethodsConfig &dedicated_methods_config, std::string_view method_name)
 
components::ComponentList MinimalComponentList ()
 Returns a list of components to do a minimal grpc client configuration.
 
components::ComponentList DefaultComponentList ()
 Returns a list of components to do a default grpc client configuration.
 
template<typename Response>
std::optional< std::size_t > ReadRemainingAndFinish (InputStream< Response > &stream) noexcept
 Read all remaining messages from the stream and call Finish.
 
template<typename Request, typename Response>
std::optional< std::size_t > ReadRemainingAndFinish (BidirectionalStream< Request, Response > &stream) noexcept
 Announce end-of-input to the server, read all remaining messages from the stream and call Finish.
 
template<typename Request, typename Response>
bool PingPongFinish (BidirectionalStream< Request, Response > &stream) noexcept
 Gracefully finish a ping-pong style interaction.
 
bool operator== (const Qos &lhs, const Qos &rhs) noexcept
 
Qos Parse (const formats::json::Value &value, formats::parse::To< Qos >)
 
formats::json::Value Serialize (const Qos &qos, formats::serialize::To< formats::json::Value >)
 
std::optional< std::uint32_t > GetAttempts (const Qos &qos)
 
std::optional< std::chrono::milliseconds > GetTotalTimeout (const Qos &qos)
 

Typedef Documentation

◆ DedicatedMethodsConfig

using ugrpc::client::DedicatedMethodsConfig = std::unordered_map<std::string, std::size_t>

Definition at line 19 of file client_settings.hpp.

◆ Middlewares

using ugrpc::client::Middlewares = std::vector<std::shared_ptr<const MiddlewareBase>>

A chain of middlewares.

Definition at line 16 of file fwd.hpp.

Function Documentation

◆ MakeChannel()

std::shared_ptr< grpc::Channel > ugrpc::client::MakeChannel ( engine::TaskProcessor & blocking_task_processor,
std::shared_ptr< grpc::ChannelCredentials > channel_credentials,
const std::string & endpoint )

Create a new gRPC channel (connection pool) for the endpoint.

Channel creation is expensive, reuse channels if possible.

Each channel is fully thread-safe: it can be used across multiple threads, possibly from multiple clients and using multiple CompletionQueue instances at the same time.

Parameters
blocking_task_processortask processor for blocking channel creation
channel_credentialschannel credentials
endpointstring host:port
Returns
shared pointer to the gRPC channel

◆ PingPongFinish()

template<typename Request, typename Response>
bool ugrpc::client::PingPongFinish ( BidirectionalStream< Request, Response > & stream)
nodiscardnoexcept

Gracefully finish a ping-pong style interaction.

  1. Announces end-of-output to the server
  2. Ensures there are no more messages to read
Warning
The method will hang indefenitely if the stream is never interrupted or closed by the server
Returns
true if the operation was successful; false if there are more messages in the stream to read or if the operation failed (i.e. due to task cancellation, the stream being already closed for writes, or the server returning an error status)

Definition at line 63 of file graceful_stream_finish.hpp.

◆ ReadRemainingAndFinish() [1/2]

template<typename Request, typename Response>
std::optional< std::size_t > ugrpc::client::ReadRemainingAndFinish ( BidirectionalStream< Request, Response > & stream)
noexcept

Announce end-of-input to the server, read all remaining messages from the stream and call Finish.

Warning
The method will hang indefenitely if the stream is never interrupted or closed by the server
Returns
the number of messages received from the stream; nullopt if the operation failed (i.e. due to task cancellation, the stream being already closed for either reads or writes, or the server returning an error status)

Definition at line 43 of file graceful_stream_finish.hpp.

◆ ReadRemainingAndFinish() [2/2]

template<typename Response>
std::optional< std::size_t > ugrpc::client::ReadRemainingAndFinish ( InputStream< Response > & stream)
noexcept

Read all remaining messages from the stream and call Finish.

Warning
The method will hang indefenitely if the stream is never interrupted or closed by the server
Returns
the number of messages received from the stream; nullopt if the operation failed (i.e. due to task cancellation, the stream being already closed for reads, or the server returning an error status)

Definition at line 28 of file graceful_stream_finish.hpp.

◆ TryWaitForConnected()

template<typename Client>
bool ugrpc::client::TryWaitForConnected ( Client & client,
engine::Deadline deadline,
engine::TaskProcessor & blocking_task_processor )
nodiscard

Wait until the channel state of client is READY. If the current state is already READY, returns true immediately. In case of multiple underlying channels, waits for all of them.

Returns
true if the state changed before deadline expired
Note
The wait operation does not support task cancellations

Definition at line 50 of file channels.hpp.