#nats #streaming #client #stan

bin+lib stan

NATS Streaming client based on official NATS rust client

16 releases

0.0.16 Mar 21, 2021
0.0.15 Mar 18, 2021
Download history 68/week @ 2021-03-08 153/week @ 2021-03-15 54/week @ 2021-03-22 53/week @ 2021-03-29 17/week @ 2021-04-05 38/week @ 2021-04-12 40/week @ 2021-04-19 1/week @ 2021-04-26 16/week @ 2021-05-03 2/week @ 2021-05-10 32/week @ 2021-05-17 17/week @ 2021-06-07

147 downloads per month


601 lines

License Apache 2 Crates.io Documentation Build Status


NATS Streaming client wrapper built on top of NATS.rs


use nats;
use std::{io, str::from_utf8, time};

fn main() -> io::Result<()> {
    let nats_url = "nats://";
    let nc = nats::connect(nats_url)?;
    let sc = stan::connect(nc, "test-cluster", "rust-client-1")?;

    sc.publish("foo", "hello from rust 1")?;

    sc.subscribe("foo", Default::default())?
        .with_handler(|msg| {
            println!("sub 1 got {:?}", from_utf8(&msg.data));

    let sub = sc
            stan::SubscriptionConfig {
                queue_group: Some("queue-group-name"),
                durable_name: Some("my-durable-queue"),
                start: stan::SubscriptionStart::AllAvailable,
        .with_handler(|msg| {
            println!("sub 2 got {:?}", from_utf8(&msg.data));
            println!("manually acked!");

    for msg in sc.subscribe("foo", Default::default())?.messages() {
        println!("sub 3 got {:?}", from_utf8(&msg.data));
        break; // just break for the example to run

    for msg in sc
        .subscribe("foo", Default::default())?
        println!("sub 4 got {:?}", from_utf8(&msg.data));
        break; // just break for the example to run

    sc.publish("foo", "hello from rust 2")?;
    sc.publish("foo", "hello from rust 3")?;


    sc.publish("foo", "hello from rust 4")?;


We were interested in at-least-once delivery with NATS, and the options here today are NATS Streaming, Lightbridge or Jetstream.

Jetstream is the future of at-least-once delivery on NATS, but is still in development, while NATS Streaming has been battle tested in production.

At the same time, the NATS team is providing an awesome rust client that also has support for Jetstream, but they are not planning on supporting NATS Streaming (reasonable since Jetstream is their main focus).

Since NATS Streaming is just a layer on top of NATS, this library was written to just wrap the nats.rs client to handle the NATS Streaming protocol, for those like us stuck with NATS Streaming.


nats = "0.9.7"
stan = "0.0.16"


To start a local nats streaming server:

docker run -p 4222:4222 -p 8222:8222 nats-streaming

Running tests require docker. To run the tests:

cargo test


~357K SLoC