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