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/// @ingroup userver_components
24///
25/// @brief RabbitMQ (AMQP 0.9.1) client component
26///
27/// Provides access to a RabbitMQ cluster.
28///
29/// ## Static configuration example:
30///
31/// @snippet samples/rabbitmq_service/static_config.yaml RabbitMQ service sample - static config
32///
33/// If the component is configured with an secdist_alias, it will lookup
34/// connection data in secdist.json via secdist_alias value, otherwise via
35/// components name.
36///
37/// ## Secdist format
38///
39/// A RabbitMQ alias in secdist is described as a JSON object
40/// 'rabbitmq_settings', containing descriptions of RabbitMQ clusters.
41///
42/// @snippet samples/rabbitmq_service/tests/conftest.py RabbitMQ service sample - secdist
43///
44/// ## Static options of components::RabbitMQ :
45/// @include{doc} scripts/docs/en/components_schema/rabbitmq/src/urabbitmq/component.md
46///
47/// Options inherited from @ref components::ComponentBase :
48/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
49class RabbitMQ final : public ComponentBase {
50public:
51 /// Component constructor
52 RabbitMQ(const ComponentConfig& config, const ComponentContext& context);
53 /// Component destructor
54 ~RabbitMQ() override;
55
56 /// Cluster accessor
57 std::shared_ptr<urabbitmq::Client> GetClient() const;
58
59 static yaml_config::Schema GetStaticConfigSchema();
60
61private:
62 clients::dns::Component& dns_;
63 std::shared_ptr<urabbitmq::Client> client_;
64
65 // Must be the last field
66 utils::statistics::Entry statistics_holder_;
67};
68
69template <>
70inline constexpr bool kHasValidate<RabbitMQ> = true;
71
72} // namespace components
73
74USERVER_NAMESPACE_END