7 releases (4 breaking)

0.4.2 Feb 16, 2024
0.4.1 Oct 30, 2023
0.4.0 Sep 12, 2023
0.3.0 Aug 1, 2023
0.0.0 Sep 16, 2021

#1024 in Network programming

Download history 5/week @ 2023-12-22 23/week @ 2023-12-29 16/week @ 2024-01-05 4/week @ 2024-01-12 12/week @ 2024-01-19 54/week @ 2024-01-26 242/week @ 2024-02-02 104/week @ 2024-02-09 233/week @ 2024-02-16 142/week @ 2024-02-23 74/week @ 2024-03-01 51/week @ 2024-03-08 31/week @ 2024-03-15 61/week @ 2024-03-22 68/week @ 2024-03-29 30/week @ 2024-04-05

196 downloads per month
Used in rabbitmq-stream-client

Apache-2.0 OR MPL-2.0

220KB
6.5K SLoC

RabbitMQ Stream Rust


A Work in progress Rust Client for RabbitMQ Stream

RabbitMQ Stream Client

A Rust Client for RabbitMQ Stream Queues

Installation

Install from crates.io

[dependencies]
rabbitmq-stream-client = "*"

Quick Start

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?;
Building the environment with TLS
use rabbitmq_stream_client::Environment;

let tls_configuration: TlsConfiguration = TlsConfiguration::builder()
.add_root_certificates(String::from(".ci/certs/ca_certificate.pem"))
.build();

// Use this configuration if you want to trust the certificates
// without providing the root certificate
let tls_configuration: TlsConfiguration = TlsConfiguration::builder()
     .trust_certificates(true)
     .build();

let environment = Environment::builder()
    .host("localhost")
    .port(5551) // specify the TLS port of the node
    .tls(tls_configuration)
    .build()
Publishing messages
use rabbitmq_stream_client::{Environment, types::Message};
let environment = Environment::builder().build().await?;
let producer = environment.producer().name("myproducer").build("mystream").await?;
for i in 0..10 {
    producer
      .send(Message::builder().body(format!("message{}", i)).build())
      .await?;
}
producer.close().await?;
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?;

Development

Compiling

git clone https://github.com/rabbitmq/rabbitmq-stream-rust-client .
make build

Running Tests

To run tests you need to have a running RabbitMQ Stream node with a TLS configuration. It is mandatory to use make rabbitmq-server to create a TLS configuration compatible with the tests. See the Environment TLS tests for more details.

make rabbitmq-server
make test

Running Benchmarks

make rabbitmq-server
make run-benchmark

Dependencies

~2.4–3.5MB
~63K SLoC