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