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