[][src]Crate rsmq_async

This is a port of the nodejs Redis Simple Message Queue package. It is a 1-to-1 conversion using async.

use rsmq_async::{Rsmq, RsmqError};

let mut rsmq = Rsmq::new(Default::default()).await?;
 
let message = rsmq.receive_message("myqueue", None).await?;
 
if let Some(message) = message {
    rsmq.delete_message("myqueue", &message.id).await?;
}
 

Main object documentation in: Rsmq

Realtime

When initializing RSMQ you can enable the realtime PUBLISH for new messages. On every new message that gets sent to RSQM via sendMessage a Redis PUBLISH will be issued to {rsmq.ns}:rt:{qname}.

Example for RSMQ with default settings:

  • The queue testQueue already contains 5 messages.
  • A new message is being sent to the queue testQueue.
  • The following Redis command will be issued: PUBLISH rsmq:rt:testQueue 6

How to use the realtime option

Besides the PUBLISH when a new message is sent to RSMQ nothing else will happen. Your app could use the Redis SUBSCRIBE command to be notified of new messages and issue a receiveMessage then. However make sure not to listen with multiple workers for new messages with SUBSCRIBE to prevent multiple simultaneous receiveMessage calls.

Guarantees

If you want to implement "at least one delivery" guarantee, you need to receive the messages using "receive_message" and then, once the message is successfully processed, delete it with "delete_message".

If you want to implement "one or less delivery" guarantee, you can use the "pop_message" method. Be aware that you may loose (delete without processing) messages in that case.

Structs

Rsmq

THe main object of this library. Creates/Handles the redis connection and contains all the methods

RsmqMessage

A new RSMQ message. You will get this when using pop_message or receive_message methods

RsmqOptions

Options for creating a new RSMQ instance.

RsmqQueueAttributes

Struct defining a queue. They are set on "create_queue" and "set_queue_attributes"

Enums

RsmqError