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