userver: userver/urabbitmq/broker_interface.hpp Source File
Loading...
Searching...
No Matches
broker_interface.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/urabbitmq/broker_interface.hpp
4/// @brief A bunch of interface classes
5
6#include <string>
7
8#include <userver/engine/deadline.hpp>
9#include <userver/utils/flags.hpp>
10
11#include <userver/urabbitmq/typedefs.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace urabbitmq {
16
17/// @brief Administrative interface for the broker.
18/// This class is merely an interface for convenience and you are not expected
19/// to use it directly (use `Client`/`AdminChannel` instead).
21public:
22 /// @brief Declare an exchange.
23 ///
24 /// @param exchange name of the exchange
25 /// @param type exchange type
26 /// @param flags exchange flags
27 /// @param deadline execution deadline
28 virtual void DeclareExchange(
29 const Exchange& exchange,
30 Exchange::Type type,
31 utils::Flags<Exchange::Flags> flags,
32 engine::Deadline deadline
33 ) = 0;
34
35 /// @brief overload of DeclareExchange
36 virtual void DeclareExchange(const Exchange& exchange, Exchange::Type type, engine::Deadline deadline) = 0;
37
38 /// @brief overload of DeclareExchange
39 virtual void DeclareExchange(const Exchange& exchange, engine::Deadline deadline) = 0;
40
41 /// @brief Declare a queue.
42 ///
43 /// @param queue name of the queue
44 /// @param flags queue flags
45 /// @param deadline execution deadline
46 virtual void DeclareQueue(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) = 0;
47
48 /// @brief overload of DeclareQueue
49 virtual void DeclareQueue(const Queue& queue, engine::Deadline deadline) = 0;
50
51 /// @brief Bind a queue to an exchange.
52 ///
53 /// @param exchange the source exchange
54 /// @param queue the target queue
55 /// @param routing_key the routing key
56 /// @param deadline execution deadline
57 virtual void BindQueue(
58 const Exchange& exchange,
59 const Queue& queue,
60 const std::string& routing_key,
61 engine::Deadline deadline
62 ) = 0;
63
64 /// @brief Remove an exchange.
65 ///
66 /// @param exchange name of the exchange to remove
67 /// @param deadline execution deadline
68 virtual void RemoveExchange(const Exchange& exchange, engine::Deadline deadline) = 0;
69
70 /// @brief Remove a queue.
71 ///
72 /// @param queue name of the queue to remove
73 /// @param deadline execution deadline
74 virtual void RemoveQueue(const Queue& queue, engine::Deadline deadline) = 0;
75
76protected:
77 ~IAdminInterface();
78};
79
80/// @brief Publisher interface for the broker.
81/// This class is merely an interface for convenience and you are not expected
82/// to use it directly (use `Client`/`Channel` instead).
84public:
85 /// @brief Publish a message to an exchange
86 ///
87 /// You have to supply the name of the exchange and a routing key. RabbitMQ
88 /// will then try to send the message to one or more queues.
89 /// By default, unroutable messages are silently discarded
90 ///
91 /// @param exchange the exchange to publish to
92 /// @param routing_key the routing key
93 /// @param message the message to send
94 /// @param type see @ref MessageType
95 /// @param deadline execution deadline
96 ///
97 /// @note This method is `fire and forget` (no delivery guarantees),
98 /// use `PublishReliable` for delivery guarantees.
99 virtual void Publish(
100 const Exchange& exchange,
101 const std::string& routing_key,
102 const std::string& message,
103 MessageType type,
104 engine::Deadline deadline
105 ) = 0;
106
107 /// @brief overload of Publish
108 virtual void Publish(
109 const Exchange& exchange,
110 const std::string& routing_key,
111 const std::string& message,
112 engine::Deadline deadline
113 ) = 0;
114
115 /// @brief overload of Publish
116 virtual void Publish(
117 const Exchange& exchange,
118 const std::string& routing_key,
119 const Envelope& envelope,
120 engine::Deadline deadline
121 ) = 0;
122
123 /// @brief Gets a single message.
124 ///
125 /// You should to set `kNoAck` flag in order for server to implicitly
126 /// acknowledge gathered message.
127 /// By default, the gathered message has to be explicitly acknowledged
128 /// or rejected, however there's no functionality for that yet, so the flag is
129 /// basically mandatory.
130 /// This API is a subject to change.
131 ///
132 /// @note This method uses a polling model for retrieving a message, which is
133 /// comparatively expensive and might lead to a connection reset in case of a
134 /// timeout. This method could come in handy in some cases, but in general we
135 /// recommend to set up a `Consumer` instead.
136 ///
137 /// @param queue name of the queue
138 /// @param flags queue flags
139 /// @param deadline execution deadline
140 virtual std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) = 0;
141
142protected:
143 ~IChannelInterface();
144};
145
146/// @brief Reliable publisher interface for the broker.
147/// This class is merely an interface for convenience and you are not expected
148/// to use it directly (use `Client`/`ReliableChannel` instead).
150public:
151 /// @brief Publish a message to an exchange and
152 /// await confirmation from the broker
153 ///
154 /// You have to supply the name of the exchange and a routing key. RabbitMQ
155 /// will then try to send the message to one or more queues.
156 /// By default, unroutable messages are silently discarded
157 ///
158 /// @param exchange the exchange to publish to
159 /// @param routing_key the routing key
160 /// @param message the message to send
161 /// @param type see @ref MessageType
162 /// @param deadline execution deadline
163 virtual void PublishReliable(
164 const Exchange& exchange,
165 const std::string& routing_key,
166 const std::string& message,
167 MessageType type,
168 engine::Deadline deadline
169 ) = 0;
170
171 /// @brief overload of PublishReliable
172 virtual void PublishReliable(
173 const Exchange& exchange,
174 const std::string& routing_key,
175 const std::string& message,
176 engine::Deadline deadline
177 ) = 0;
178
179 /// @brief overload of PublishReliable
180 virtual void PublishReliable(
181 const Exchange& exchange,
182 const std::string& routing_key,
183 const Envelope& envelope,
184 engine::Deadline deadline
185 ) = 0;
186
187protected:
188 ~IReliableChannelInterface();
189};
190
191} // namespace urabbitmq
192
193USERVER_NAMESPACE_END