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/storages/secdist/secdist.hpp>
16#include <userver/testsuite/grpc_control.hpp>
17#include <userver/utils/statistics/fwd.hpp>
18#include <userver/yaml_config/fwd.hpp>
20#include <userver/ugrpc/client/impl/channel_cache.hpp>
21#include <userver/ugrpc/client/impl/client_data.hpp>
22#include <userver/ugrpc/client/middlewares/base.hpp>
23#include <userver/ugrpc/impl/statistics_storage.hpp>
25USERVER_NAMESPACE_BEGIN
30struct ClientFactorySettings
final {
33 grpc::InsecureChannelCredentials()};
56class ClientFactory
final {
58 ClientFactory(ClientFactorySettings&& settings,
59 engine::TaskProcessor& channel_task_processor,
60 MiddlewareFactories mws, grpc::CompletionQueue& queue,
61 utils::statistics::Storage& statistics_storage,
63 dynamic_config::Source source);
65 template <
typename Client>
66 Client MakeClient(
const std::string& client_name,
67 const std::string& endpoint);
70 impl::ChannelCache::Token GetChannel(
const std::string& client_name,
71 const std::string& endpoint);
73 engine::TaskProcessor& channel_task_processor_;
74 MiddlewareFactories mws_;
75 grpc::CompletionQueue& queue_;
76 impl::ChannelCache channel_cache_;
77 std::unordered_map<std::string, std::unique_ptr<impl::ChannelCache>>
78 client_channel_cache_;
79 ugrpc::impl::StatisticsStorage client_statistics_storage_;
80 const dynamic_config::Source config_source_;
84template <
typename Client>
85Client ClientFactory::MakeClient(
const std::string& client_name,
86 const std::string& endpoint) {
88 client_statistics_storage_.GetServiceStatistics(Client::GetMetadata());
91 mws.reserve(mws_.size());
92 for (
const auto& mw_factory : mws_)
93 mws.push_back(mw_factory->GetMiddleware(client_name));
95 return Client(impl::ClientParams{
96 client_name, std::move(mws), queue_, statistics,
97 GetChannel(client_name, endpoint), config_source_, testsuite_grpc_});