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
92
93
94
95
96
97
98
#[derive(Clone, Debug)]
pub enum StartPosition {
EndOfStream,
Other(String),
StartOfStream,
}
#[derive(Debug)]
pub struct ConsumerOpts {
pub count: Option<usize>,
pub create_stream_if_not_exists: bool,
pub group: Option<(String, String)>,
pub process_pending: bool,
pub start_pos: StartPosition,
pub timeout: usize,
}
impl Default for ConsumerOpts {
fn default() -> Self {
Self {
count: None,
create_stream_if_not_exists: true,
group: None,
process_pending: true,
start_pos: StartPosition::EndOfStream,
timeout: 2_000,
}
}
}
impl ConsumerOpts {
pub fn count(mut self, count: usize) -> Self {
self.count = Some(count);
self
}
pub fn create_stream_if_not_exists(mut self, create_stream_if_not_exists: bool) -> Self {
self.create_stream_if_not_exists = create_stream_if_not_exists;
self
}
pub fn group(mut self, group_name: &str, consumer_name: &str) -> Self {
self.group = Some((group_name.to_string(), consumer_name.to_string()));
self
}
pub fn process_pending(mut self, process_pending: bool) -> Self {
self.process_pending = process_pending;
self
}
pub fn start_pos(mut self, start_pos: StartPosition) -> Self {
self.start_pos = start_pos;
self
}
pub fn timeout(mut self, timeout: usize) -> Self {
self.timeout = timeout;
self
}
}