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