Expand description

A Rust async bleeding edge client for the NATS.io ecosystem.

git clone https://github.com/nats-io/nats.rs

NATS.io is a simple, secure and high performance open source messaging system for cloud native applications, IoT messaging, and microservices architectures.

For sync API refer to the [https://crates.io/crates/nats]

For more information see https://nats.io/.

Examples

Complete example

use bytes::Bytes;
use futures_util::StreamExt;

#[tokio::main]
async fn example() {
    let mut client = async_nats::connect("demo.nats.io").await.unwrap();
    let mut subscriber = client.subscribe("foo".into()).await.unwrap();

    for _ in 0..10 {
        client.publish("foo".into(), "data".into()).await.unwrap();
    }

    let mut i = 0;
    while subscriber.next()
        .await
        .is_some()
    {
        i += 1;
        if i >= 10 {
            break;
        }
    }
    assert_eq!(i, 10);
}

Publish


let mut client = async_nats::connect("demo.nats.io").await?;

let subject = String::from("foo");
let data = Bytes::from("bar");
for _ in 0..10 {
    client.publish("subject".into(), "data".into()).await?;
}

Subscribe


let mut client = async_nats::connect("demo.nats.io").await?;

let mut subscriber = client.subscribe("foo".into()).await.unwrap();

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

Re-exports

pub use tokio_rustls::rustls;

Structs

Connect options.

Address of a NATS server.

Information sent by the server back to this client during initial connection, and possibly again later.

Enums

ClientOp represents all actions of Client.

Protocol version used by the client.

Traits

Capability to convert into a list of NATS server addresses.

Functions

Type Definitions