Skip to content
/ hare Public

Streamlined and production ready RabbitMQ experience in Rust. Comfortably define consumers by utilizing the extractor pattern. Don't worry about concurrency, graceful shutdowns or connection handling.

License

Notifications You must be signed in to change notification settings

mzndr/hare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hare

hare is a RabbitMQ client that focuses on providing an ergonomic, streamlined, easy to setup and production ready RabbitMQ experience.

This repo is still under construction.

Features

  • Connection pooling using deadpool
  • Easy consumer concurrency
  • Consume any data in consumers using the extractor pattern

Quickstart

/// Some shared state between `consumers`. Great
/// for passing database clients or the application config.
struct State {
    pub db: SomeClient,
}

/// The message payload to be extracted from the incoming message.
#[derive(serde::Deserialize)]
struct IncomingMsgPayload {
    pub foo: String
}

/// Consumes messages.
async fn consumer_handler(
    Json(event): Json<request::Event>, // Consumer parameters are very flexible due to the extractor pattern.
    State(state): State,
) -> Result<(), anyhow::Error> {
    // Do something..
}


#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create the client.
    let rabbitmq_client = hare::Client::new(
        "amqp://guest:guest@localhost:5672",
        hare::lapin::ConnectionProperties::default(),
        "example app",
        State::new(&db),
    )
    .await?;

    let exchange_name = "example_exchange";

    // Declare an `exchange` using the exchange declare builder.
    rabbitmq_client.exchange_declare_builder(exchange_name, hare::lapin::ExchangeKind::Topic)
        .auto_delete(true)
        .declare()
        .await?;

    // Declare a `queue` using the queue declare builder.
    let queue = rabbitmq_client
        .queue_declare_builder("example_queue")
        .auto_delete(true)
        .declare()
        .await?;

    // Declare a `consumer` and set it to consume from the `queue`.
    rabbitmq_client
        .basic_consume_builder(&queue, "example_consumer")
        .consume(consumer_handler)
        .await?;

    // Bind the `queue` to the `exchange`.
    rabbitmq_client
        .queue_bind_builder(&queue, exchange_name, "example.routing_key")
        .bind()
        .await?;

    // Run the client and wait for all consumers to be finished.
    rabbitmq_client.run().await?;
}

About

Streamlined and production ready RabbitMQ experience in Rust. Comfortably define consumers by utilizing the extractor pattern. Don't worry about concurrency, graceful shutdowns or connection handling.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages