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
use crate::types::RedisBytes;
use crate::types::{RsmqMessage, RsmqQueueAttributes};
use crate::RsmqResult;
use core::convert::TryFrom;
use std::time::Duration;
#[async_trait::async_trait]
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
async 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
///
/// 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)
async fn create_queue(
&mut self,
qname: &str,
hidden: Option<Duration>,
delay: Option<Duration>,
maxsize: Option<i32>,
) -> RsmqResult<()>;
/// Deletes a message from the queue.
///
/// Important to use when you are using receive_message.
async fn delete_message(&mut self, qname: &str, id: &str) -> RsmqResult<bool>;
/// Deletes the queue and all the messages on it
async fn delete_queue(&mut self, qname: &str) -> RsmqResult<()>;
/// Returns the queue attributes and statistics
async fn get_queue_attributes(&mut self, qname: &str) -> RsmqResult<RsmqQueueAttributes>;
/// Returns a list of queues in the namespace
async 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.
async 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. 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.
async 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.
async fn send_message<E: Into<RedisBytes> + Send>(
&mut self,
qname: &str,
message: E,
delay: Option<Duration>,
) -> RsmqResult<String>;
/// 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)
async fn set_queue_attributes(
&mut self,
qname: &str,
hidden: Option<Duration>,
delay: Option<Duration>,
maxsize: Option<i64>,
) -> RsmqResult<RsmqQueueAttributes>;
}