userver: userver/urabbitmq/client.hpp Source File
Loading...
Searching...
No Matches
client.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/urabbitmq/client.hpp
4/// @brief @copybrief urabbitmq::Client
5
6#include <memory>
7
8#include <userver/clients/dns/resolver_fwd.hpp>
9#include <userver/utils/fast_pimpl.hpp>
10#include <userver/utils/statistics/writer.hpp>
11
12#include <userver/rabbitmq_fwd.hpp>
13#include <userver/urabbitmq/broker_interface.hpp>
14#include <userver/urabbitmq/client_settings.hpp>
15
16USERVER_NAMESPACE_BEGIN
17
18namespace urabbitmq {
19
20class ConsumerBase;
21class ClientImpl;
22
23/// @ingroup userver_clients
24///
25/// @brief Interface for communicating with a RabbitMQ cluster.
26///
27/// Usually retrieved from components::RabbitMQ component.
29 public IAdminInterface,
30 public IChannelInterface,
32 public:
33 /// Client factory function
34 /// @param resolver asynchronous DNS resolver
35 /// @param settings client settings
36 static std::shared_ptr<Client> Create(clients::dns::Resolver& resolver,
37 const ClientSettings& settings);
38 /// Client destructor
40
41 void DeclareExchange(const Exchange& exchange, Exchange::Type type,
42 utils::Flags<Exchange::Flags> flags,
43 engine::Deadline deadline) override;
44
45 void DeclareExchange(const Exchange& exchange, Exchange::Type type,
46 engine::Deadline deadline) override {
47 DeclareExchange(exchange, type, {}, deadline);
48 }
49
50 void DeclareExchange(const Exchange& exchange,
51 engine::Deadline deadline) override {
52 DeclareExchange(exchange, Exchange::Type::kFanOut, {}, deadline);
53 }
54
55 void DeclareQueue(const Queue& queue, utils::Flags<Queue::Flags> flags,
56 engine::Deadline deadline) override;
57
58 void DeclareQueue(const Queue& queue, engine::Deadline deadline) override {
59 DeclareQueue(queue, {}, deadline);
60 }
61
62 void BindQueue(const Exchange& exchange, const Queue& queue,
63 const std::string& routing_key,
64 engine::Deadline deadline) override;
65
66 void RemoveExchange(const Exchange& exchange,
67 engine::Deadline deadline) override;
68
69 void RemoveQueue(const Queue& queue, engine::Deadline deadline) override;
70
71 /// @brief Get an administrative interface for the broker.
72 ///
73 /// @param deadline deadline for connection acquisition from the pool
74 AdminChannel GetAdminChannel(engine::Deadline deadline);
75
76 void Publish(const Exchange& exchange, const std::string& routing_key,
77 const std::string& message, MessageType type,
78 engine::Deadline deadline) override;
79
80 void Publish(const Exchange& exchange, const std::string& routing_key,
81 const std::string& message, engine::Deadline deadline) override {
82 Publish(exchange, routing_key, message, MessageType::kTransient, deadline);
83 };
84
85 std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags,
86 engine::Deadline deadline) override;
87
88 /// @brief Get a publisher interface for the broker.
89 ///
90 /// @param deadline deadline for connection acquisition from the pool
91 Channel GetChannel(engine::Deadline deadline);
92
93 void PublishReliable(const Exchange& exchange, const std::string& routing_key,
94 const std::string& message, MessageType type,
95 engine::Deadline deadline) override;
96
97 void PublishReliable(const Exchange& exchange, const std::string& routing_key,
98 const std::string& message,
99 engine::Deadline deadline) override {
100 PublishReliable(exchange, routing_key, message, MessageType::kTransient,
101 deadline);
102 }
103
104 /// @brief Get a reliable publisher interface for the broker
105 /// (publisher-confirms)
106 ///
107 /// @param deadline deadline for connection acquisition from the pool
108 ReliableChannel GetReliableChannel(engine::Deadline deadline);
109
110 /// Write cluster statistics
111 void WriteStatistics(utils::statistics::Writer& writer) const;
112
113 protected:
114 Client(clients::dns::Resolver& resolver, const ClientSettings& settings);
115
116 private:
117 friend class ConsumerBase;
118 utils::FastPimpl<ClientImpl, 232, 8> impl_;
119};
120
121} // namespace urabbitmq
122
123USERVER_NAMESPACE_END