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).
21 public:
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(const Exchange& exchange, Exchange::Type type,
29 utils::Flags<Exchange::Flags> flags,
30 engine::Deadline deadline) = 0;
31
32 /// @brief overload of DeclareExchange
33 virtual void DeclareExchange(const Exchange& exchange, Exchange::Type type,
34 engine::Deadline deadline) = 0;
35
36 /// @brief overload of DeclareExchange
37 virtual void DeclareExchange(const Exchange& exchange,
38 engine::Deadline deadline) = 0;
39
40 /// @brief Declare a queue.
41 ///
42 /// @param queue name of the queue
43 /// @param flags queue flags
44 /// @param deadline execution deadline
45 virtual void DeclareQueue(const Queue& queue,
46 utils::Flags<Queue::Flags> flags,
47 engine::Deadline deadline) = 0;
48
49 /// @brief overload of DeclareQueue
50 virtual void DeclareQueue(const Queue& queue, engine::Deadline deadline) = 0;
51
52 /// @brief Bind a queue to an exchange.
53 ///
54 /// @param exchange the source exchange
55 /// @param queue the target queue
56 /// @param routing_key the routing key
57 /// @param deadline execution deadline
58 virtual void BindQueue(const Exchange& exchange, const Queue& queue,
59 const std::string& routing_key,
60 engine::Deadline deadline) = 0;
61
62 /// @brief Remove an exchange.
63 ///
64 /// @param exchange name of the exchange to remove
65 /// @param deadline execution deadline
66 virtual void RemoveExchange(const Exchange& exchange,
67 engine::Deadline deadline) = 0;
68
69 /// @brief Remove a queue.
70 ///
71 /// @param queue name of the queue to remove
72 /// @param deadline execution deadline
73 virtual void RemoveQueue(const Queue& queue, engine::Deadline deadline) = 0;
74
75 protected:
76 ~IAdminInterface();
77};
78
79/// @brief Publisher interface for the broker.
80/// This class is merely an interface for convenience and you are not expected
81/// to use it directly (use `Client`/`Channel` instead).
83 public:
84 /// @brief Publish a message to an exchange
85 ///
86 /// You have to supply the name of the exchange and a routing key. RabbitMQ
87 /// will then try to send the message to one or more queues.
88 /// By default unroutable messages are silently discarded
89 ///
90 /// @param exchange the exchange to publish to
91 /// @param routing_key the routing key
92 /// @param message the message to send
93 /// @param deadline execution deadline
94 ///
95 /// @note This method is `fire and forget` (no delivery guarantees),
96 /// use `PublishReliable` for delivery guarantees.
97 virtual void Publish(const Exchange& exchange, const std::string& routing_key,
98 const std::string& message, MessageType type,
99 engine::Deadline deadline) = 0;
100
101 /// @brief overload of Publish
102 virtual void Publish(const Exchange& exchange, const std::string& routing_key,
103 const std::string& message,
104 engine::Deadline deadline) = 0;
105
106 /// @brief Gets a single message.
107 ///
108 /// You should to set `kNoAck` flag in order for server to implicitly
109 /// acknowledge gathered message.
110 /// By default the gathered message has to be explicitly acknowledged
111 /// or rejected, however there's no functionality for that yet, so the flag is
112 /// basically mandatory.
113 /// This API is a subject to change.
114 ///
115 /// @note This method uses a polling model for retrieving a message, which is
116 /// comparatively expensive and might lead to a connection reset in case of a
117 /// timeout. This method could come in handy in some cases, but in general we
118 /// recommend to set up a `Consumer` instead.
119 ///
120 /// @param queue name of the queue
121 /// @param flags queue flags
122 /// @param deadline execution deadline
123 virtual std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags,
124 engine::Deadline deadline) = 0;
125
126 protected:
127 ~IChannelInterface();
128};
129
130/// @brief Reliable publisher interface for the broker.
131/// This class is merely an interface for convenience and you are not expected
132/// to use it directly (use `Client`/`ReliableChannel` instead).
134 public:
135 /// @brief Publish a message to an exchange and
136 /// await confirmation from the broker
137 ///
138 /// You have to supply the name of the exchange and a routing key. RabbitMQ
139 /// will then try to send the message to one or more queues.
140 /// By default unroutable messages are silently discarded
141 ///
142 /// @param exchange the exchange to publish to
143 /// @param routing_key the routing key
144 /// @param message the message to send
145 /// @param deadline execution deadline
146 virtual void PublishReliable(const Exchange& exchange,
147 const std::string& routing_key,
148 const std::string& message, MessageType type,
149 engine::Deadline deadline) = 0;
150
151 /// @brief overload of PublishReliable
152 virtual void PublishReliable(const Exchange& exchange,
153 const std::string& routing_key,
154 const std::string& message,
155 engine::Deadline deadline) = 0;
156
157 protected:
158 ~IReliableChannelInterface();
159};
160
161} // namespace urabbitmq
162
163USERVER_NAMESPACE_END