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
26struct ClientCertSettings {
27 crypto::Certificate cert;
28 crypto::PrivateKey key;
29};
30
31struct TlsSettings {
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
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
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
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
79class TestsHelper;
80struct ClientSettings final {
81 /// Per-host connections pool settings
82 PoolSettings pool_settings{};
83
84 /// Endpoints settings
85 RabbitEndpoints endpoints{};
86
87 /// Whether to use TLS for connections
88 bool use_secure_connection = true;
89
90 ClientSettings(const components::ComponentConfig& config,
91 const RabbitEndpoints& rabbit_endpoints);
92
93 private:
94 friend class TestsHelper;
95 ClientSettings();
96};
97
98class RabbitEndpointsMulti final {
99 public:
100 RabbitEndpointsMulti(const formats::json::Value& doc);
101
102 const RabbitEndpoints& Get(const std::string& name) const;
103
104 private:
105 std::unordered_map<std::string, RabbitEndpoints> endpoints_;
106};
107
108} // namespace urabbitmq
109
110USERVER_NAMESPACE_END