userver: userver/urabbitmq/client_settings.hpp Source File
Loading...
Searching...
No Matches
client_settings.hpp
1#pragma once
2
3#include <cstddef>
4#include <string>
5#include <unordered_map>
6#include <vector>
7
8#include <userver/components/component_config.hpp>
9#include <userver/formats/json_fwd.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace urabbitmq {
14
15struct EndpointInfo final {
16 /// RabbitMQ node address (either FQDN or ip)
17 std::string host = "localhost";
18
19 /// Port to connect to
20 uint16_t port = 5672;
21};
22
23struct AuthSettings final {
24 /// Login to use
25 std::string login = "guest";
26
27 /// Password to use
28 std::string password = "guest";
29
30 /// RabbitMQs vhost
31 std::string vhost = "/";
32};
33
34struct RabbitEndpoints final {
35 /// Auth settings
36 AuthSettings auth{};
37
38 /// Endpoints to connect to
40};
41
42struct PoolSettings final {
43 /// Library will try to maintain at least this amount of connections.
44 /// Note that every consumer takes a connection for himself and this limit
45 /// doesn't account that
47
48 /// Library will maintain at most this amount of connections.
49 /// Note that every consumer takes a connection for himself and this limit
50 /// doesn't account that
52
53 /// A per-connection limit for concurrent requests waiting
54 /// for response from the broker.
55 /// Note: increasing this allows one to potentially increase throughput,
56 /// but in case of a connection-wide error
57 /// (tcp error/protocol error/write timeout) leads to a errors burst:
58 /// all outstanding request will fails at once
60};
61
62class TestsHelper;
63struct ClientSettings final {
64 /// Per-host connections pool settings
65 PoolSettings pool_settings{};
66
67 /// Endpoints settings
68 RabbitEndpoints endpoints{};
69
70 /// Whether to use TLS for connections
71 bool use_secure_connection = true;
72
73 ClientSettings(const components::ComponentConfig& config,
74 const RabbitEndpoints& rabbit_endpoints);
75
76 private:
77 friend class TestsHelper;
78 ClientSettings();
79};
80
81class RabbitEndpointsMulti final {
82 public:
83 RabbitEndpointsMulti(const formats::json::Value& doc);
84
85 const RabbitEndpoints& Get(const std::string& name) const;
86
87 private:
88 std::unordered_map<std::string, RabbitEndpoints> endpoints_;
89};
90
91} // namespace urabbitmq
92
93USERVER_NAMESPACE_END