Expand description

rabbitmq-stream-client

Experimental Rust client for RabbitMQ Stream

The main access point is Environment, which is used to connect to a node.

Example

Building the environment

use rabbitmq_stream_client::Environment;

let environment = Environment::builder().build().await?;

For more connection options check EnvironmentBuilder

Publishing messages

use rabbitmq_stream_client::{Environment, types::Message};

let environment = Environment::builder().build().await?;
let producer = environment.producer().build("mystream").await?;

for i in 0..10 {
    producer
        .send_with_confirm(Message::builder().body(format!("message{}", i)).build())
        .await?;
}

producer.close().await?;

For more producer options check ProducerBuilder

Consuming messages

use rabbitmq_stream_client::{Environment};
use futures::StreamExt;
use tokio::task;
use tokio::time::{sleep, Duration};

let environment = Environment::builder().build().await?;
let mut consumer = environment.consumer().build("mystream").await?;


let handle = consumer.handle();
task::spawn(async move {
    while let Some(delivery) = consumer.next().await {
        println!("Got message {:?}",delivery);
    }
});

// wait 10 second and then close the consumer
sleep(Duration::from_secs(10)).await;

handle.close().await?;

For more consumer options check ConsumerBuilder

Modules

Structs

Traits

Type Aliases