userver: userver/urabbitmq/channel.hpp Source File
Loading...
Searching...
No Matches
channel.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/urabbitmq/channel.hpp
4/// @brief Publisher interface for the broker.
5
6#include <memory>
7
8#include <userver/utils/fast_pimpl.hpp>
9
10#include <userver/urabbitmq/broker_interface.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace urabbitmq {
15
16class ConnectionPtr;
17
18/// @brief Publisher interface for the broker.
19/// You may use this class to publish your messages.
20///
21/// You may as well use `Client` itself instead, this class just gives you
22/// some order guaranties.
23///
24/// You are not expected to store this class for a long time, because it takes
25/// a connection from the underlying connections pool.
26///
27/// Usually retrieved from `Client`.
28class Channel final : IChannelInterface {
29public:
30 Channel(ConnectionPtr&& channel);
31 ~Channel();
32
33 Channel(Channel&& other) noexcept;
34
35 void Publish(
36 const Exchange& exchange,
37 const std::string& routing_key,
38 const std::string& message,
39 MessageType type,
40 engine::Deadline deadline
41 ) override;
42
43 void Publish(
44 const Exchange& exchange,
45 const std::string& routing_key,
46 const std::string& message,
47 engine::Deadline deadline
48 ) override {
49 Publish(exchange, routing_key, message, MessageType::kTransient, deadline);
50 };
51
52 std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) override;
53
54private:
55 utils::FastPimpl<ConnectionPtr, 32, 8> impl_;
56};
57
58/// @brief Reliable publisher interface for the broker.
59/// You may use this class to reliably publish your messages
60/// (publisher-confirms).
61///
62/// You may as well use `Client` itself instead, this class gives no additional
63/// benefits and is present merely for convenience.
64///
65/// You are not expected to store this class for a long time, because it takes
66/// a connection from the underlying connections pool.
67///
68/// Usually retrieved from `Client`.
69class ReliableChannel final : IReliableChannelInterface {
70public:
71 ReliableChannel(ConnectionPtr&& channel);
72 ~ReliableChannel();
73
74 ReliableChannel(ReliableChannel&& other) noexcept;
75
77 const Exchange& exchange,
78 const std::string& routing_key,
79 const std::string& message,
80 MessageType type,
81 engine::Deadline deadline
82 ) override;
83
85 const Exchange& exchange,
86 const std::string& routing_key,
87 const std::string& message,
88 engine::Deadline deadline
89 ) override {
90 PublishReliable(exchange, routing_key, message, MessageType::kTransient, deadline);
91 }
92
93private:
94 utils::FastPimpl<ConnectionPtr, 32, 8> impl_;
95};
96
97} // namespace urabbitmq
98
99USERVER_NAMESPACE_END