11 releases

0.1.10 Sep 23, 2024
0.1.9 Jun 4, 2024
0.1.8 Feb 10, 2024

#1745 in Network programming

Download history 1/week @ 2024-06-28 63/week @ 2024-07-05 9/week @ 2024-07-12 9/week @ 2024-07-19 14/week @ 2024-07-26 2/week @ 2024-08-02 65/week @ 2024-08-09 1/week @ 2024-08-16 16/week @ 2024-08-23 13/week @ 2024-08-30 27/week @ 2024-09-06 11/week @ 2024-09-13 178/week @ 2024-09-20 43/week @ 2024-09-27 15/week @ 2024-10-04 6/week @ 2024-10-11

243 downloads per month

MIT license

17KB
241 lines

rabbit_mqr

Extremely simplified RabbitMQ client built on-top of lapin.

This crate was mainly created from my cumbersome experience with both lapin and amqprs. If you simply need a client to publish and asynchronously read messages from a queue, one-by-one, this is the crate for you.

There are no consumers, there is a simple API to register queues, and to publish, ack/nack, and read messages from the queue.

Installation

cargo add rabbit_mqr

Requirements

Usage

Exposes two structs:

  • RabbitMQ, which is a manager of the queues, and the main access point to publish messages, or to get the inner Queues.

  • Queue, which represents a single Queue, and has the basic operations.

Full crate documentation can be found here.

Basic Example

use rabbit_mqr::{GetMessageResult, RabbitMQ};
use std::time::Duration;
use tokio::time::sleep;

#[tokio::main]
async fn main() -> Result<(), rabbit_mqr::lapin::Error> {
    let mut rabbit_mq = RabbitMQ::new("amqp://guest:guest@localhost:5672/%2f", None).await?;

    rabbit_mq.register_queue("test_queue", None, None).await?;

    rabbit_mq
        .publish_message("test_queue", b"1337".to_vec(), None)
        .await?;

    rabbit_mq
        .publish_message("test_queue", b"1337".to_vec(), None)
        .await?;

    if let Some(test_queue) = rabbit_mq.get_queue("test_queue") {
        while let Some(GetMessageResult {
            message,
            delivery_tag,
        }) = test_queue.get_message().await?
        {
            println!("{}", String::from_utf8(message).unwrap());
            // Prints: "1337"

            test_queue.acknowledge_message(delivery_tag).await?;

            sleep(Duration::from_millis(1337)).await;
        }
    }

    Ok(())
}

License

MIT See LICENSE.md

Third party

This crate is built on-top of lapin see their MIT license here

Dependencies

~7–18MB
~266K SLoC