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 {
29 public:
30 Channel(ConnectionPtr&& channel);
31 ~Channel();
32
33 Channel(Channel&& other) noexcept;
34
35 void Publish(const Exchange& exchange, const std::string& routing_key,
36 const std::string& message, MessageType type,
37 engine::Deadline deadline) override;
38
39 void Publish(const Exchange& exchange, const std::string& routing_key,
40 const std::string& message, engine::Deadline deadline) override {
41 Publish(exchange, routing_key, message, MessageType::kTransient, deadline);
42 };
43
44 std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags,
45 engine::Deadline deadline) override;
46
47 private:
48 utils::FastPimpl<ConnectionPtr, 32, 8> impl_;
49};
50
51/// @brief Reliable publisher interface for the broker.
52/// You may use this class to reliably publish your messages
53/// (publisher-confirms).
54///
55/// You may as well use `Client` itself instead, this class gives no additional
56/// benefits and is present merely for convenience.
57///
58/// You are not expected to store this class for a long time, because it takes
59/// a connection from the underlying connections pool.
60///
61/// Usually retrieved from `Client`.
62class ReliableChannel final : IReliableChannelInterface {
63 public:
64 ReliableChannel(ConnectionPtr&& channel);
65 ~ReliableChannel();
66
67 ReliableChannel(ReliableChannel&& other) noexcept;
68
69 void PublishReliable(const Exchange& exchange, const std::string& routing_key,
70 const std::string& message, MessageType type,
71 engine::Deadline deadline) override;
72
73 void PublishReliable(const Exchange& exchange, const std::string& routing_key,
74 const std::string& message,
75 engine::Deadline deadline) override {
76 PublishReliable(exchange, routing_key, message, MessageType::kTransient,
77 deadline);
78 }
79
80 private:
81 utils::FastPimpl<ConnectionPtr, 32, 8> impl_;
82};
83
84} // namespace urabbitmq
85
86USERVER_NAMESPACE_END