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 : public std::enable_shared_from_this<Client>,
29 public IAdminInterface,
30 public IChannelInterface,
32public:
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, const ClientSettings& settings);
37 /// Client destructor
39
41 const Exchange& exchange,
42 Exchange::Type type,
43 utils::Flags<Exchange::Flags> flags,
44 engine::Deadline deadline
45 ) override;
46
47 void DeclareExchange(const Exchange& exchange, Exchange::Type type, engine::Deadline deadline) override {
48 DeclareExchange(exchange, type, {}, deadline);
49 }
50
51 void DeclareExchange(const Exchange& exchange, engine::Deadline deadline) override {
52 DeclareExchange(exchange, Exchange::Type::kFanOut, {}, deadline);
53 }
54
55 void DeclareQueue(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) override;
56
57 void DeclareQueue(const Queue& queue, engine::Deadline deadline) override { DeclareQueue(queue, {}, deadline); }
58
60 const Exchange& exchange,
61 const Queue& queue,
62 const std::string& routing_key,
63 engine::Deadline deadline
64 ) override;
65
66 void RemoveExchange(const Exchange& exchange, engine::Deadline deadline) override;
67
68 void RemoveQueue(const Queue& queue, engine::Deadline deadline) override;
69
70 /// @brief Get an administrative interface for the broker.
71 ///
72 /// @param deadline deadline for connection acquisition from the pool
73 AdminChannel GetAdminChannel(engine::Deadline deadline);
74
75 void Publish(
76 const Exchange& exchange,
77 const std::string& routing_key,
78 const std::string& message,
79 MessageType type,
80 engine::Deadline deadline
81 ) override {
82 Publish(exchange, routing_key, Envelope{message, type, {}, {}, {}}, deadline);
83 };
84
85 void Publish(
86 const Exchange& exchange,
87 const std::string& routing_key,
88 const std::string& message,
89 engine::Deadline deadline
90 ) override {
91 Publish(exchange, routing_key, message, MessageType::kTransient, deadline);
92 };
93
94 void Publish(
95 const Exchange& exchange,
96 const std::string& routing_key,
97 const Envelope& envelope,
98 engine::Deadline deadline
99 ) override;
100
101 std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) override;
102
103 /// @brief Get a publisher interface for the broker.
104 ///
105 /// @param deadline deadline for connection acquisition from the pool
106 Channel GetChannel(engine::Deadline deadline);
107
109 const Exchange& exchange,
110 const std::string& routing_key,
111 const std::string& message,
112 MessageType type,
113 engine::Deadline deadline
114 ) override {
115 PublishReliable(exchange, routing_key, Envelope{message, type, {}, {}, {}}, deadline);
116 }
117
119 const Exchange& exchange,
120 const std::string& routing_key,
121 const std::string& message,
122 engine::Deadline deadline
123 ) override {
124 PublishReliable(exchange, routing_key, message, MessageType::kTransient, deadline);
125 }
126
128 const Exchange& exchange,
129 const std::string& routing_key,
130 const Envelope& envelope,
131 engine::Deadline deadline
132 ) override;
133
134 /// @brief Get a reliable publisher interface for the broker
135 /// (publisher-confirms)
136 ///
137 /// @param deadline deadline for connection acquisition from the pool
138 ReliableChannel GetReliableChannel(engine::Deadline deadline);
139
140 /// Write cluster statistics
141 void WriteStatistics(utils::statistics::Writer& writer) const;
142
143protected:
144 Client(clients::dns::Resolver& resolver, const ClientSettings& settings);
145
146private:
147 friend class ConsumerBase;
148 utils::FastPimpl<ClientImpl, 296, 8> impl_;
149};
150
151} // namespace urabbitmq
152
153USERVER_NAMESPACE_END