userver: userver/urabbitmq/broker_interface.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 Gets a single message.
116 ///
117 /// You should to set `kNoAck` flag in order for server to implicitly
118 /// acknowledge gathered message.
119 /// By default, the gathered message has to be explicitly acknowledged
120 /// or rejected, however there's no functionality for that yet, so the flag is
121 /// basically mandatory.
122 /// This API is a subject to change.
123 ///
124 /// @note This method uses a polling model for retrieving a message, which is
125 /// comparatively expensive and might lead to a connection reset in case of a
126 /// timeout. This method could come in handy in some cases, but in general we
127 /// recommend to set up a `Consumer` instead.
128 ///
129 /// @param queue name of the queue
130 /// @param flags queue flags
131 /// @param deadline execution deadline
132 virtual std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) = 0;
133
134protected:
135 ~IChannelInterface();
136};
137
138/// @brief Reliable publisher interface for the broker.
139/// This class is merely an interface for convenience and you are not expected
140/// to use it directly (use `Client`/`ReliableChannel` instead).
142public:
143 /// @brief Publish a message to an exchange and
144 /// await confirmation from the broker
145 ///
146 /// You have to supply the name of the exchange and a routing key. RabbitMQ
147 /// will then try to send the message to one or more queues.
148 /// By default, unroutable messages are silently discarded
149 ///
150 /// @param exchange the exchange to publish to
151 /// @param routing_key the routing key
152 /// @param message the message to send
153 /// @param type see @ref MessageType
154 /// @param deadline execution deadline
155 virtual void PublishReliable(
156 const Exchange& exchange,
157 const std::string& routing_key,
158 const std::string& message,
159 MessageType type,
160 engine::Deadline deadline
161 ) = 0;
162
163 /// @brief overload of PublishReliable
164 virtual void PublishReliable(
165 const Exchange& exchange,
166 const std::string& routing_key,
167 const std::string& message,
168 engine::Deadline deadline
169 ) = 0;
170
171protected:
172 ~IReliableChannelInterface();
173};
174
175} // namespace urabbitmq
176
177USERVER_NAMESPACE_END