userver: userver/urabbitmq/client.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
client.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/urabbitmq/client.hpp
4/// @brief @copybrief urabbitmq::Client
5
6#include <memory>
7
8#include <userver/clients/dns/resolver_fwd.hpp>
9#include <userver/utils/fast_pimpl.hpp>
10#include <userver/utils/statistics/writer.hpp>
11
12#include <userver/rabbitmq_fwd.hpp>
13#include <userver/urabbitmq/broker_interface.hpp>
14#include <userver/urabbitmq/client_settings.hpp>
15
16USERVER_NAMESPACE_BEGIN
17
18namespace urabbitmq {
19
20class ConsumerBase;
21class ClientImpl;
22
23/// @ingroup userver_clients
24///
25/// @brief Interface for communicating with a RabbitMQ cluster.
26///
27/// Usually retrieved from components::RabbitMQ component.
29 public IAdminInterface,
30 public IChannelInterface,
32 public:
33 /// Client factory function
34 /// @param resolver asynchronous DNS resolver
35 /// @param settings client settings
36 static std::shared_ptr<Client> Create(clients::dns::Resolver& resolver,
37 const ClientSettings& settings);
38 /// Client destructor
40
41 void DeclareExchange(const Exchange& exchange, Exchange::Type type,
42 utils::Flags<Exchange::Flags> flags,
43 engine::Deadline deadline) override;
44
45 void DeclareExchange(const Exchange& exchange, Exchange::Type type,
46 engine::Deadline deadline) override {
47 DeclareExchange(exchange, type, {}, deadline);
48 }
49
50 void DeclareExchange(const Exchange& exchange,
51 engine::Deadline deadline) override {
52 DeclareExchange(exchange, Exchange::Type::kFanOut, {}, deadline);
53 }
54
55 void DeclareQueue(const Queue& queue, utils::Flags<Queue::Flags> flags,
56 engine::Deadline deadline) override;
57
58 void DeclareQueue(const Queue& queue, engine::Deadline deadline) override {
59 DeclareQueue(queue, {}, deadline);
60 }
61
62 void BindQueue(const Exchange& exchange, const Queue& queue,
63 const std::string& routing_key,
64 engine::Deadline deadline) override;
65
66 void RemoveExchange(const Exchange& exchange,
67 engine::Deadline deadline) override;
68
69 void RemoveQueue(const Queue& queue, engine::Deadline deadline) override;
70
71 /// @brief Get an administrative interface for the broker.
72 ///
73 /// @param deadline deadline for connection acquisition from the pool
74 AdminChannel GetAdminChannel(engine::Deadline deadline);
75
76 void Publish(const Exchange& exchange, const std::string& routing_key,
77 const std::string& message, MessageType type,
78 engine::Deadline deadline) override;
79
80 void Publish(const Exchange& exchange, const std::string& routing_key,
81 const std::string& message, engine::Deadline deadline) override {
82 Publish(exchange, routing_key, message, MessageType::kTransient, deadline);
83 };
84
85 /// @brief Get a publisher interface for the broker.
86 ///
87 /// @param deadline deadline for connection acquisition from the pool
88 Channel GetChannel(engine::Deadline deadline);
89
90 void PublishReliable(const Exchange& exchange, const std::string& routing_key,
91 const std::string& message, MessageType type,
92 engine::Deadline deadline) override;
93
94 void PublishReliable(const Exchange& exchange, const std::string& routing_key,
95 const std::string& message,
96 engine::Deadline deadline) override {
97 PublishReliable(exchange, routing_key, message, MessageType::kTransient,
98 deadline);
99 }
100
101 /// @brief Get a reliable publisher interface for the broker
102 /// (publisher-confirms)
103 ///
104 /// @param deadline deadline for connection acquisition from the pool
105 ReliableChannel GetReliableChannel(engine::Deadline deadline);
106
107 /// Write cluster statistics
108 void WriteStatistics(utils::statistics::Writer& writer) const;
109
110 protected:
111 Client(clients::dns::Resolver& resolver, const ClientSettings& settings);
112
113 private:
114 friend class ConsumerBase;
115 utils::FastPimpl<ClientImpl, 232, 8> impl_;
116};
117
118} // namespace urabbitmq
119
120USERVER_NAMESPACE_END