#nats #extension #api-bindings #extra #messaging-api

nats-extra

Set of utilities and extensions for the Core NATS of the async-nats crate

3 releases (breaking)

Uses new Rust 2024

0.3.0 Aug 28, 2025
0.2.0 Jan 9, 2025
0.1.0 Nov 20, 2024

#9 in #extra

Download history 110/week @ 2025-08-25 13/week @ 2025-09-01 1/week @ 2025-09-08 5/week @ 2025-09-29 2/week @ 2025-10-06

117 downloads per month

Apache-2.0

18KB
189 lines

nats-extra

License Apache 2 Crates.io Documentation Build Status

Set of utilities and extensions for the Core NATS of the async-nats crate.

Request Many

Request many pattern implementation useful for streaming responses and scatter-gather pattern.

Complete example

Connect to NATS server, and extend the async-nats::Client with the request_many capabilities.

use async_nats::Client;
// Extend the client with request_many.
use nats_extra::request_many::RequestManyExt;
use futures::StreamExt;

#[tokio::main]
async fn main() -> Result<(), async_nats::Error> {
    let client = async_nats::connect("demo.nats.io").await?;

    let mut requests = client.subscribe("requests").await?;

    let mut responses = client
        .request_many()
        .send("requests", "payload".into())
        .await?;

    let request = requests.next().await.unwrap();
    for _ in 0..100 {
        client.publish(request.reply.clone().unwrap(), "data".into()).await?;
    }

    while let Some(message) = responses.next().await {
        println!("Received: {:?}", message);
    }
    Ok(())
}

Dependencies

~22–38MB
~622K SLoC