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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
use crate::types::RedisBytes;
use crate::types::{RsmqMessage, RsmqQueueAttributes};
use crate::RsmqResult;
use core::convert::TryFrom;
use std::future::Future;
use std::time::Duration;
pub trait RsmqConnection {
/// Change the hidden time of a already sent message.
///
/// `hidden` has a max time of 9_999_999 for compatibility reasons to this library JS version counterpart
fn change_message_visibility(
&mut self,
qname: &str,
message_id: &str,
hidden: Duration,
) -> impl Future<Output = RsmqResult<()>> + Send;
/// Creates a new queue. Attributes can be later modified with "set_queue_attributes" method
///
/// hidden: Time the messages will be hidden when they are received with the "receive_message" method. It
/// has a max time of 9_999_999 for compatibility reasons to this library JS version counterpart
///
/// delay: Time the messages will be delayed before being delivered
///
/// maxsize: Maximum size in bytes of each message in the queue. Needs to be between 1024 or 65536 or -1 (unlimited
/// size)
fn create_queue(
&mut self,
qname: &str,
hidden: Option<Duration>,
delay: Option<Duration>,
maxsize: Option<i64>,
) -> impl Future<Output = RsmqResult<()>> + Send;
/// Deletes a message from the queue.
///
/// Important to use when you are using receive_message.
fn delete_message(
&mut self,
qname: &str,
id: &str,
) -> impl Future<Output = RsmqResult<bool>> + Send;
/// Deletes the queue and all the messages on it
fn delete_queue(&mut self, qname: &str) -> impl Future<Output = RsmqResult<()>> + Send;
/// Returns the queue attributes and statistics
fn get_queue_attributes(
&mut self,
qname: &str,
) -> impl Future<Output = RsmqResult<RsmqQueueAttributes>> + Send;
/// Returns a list of queues in the namespace
fn list_queues(&mut self) -> impl Future<Output = RsmqResult<Vec<String>>> + Send;
/// Deletes and returns a message. Be aware that using this you may end with deleted & unprocessed messages.
fn pop_message<E: TryFrom<RedisBytes, Error = Vec<u8>>>(
&mut self,
qname: &str,
) -> impl Future<Output = RsmqResult<Option<RsmqMessage<E>>>> + Send;
/// Returns a message. The message stays hidden for some time (defined by "hidden" argument or the queue
/// settings). After that time, the message will be redelivered. In order to avoid the redelivery, you need to use
/// the "delete_message" after this function.
///
/// `hidden` has a max time of 9_999_999 for compatibility reasons to this library JS version counterpart.
fn receive_message<E: TryFrom<RedisBytes, Error = Vec<u8>>>(
&mut self,
qname: &str,
hidden: Option<Duration>,
) -> impl Future<Output = RsmqResult<Option<RsmqMessage<E>>>> + Send;
/// Sends a message to the queue. The message will be delayed some time (controlled by the "delayed" argument or
/// the queue settings) before being delivered to a client.
fn send_message<E: Into<RedisBytes> + Send>(
&mut self,
qname: &str,
message: E,
delay: Option<Duration>,
) -> impl Future<Output = RsmqResult<String>> + Send;
/// Modify the queue attributes. Keep in mind that "hidden" and "delay" can be overwritten when the message
/// is sent. "hidden" can be changed by the method "change_message_visibility"
///
/// hidden: Time the messages will be hidden when they are received with the "receive_message" method. It
/// has a max time of 9_999_999 for compatibility reasons to this library JS version counterpart
///
/// delay: Time the messages will be delayed before being delivered
///
/// maxsize: Maximum size in bytes of each message in the queue. Needs to be between 1024 or 65536 or -1 (unlimited
/// size)
fn set_queue_attributes(
&mut self,
qname: &str,
hidden: Option<Duration>,
delay: Option<Duration>,
maxsize: Option<i64>,
) -> impl Future<Output = RsmqResult<RsmqQueueAttributes>> + Send;
}
pub trait RsmqConnectionSync {
/// Change the hidden time of a already sent message.
///
/// # Arguments
/// * `qname` - Name of the queue
/// * `message_id` - ID of the message to modify
/// * `hidden` - New hidden duration. Has a max time of 9_999_999 for compatibility reasons with the JS version
fn change_message_visibility(
&mut self,
qname: &str,
message_id: &str,
hidden: Duration,
) -> RsmqResult<()>;
/// Creates a new queue. Attributes can be later modified with "set_queue_attributes" method
///
/// # Arguments
/// * `qname` - Name of the queue to create
/// * `hidden` - Time the messages will be hidden when received. Max 9_999_999
/// * `delay` - Time messages will be delayed before delivery
/// * `maxsize` - Maximum message size in bytes (1024-65536 or -1 for unlimited)
fn create_queue(
&mut self,
qname: &str,
hidden: Option<Duration>,
delay: Option<Duration>,
maxsize: Option<i64>,
) -> RsmqResult<()>;
/// Deletes a message from the queue.
///
/// Important to use when you are using receive_message.
///
/// # Arguments
/// * `qname` - Name of the queue
/// * `id` - ID of the message to delete
fn delete_message(&mut self, qname: &str, id: &str) -> RsmqResult<bool>;
/// Deletes the queue and all messages in it
///
/// # Arguments
/// * `qname` - Name of the queue to delete
fn delete_queue(&mut self, qname: &str) -> RsmqResult<()>;
/// Returns the queue attributes and statistics
///
/// # Arguments
/// * `qname` - Name of the queue
fn get_queue_attributes(&mut self, qname: &str) -> RsmqResult<RsmqQueueAttributes>;
/// Returns a list of queues in the namespace
fn list_queues(&mut self) -> RsmqResult<Vec<String>>;
/// Deletes and returns a message. Be aware that using this you may end with deleted & unprocessed messages.
///
/// # Arguments
/// * `qname` - Name of the queue
fn pop_message<E: TryFrom<RedisBytes, Error = Vec<u8>>>(
&mut self,
qname: &str,
) -> RsmqResult<Option<RsmqMessage<E>>>;
/// Returns a message. The message stays hidden for some time (defined by "hidden" argument or the queue
/// settings). After that time, the message will be redelivered. To avoid redelivery, use "delete_message"
/// after this function.
///
/// # Arguments
/// * `qname` - Name of the queue
/// * `hidden` - Optional custom hidden duration. Max 9_999_999
fn receive_message<E: TryFrom<RedisBytes, Error = Vec<u8>>>(
&mut self,
qname: &str,
hidden: Option<Duration>,
) -> RsmqResult<Option<RsmqMessage<E>>>;
/// Sends a message to the queue. The message will be delayed some time (controlled by the "delayed" argument or
/// the queue settings) before being delivered to a client.
///
/// # Arguments
/// * `qname` - Name of the queue
/// * `message` - Message content to send
/// * `delay` - Optional custom delay duration
fn send_message<E: Into<RedisBytes> + Send>(
&mut self,
qname: &str,
message: E,
delay: Option<Duration>,
) -> RsmqResult<String>;
/// Modify the queue attributes. Note that "hidden" and "delay" can be overwritten when sending messages.
/// "hidden" can be changed by the method "change_message_visibility"
///
/// # Arguments
/// * `qname` - Name of the queue
/// * `hidden` - Time messages will be hidden when received. Max 9_999_999
/// * `delay` - Time messages will be delayed before delivery
/// * `maxsize` - Maximum message size in bytes (1024-65536 or -1 for unlimited)
fn set_queue_attributes(
&mut self,
qname: &str,
hidden: Option<Duration>,
delay: Option<Duration>,
maxsize: Option<i64>,
) -> RsmqResult<RsmqQueueAttributes>;
}