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,
32public:
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, const ClientSettings& settings);
37 /// Client destructor
39
41 const Exchange& exchange,
42 Exchange::Type type,
43 utils::Flags<Exchange::Flags> flags,
44 engine::Deadline deadline
45 ) override;
46
47 void DeclareExchange(const Exchange& exchange, Exchange::Type type, engine::Deadline deadline) override {
48 DeclareExchange(exchange, type, {}, deadline);
49 }
50
51 void DeclareExchange(const Exchange& exchange, engine::Deadline deadline) override {
52 DeclareExchange(exchange, Exchange::Type::kFanOut, {}, deadline);
53 }
54
55 void DeclareQueue(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) override;
56
57 void DeclareQueue(const Queue& queue, engine::Deadline deadline) override { DeclareQueue(queue, {}, deadline); }
58
60 const Exchange& exchange,
61 const Queue& queue,
62 const std::string& routing_key,
63 engine::Deadline deadline
64 ) override;
65
66 void RemoveExchange(const Exchange& exchange, engine::Deadline deadline) override;
67
68 void RemoveQueue(const Queue& queue, engine::Deadline deadline) override;
69
70 /// @brief Get an administrative interface for the broker.
71 ///
72 /// @param deadline deadline for connection acquisition from the pool
73 AdminChannel GetAdminChannel(engine::Deadline deadline);
74
75 void Publish(
76 const Exchange& exchange,
77 const std::string& routing_key,
78 const std::string& message,
79 MessageType type,
80 engine::Deadline deadline
81 ) override;
82
83 void Publish(
84 const Exchange& exchange,
85 const std::string& routing_key,
86 const std::string& message,
87 engine::Deadline deadline
88 ) override {
89 Publish(exchange, routing_key, message, MessageType::kTransient, deadline);
90 };
91
92 std::string Get(const Queue& queue, utils::Flags<Queue::Flags> flags, engine::Deadline deadline) override;
93
94 /// @brief Get a publisher interface for the broker.
95 ///
96 /// @param deadline deadline for connection acquisition from the pool
97 Channel GetChannel(engine::Deadline deadline);
98
100 const Exchange& exchange,
101 const std::string& routing_key,
102 const std::string& message,
103 MessageType type,
104 engine::Deadline deadline
105 ) override;
106
108 const Exchange& exchange,
109 const std::string& routing_key,
110 const std::string& message,
111 engine::Deadline deadline
112 ) override {
113 PublishReliable(exchange, routing_key, message, MessageType::kTransient, deadline);
114 }
115
116 /// @brief Get a reliable publisher interface for the broker
117 /// (publisher-confirms)
118 ///
119 /// @param deadline deadline for connection acquisition from the pool
120 ReliableChannel GetReliableChannel(engine::Deadline deadline);
121
122 /// Write cluster statistics
123 void WriteStatistics(utils::statistics::Writer& writer) const;
124
125protected:
126 Client(clients::dns::Resolver& resolver, const ClientSettings& settings);
127
128private:
129 friend class ConsumerBase;
130 utils::FastPimpl<ClientImpl, 296, 8> impl_;
131};
132
133} // namespace urabbitmq
134
135USERVER_NAMESPACE_END