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#include <cstdint>
8#include <optional>
9#include <string>
10#include <unordered_map>
11
12#include <userver/formats/json/value.hpp>
13#include <userver/utils/strong_typedef.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace urabbitmq {
18
19/// @brief StrongTypedef alias for a queue name.
20class Queue final : public utils::StrongTypedef<class QueueTag, std::string> {
21public:
22 using utils::StrongTypedef<QueueTag, std::string>::StrongTypedef;
23
24 /// @brief Queue options, consult RabbitMQ docs for better understanding
25 enum class Flags {
26 kNone = 0,
27 kPassive = 1 << 0,
28 kDurable = 1 << 1,
29 kExclusive = 1 << 2,
30 kAutoDelete = 1 << 3,
31 kNoAck = 1 << 4
32 };
33};
34
35/// @brief StrongTypedef alias for an exchange name.
36class Exchange final : public utils::StrongTypedef<class ExchangeTag, std::string> {
37public:
38 using utils::StrongTypedef<ExchangeTag, std::string>::StrongTypedef;
39
40 /// @brief Type of an exchange.
41 ///
42 /// Consult RabbitMQ docs for better understanding.
43 enum class Type {
44 kFanOut,
45 kDirect,
46 kTopic,
47 kHeaders,
48 // plugin required
49 kConsistentHash,
50 // plugin required
51 kMessageDeduplication
52 };
53
54 /// @brief Exchange options, consult RabbitMQ docs for better understanding
55 enum class Flags {
56 kNone = 0,
57 kPassive = 1 << 0,
58 kDurable = 1 << 1,
59 kAutoDelete = 1 << 2,
60 kInternal = 1 << 3,
61 kNoWait = 1 << 4
62 };
63};
64
65/// @brief Message storage type, consult RabbitMQ docs for better understanding
66enum class MessageType {
67 kPersistent,
68 kTransient,
69};
70
71/// JSON-like representation of an AMQP header value.
72/// This is not JSON, but a convenient tree representation for AMQP field values.
73using HeaderValue = formats::json::Value;
74
75/// @brief Structure holding an AMQP message body along with some of its
76/// metadata fields. This struct is used to pass messages to the end user,
77/// hiding the actual AMQP message object implementation.
79 struct Metadata {
80 std::string exchange;
81 std::string routingKey;
82 };
83 std::string message;
84 Metadata metadata;
85 std::optional<std::string> reply_to{};
86 std::optional<std::string> correlation_id{};
87 std::unordered_map<std::string, HeaderValue> headers{};
88};
89
90/// @brief Structure holding an AMQP message body along with some of its
91/// metadata fields. This struct is used to pass messages from the end user,
92/// hiding the actual AMQP message object implementation.
93struct Envelope {
94 std::string message;
95 MessageType type;
96 std::optional<std::string> reply_to{};
97 std::optional<std::string> correlation_id{};
98 std::optional<std::chrono::milliseconds> expiration{};
99 std::optional<std::unordered_map<std::string, HeaderValue>> headers{};
100};
101
102} // namespace urabbitmq
103
104USERVER_NAMESPACE_END