Skip to content

Commit 58cde32

Browse files
committed
add sync version of trait; version bump
1 parent 355b6f6 commit 58cde32

File tree

4 files changed

+136
-17
lines changed

4 files changed

+136
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rsmq_async"
3-
version = "14.0.0"
3+
version = "15.0.0"
44
authors = ["David Bonet <webbonet@gmail.com>"]
55
edition = "2021"
66
license = "MIT"

src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
//! [![dependency status](https://deps.rs/crate/rsmq_async/4.0.0/status.svg)](https://deps.rs/crate/rsmq_async)
99
//! [![Docs](https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square)](https://docs.rs/rsmq_async)
1010
//!
11+
//! ## Traits
12+
//!
13+
//! This library provides two core traits for interacting with Redis message queues:
14+
//!
15+
//! - [`RsmqConnection`]: The async trait that defines all queue operations. Must be imported with `use rsmq_async::RsmqConnection;`
16+
//! - [`RsmqConnectionSync`]: The synchronous version of the trait, available with the "sync" feature. Must be imported with `use rsmq_async::RsmqConnectionSync;`
17+
//!
18+
//! ## Implementations
19+
//!
20+
//! Three main implementations are provided:
21+
//!
22+
//! - [`Rsmq`]: The preferred implementation using a multiplexed Redis connection
23+
//! - [`PooledRsmq`]: Uses a connection pool for large messages
24+
//! - [`RsmqSync`]: A synchronous wrapper (requires "sync" feature)
25+
//!
1126
//! ## Example
1227
//!
1328
//! ```rust
@@ -24,10 +39,6 @@
2439
//!
2540
//! ```
2641
//!
27-
//! Main object documentation are in: [`Rsmq`] and[`PooledRsmq`] and they both implement the trait
28-
//! [`RsmqConnection`] where you can see all the RSMQ methods. Make sure you always import the trait
29-
//! [`RsmqConnection`].
30-
//!
3142
//! ## Installation
3243
//!
3344
//! Check [https://crates.io/crates/rsmq_async](https://crates.io/crates/rsmq_async)
@@ -170,6 +181,8 @@ pub use multiplexed_facade::Rsmq;
170181
pub use pooled_facade::{PoolOptions, PooledRsmq, RedisConnectionManager};
171182
pub use r#trait::RsmqConnection;
172183
#[cfg(feature = "sync")]
184+
pub use r#trait::RsmqConnectionSync;
185+
#[cfg(feature = "sync")]
173186
pub use sync_facade::RsmqSync;
174187
pub use types::RedisBytes;
175188
pub use types::RsmqMessage;

src/sync_facade.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::functions::{CachedScript, RsmqFunctions};
2-
use crate::r#trait::RsmqConnection;
2+
use crate::r#trait::RsmqConnectionSync;
33
use crate::types::{RedisBytes, RsmqMessage, RsmqOptions, RsmqQueueAttributes};
44
use crate::{RsmqError, RsmqResult};
55
use core::convert::TryFrom;
@@ -66,8 +66,8 @@ impl RsmqSync {
6666
}
6767
}
6868

69-
impl RsmqConnection for RsmqSync {
70-
async fn change_message_visibility(
69+
impl RsmqConnectionSync for RsmqSync {
70+
fn change_message_visibility(
7171
&mut self,
7272
qname: &str,
7373
message_id: &str,
@@ -86,7 +86,7 @@ impl RsmqConnection for RsmqSync {
8686
})
8787
}
8888

89-
async fn create_queue(
89+
fn create_queue(
9090
&mut self,
9191
qname: &str,
9292
hidden: Option<Duration>,
@@ -100,34 +100,34 @@ impl RsmqConnection for RsmqSync {
100100
})
101101
}
102102

103-
async fn delete_message(&mut self, qname: &str, id: &str) -> RsmqResult<bool> {
103+
fn delete_message(&mut self, qname: &str, id: &str) -> RsmqResult<bool> {
104104
self.runner.block_on(async {
105105
self.functions
106106
.delete_message(&mut self.connection.0, qname, id)
107107
.await
108108
})
109109
}
110-
async fn delete_queue(&mut self, qname: &str) -> RsmqResult<()> {
110+
fn delete_queue(&mut self, qname: &str) -> RsmqResult<()> {
111111
self.runner.block_on(async {
112112
self.functions
113113
.delete_queue(&mut self.connection.0, qname)
114114
.await
115115
})
116116
}
117-
async fn get_queue_attributes(&mut self, qname: &str) -> RsmqResult<RsmqQueueAttributes> {
117+
fn get_queue_attributes(&mut self, qname: &str) -> RsmqResult<RsmqQueueAttributes> {
118118
self.runner.block_on(async {
119119
self.functions
120120
.get_queue_attributes(&mut self.connection.0, qname)
121121
.await
122122
})
123123
}
124124

125-
async fn list_queues(&mut self) -> RsmqResult<Vec<String>> {
125+
fn list_queues(&mut self) -> RsmqResult<Vec<String>> {
126126
self.runner
127127
.block_on(async { self.functions.list_queues(&mut self.connection.0).await })
128128
}
129129

130-
async fn pop_message<E: TryFrom<RedisBytes, Error = Vec<u8>>>(
130+
fn pop_message<E: TryFrom<RedisBytes, Error = Vec<u8>>>(
131131
&mut self,
132132
qname: &str,
133133
) -> RsmqResult<Option<RsmqMessage<E>>> {
@@ -138,7 +138,7 @@ impl RsmqConnection for RsmqSync {
138138
})
139139
}
140140

141-
async fn receive_message<E: TryFrom<RedisBytes, Error = Vec<u8>>>(
141+
fn receive_message<E: TryFrom<RedisBytes, Error = Vec<u8>>>(
142142
&mut self,
143143
qname: &str,
144144
hidden: Option<Duration>,
@@ -150,7 +150,7 @@ impl RsmqConnection for RsmqSync {
150150
})
151151
}
152152

153-
async fn send_message<E: Into<RedisBytes> + Send>(
153+
fn send_message<E: Into<RedisBytes> + Send>(
154154
&mut self,
155155
qname: &str,
156156
message: E,
@@ -163,7 +163,7 @@ impl RsmqConnection for RsmqSync {
163163
})
164164
}
165165

166-
async fn set_queue_attributes(
166+
fn set_queue_attributes(
167167
&mut self,
168168
qname: &str,
169169
hidden: Option<Duration>,

src/trait.rs

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

0 commit comments

Comments
 (0)