| Crates.io | nats-extra |
| lib.rs | nats-extra |
| version | 0.3.0 |
| created_at | 2024-11-20 12:16:24.352393+00 |
| updated_at | 2025-08-28 10:46:41.271611+00 |
| description | Set of utilities and extensions for the Core NATS of the async-nats crate |
| homepage | https://github.com/synadia-io/orbit.rs |
| repository | https://github.com/synadia-io/orbit.rs |
| max_upload_size | |
| id | 1454748 |
| size | 63,221 |
Set of utilities and extensions for the Core NATS of the async-nats crate.
Request many pattern implementation useful for streaming responses and scatter-gather pattern.
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(())
}