1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crate::{
options::QueueDeclareOptions,
types::{ConsumerCount, MessageCount, ShortString},
};
use std::borrow::Borrow;
/// Information about an AMQP queue as returned by the server.
///
/// Obtained as the return value of [`Channel::queue_declare`].
///
/// [`Channel::queue_declare`]: crate::Channel::queue_declare
#[derive(Clone, Debug)]
pub struct Queue {
name: ShortString,
message_count: MessageCount,
consumer_count: ConsumerCount,
}
impl Queue {
pub(crate) fn new(
name: ShortString,
message_count: MessageCount,
consumer_count: ConsumerCount,
) -> Self {
Self {
name,
message_count,
consumer_count,
}
}
/// The name of the queue.
#[must_use]
pub fn name(&self) -> &ShortString {
&self.name
}
/// The number of messages currently in the queue.
#[must_use]
pub fn message_count(&self) -> MessageCount {
self.message_count
}
/// The number of active consumers on the queue.
#[must_use]
pub fn consumer_count(&self) -> ConsumerCount {
self.consumer_count
}
}
impl Borrow<str> for Queue {
fn borrow(&self) -> &str {
self.name.as_str()
}
}
impl QueueDeclareOptions {
/// The traditional queue type, persisted on the AMQP server.
#[must_use]
pub fn durable() -> Self {
Self {
durable: true,
..Default::default()
}
}
/// Only the current connection can consume messages.
/// When enabling exclusive, you probably want to enable auto_delete too.
#[must_use]
pub fn exclusive() -> Self {
Self {
exclusive: true,
..Default::default()
}
}
/// The queue will get automatically deleted when its last consumer stops.
#[must_use]
pub fn auto_delete(mut self) -> Self {
self.auto_delete = true;
self
}
/// When enabling passive, we only checks for a queue existence.
/// If the queue exists, the queue_declare call will succeed, otherwise a channel error is raised.
#[must_use]
pub fn passive(mut self) -> Self {
self.passive = true;
self
}
}