userver: userver/urabbitmq/component.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/urabbitmq/component.hpp
4/// @brief @copybrief components::RabbitMQ
5
6#include <memory>
7
8#include <userver/components/loggable_component_base.hpp>
9
10#include <userver/utils/statistics/storage.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace clients::dns {
15class Component;
16}
17
18namespace urabbitmq {
19class Client;
20}
21
22namespace components {
23
24// clang-format off
25/// @ingroup userver_components
26///
27/// @brief RabbitMQ (AMQP 0.9.1) client component
28///
29/// Provides access to a RabbitMQ cluster.
30///
31/// ## Static configuration example:
32///
33/// @snippet samples/rabbitmq_service/static_config.yaml RabbitMQ service sample - static config
34///
35/// If the component is configured with an secdist_alias, it will lookup
36/// connection data in secdist.json via secdist_alias value, otherwise via
37/// components name.
38///
39/// ## Secdist format
40///
41/// A RabbitMQ alias in secdist is described as a JSON object
42/// 'rabbitmq_settings', containing descriptions of RabbitMQ clusters.
43///
44/// @snippet samples/rabbitmq_service/tests/conftest.py RabbitMQ service sample - secdist
45///
46/// ## Static options:
47/// Name | Description | Default value
48/// ----------------------- | -------------------------------------------------------------------- | ---------------
49/// secdist_alias | name of the key in secdist config | components name
50/// min_pool_size | minimum connections pool size (per host) | 5
51/// max_pool_size | maximum connections pool size (per host, consumers excluded) | 10
52/// max_in_flight_requests | per-connection limit for requests awaiting response from the broker | 5
53/// use_secure_connection | whether to use TLS for connections | true
54///
55// clang-format on
56
58 public:
59 /// Component constructor
60 RabbitMQ(const ComponentConfig& config, const ComponentContext& context);
61 /// Component destructor
62 ~RabbitMQ() override;
63
64 /// Cluster accessor
65 std::shared_ptr<urabbitmq::Client> GetClient() const;
66
67 static yaml_config::Schema GetStaticConfigSchema();
68
69 private:
70 clients::dns::Component& dns_;
71
72 std::shared_ptr<urabbitmq::Client> client_;
73 utils::statistics::Entry statistics_holder_;
74};
75
76template <>
77inline constexpr bool kHasValidate<RabbitMQ> = true;
78
79} // namespace components
80
81USERVER_NAMESPACE_END