userver: userver/urabbitmq/typedefs.hpp Source File
Loading...
Searching...
No Matches
typedefs.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/urabbitmq/typedefs.hpp
4/// @brief Convenient typedefs for RabbitMQ entities.
5
6#include <chrono>
7
8#include <userver/utils/strong_typedef.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace urabbitmq {
13
14/// @brief StrongTypedef alias for a queue name.
15class Queue final : public utils::StrongTypedef<class QueueTag, std::string> {
16public:
17 using utils::StrongTypedef<QueueTag, std::string>::StrongTypedef;
18
19 /// @brief Queue options, consult RabbitMQ docs for better understanding
20 enum class Flags {
21 kNone = 0,
22 kPassive = 1 << 0,
23 kDurable = 1 << 1,
24 kExclusive = 1 << 2,
25 kAutoDelete = 1 << 3,
26 kNoAck = 1 << 4
27 };
28};
29
30/// @brief StrongTypedef alias for an exchange name.
31class Exchange final : public utils::StrongTypedef<class ExchangeTag, std::string> {
32public:
33 using utils::StrongTypedef<ExchangeTag, std::string>::StrongTypedef;
34
35 /// @brief Type of an exchange.
36 ///
37 /// Consult RabbitMQ docs for better understanding.
38 enum class Type {
39 kFanOut,
40 kDirect,
41 kTopic,
42 kHeaders,
43 // plugin required
44 kConsistentHash,
45 // plugin required
46 kMessageDeduplication
47 };
48
49 /// @brief Exchange options, consult RabbitMQ docs for better understanding
50 enum class Flags {
51 kNone = 0,
52 kPassive = 1 << 0,
53 kDurable = 1 << 1,
54 kAutoDelete = 1 << 2,
55 kInternal = 1 << 3,
56 kNoWait = 1 << 4
57 };
58};
59
60/// @brief Message storage type, consult RabbitMQ docs for better understanding
61enum class MessageType {
62 kPersistent,
63 kTransient,
64};
65
66/// @brief Structure holding an AMQP message body along with some of its
67/// metadata fields. This struct is used to pass messages to the end user,
68/// hiding the actual AMQP message object implementation.
70 struct Metadata {
71 std::string exchange;
72 std::string routingKey;
73 };
74 std::string message;
75 Metadata metadata;
76 std::optional<std::string> reply_to{};
77 std::optional<std::string> correlation_id{};
78};
79
80/// @brief Structure holding an AMQP message body along with some of its
81/// metadata fields. This struct is used to pass messages from the end user,
82/// hiding the actual AMQP message object implementation.
83struct Envelope {
84 std::string message;
85 MessageType type;
86 std::optional<std::string> reply_to{};
87 std::optional<std::string> correlation_id{};
88 std::optional<std::chrono::milliseconds> expiration{};
89};
90
91} // namespace urabbitmq
92
93USERVER_NAMESPACE_END