8#include <grpcpp/completion_queue.h>
9#include <grpcpp/security/credentials.h>
10#include <grpcpp/support/channel_arguments.h>
12#include <userver/dynamic_config/source.hpp>
13#include <userver/engine/task/task_processor_fwd.hpp>
14#include <userver/logging/level.hpp>
15#include <userver/testsuite/grpc_control.hpp>
16#include <userver/utils/statistics/fwd.hpp>
17#include <userver/yaml_config/fwd.hpp>
19#include <userver/ugrpc/client/impl/channel_cache.hpp>
20#include <userver/ugrpc/client/impl/client_data.hpp>
21#include <userver/ugrpc/client/middlewares/base.hpp>
22#include <userver/ugrpc/impl/statistics_storage.hpp>
24USERVER_NAMESPACE_BEGIN
53class ClientFactory
final {
56 engine::TaskProcessor& channel_task_processor,
57 MiddlewareFactories mws, grpc::CompletionQueue& queue,
58 utils::statistics::Storage& statistics_storage,
60 dynamic_config::Source source);
62 template <
typename Client>
63 Client MakeClient(
const std::string& client_name,
64 const std::string& endpoint);
67 impl::ChannelCache::Token GetChannel(
const std::string& endpoint);
69 engine::TaskProcessor& channel_task_processor_;
70 MiddlewareFactories mws_;
71 grpc::CompletionQueue& queue_;
72 impl::ChannelCache channel_cache_;
73 ugrpc::impl::StatisticsStorage client_statistics_storage_;
74 const dynamic_config::Source config_source_;
78template <
typename Client>
79Client ClientFactory::MakeClient(
const std::string& client_name,
80 const std::string& endpoint) {
82 client_statistics_storage_.GetServiceStatistics(Client::GetMetadata());
85 mws.reserve(mws_.size());
86 for (
const auto& mw_factory : mws_)
87 mws.push_back(mw_factory->GetMiddleware(client_name));
89 return Client(impl::ClientParams{client_name, std::move(mws), queue_,
90 statistics, GetChannel(endpoint),
91 config_source_, testsuite_grpc_});