userver: userver/urabbitmq/client.hpp Source File
Loading...
Searching...
No Matches
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.
28class Client
29 : public std::enable_shared_from_this<Client>,
30 public IAdminInterface,
31 public IChannelInterface,
33public:
34 /// Client factory function
35 /// @param resolver asynchronous DNS resolver
36 /// @param settings client settings
37 static std::shared_ptr<Client> Create(clients::dns::Resolver& resolver, const ClientSettings& settings);
38 /// Client destructor
40
42 const Exchange& exchange,
43 Exchange::Type type,
44 utils::Flags<Exchange::Flags> flags,
45 engine::Deadline deadline
46 ) override;
47
48 void DeclareExchange(const Exchange& exchange, Exchange::Type type, engine::Deadline deadline) override {
49 DeclareExchange(exchange, type, {}, deadline);
50 }
51
52 void DeclareExchange(const Exchange& exchange, engine::Deadline deadline) override {
53 DeclareExchange(exchange, Exchange::Type::kFanOut, {}, deadline);
54 }
55
56 void DeclareQueue(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) override;
57
58 void DeclareQueue(const Queue& queue, engine::Deadline deadline) override { DeclareQueue(queue, {}, deadline); }
59
61 const Exchange& exchange,
62 const Queue& queue,
63 const std::string& routing_key,
64 engine::Deadline deadline
65 ) override;
66
67 void RemoveExchange(const Exchange& exchange, 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(
77 const Exchange& exchange,
78 const std::string& routing_key,
79 const std::string& message,
80 MessageType type,
81 engine::Deadline deadline
82 ) override {
83 Publish(exchange, routing_key, Envelope{message, type, {}, {}, {}}, deadline);
84 };
85
86 void Publish(
87 const Exchange& exchange,
88 const std::string& routing_key,
89 const std::string& message,
90 engine::Deadline deadline
91 ) override {
92 Publish(exchange, routing_key, message, MessageType::kTransient, deadline);
93 };
94
95 void Publish(
96 const Exchange& exchange,
97 const std::string& routing_key,
98 const Envelope& envelope,
99 engine::Deadline deadline
100 ) override;
101
102 std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) override;
103
104 /// @brief Get a publisher interface for the broker.
105 ///
106 /// @param deadline deadline for connection acquisition from the pool
107 Channel GetChannel(engine::Deadline deadline);
108
110 const Exchange& exchange,
111 const std::string& routing_key,
112 const std::string& message,
113 MessageType type,
114 engine::Deadline deadline
115 ) override {
116 PublishReliable(exchange, routing_key, Envelope{message, type, {}, {}, {}}, deadline);
117 }
118
120 const Exchange& exchange,
121 const std::string& routing_key,
122 const std::string& message,
123 engine::Deadline deadline
124 ) override {
125 PublishReliable(exchange, routing_key, message, MessageType::kTransient, deadline);
126 }
127
129 const Exchange& exchange,
130 const std::string& routing_key,
131 const Envelope& envelope,
132 engine::Deadline deadline
133 ) override;
134
135 /// @brief Get a reliable publisher interface for the broker
136 /// (publisher-confirms)
137 ///
138 /// @param deadline deadline for connection acquisition from the pool
139 ReliableChannel GetReliableChannel(engine::Deadline deadline);
140
141 /// Write cluster statistics
142 void WriteStatistics(utils::statistics::Writer& writer) const;
143
144protected:
145 Client(clients::dns::Resolver& resolver, const ClientSettings& settings);
146
147private:
148 friend class ConsumerBase;
149 utils::FastPimpl<ClientImpl, 296, 8> impl_;
150};
151
152} // namespace urabbitmq
153
154USERVER_NAMESPACE_END