strut_rabbitmq/repr/ingress/
queue.rs

1use strut_factory::Deserialize as StrutDeserialize;
2
3/// Defines a RabbitMQ queue kind, which is currently limited to either **classic**
4/// or **quorum** queues. See the RabbitMQ documentation for details.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, StrutDeserialize)]
6#[strut(eq_fn = strut_deserialize::Slug::eq_as_slugs)]
7pub enum QueueKind {
8    /// Classic queues are stored on a single node in the RabbitMQ cluster and
9    /// provide high throughput.
10    ///
11    /// A classic queue may still be mirrored to other nodes, which provides a degree
12    /// of high availability.
13    Classic,
14    /// Quorum queues are stored on multiple nodes in the RabbitMQ cluster and
15    /// provide high availability using a quorum algorithm.
16    Quorum,
17}
18
19/// Defines optional queue renaming behavior. Values other than
20/// [`Verbatim`](QueueRenamingBehavior::Verbatim) trigger appending of a
21/// suffix to the user-provided queue name.
22///
23/// When a suffix is added, it is separated from the preceding queue name with a
24/// full-stop `.` character. A suffix is never added to an empty queue name.
25#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, StrutDeserialize)]
26#[strut(eq_fn = strut_deserialize::Slug::eq_as_slugs)]
27pub enum QueueRenamingBehavior {
28    /// Leaves the queue name unchanged (doesn’t add any suffix).
29    #[strut(alias = "none")]
30    Verbatim,
31
32    /// Suffixes the queue name with the application replica index (as reported
33    /// by [`AppReplica::index`](strut_core::AppReplica::index)).
34    #[strut(alias = "index")]
35    ReplicaIndex,
36
37    /// Suffixes the queue name with the application replica lifetime ID (as reported
38    /// by [`AppReplica::lifetime_id`](strut_core::AppReplica::lifetime_id)).
39    #[strut(alias = "lifetime", alias = "lifetime_id")]
40    ReplicaLifetimeId,
41}
42
43impl QueueKind {
44    /// Returns the appropriate string header value recognized by RabbitMQ.
45    pub const fn rabbitmq_value(&self) -> &str {
46        match self {
47            QueueKind::Classic => "classic",
48            QueueKind::Quorum => "quorum",
49        }
50    }
51}