async-nats 0.49.0

A async Rust NATS client
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use futures::StreamExt;

#[tokio::main]
async fn main() -> Result<(), async_nats::Error> {
    let nc = async_nats::connect("nats://localhost:4222").await?;

    // NATS-DOC-START
    //  Subscribe to the "weather.updates" subject
    let mut sub = nc.subscribe("weather.updates").await?;

    while let Some(msg) = sub.next().await {
        println!("Received: {}", String::from_utf8_lossy(&msg.payload));
    }
    // NATS-DOC-END

    Ok(())
}