Crate rants[][src]

Expand description

An async NATS client library for the Rust programming language.

The client aims to be an ergonomic, yet thin, wrapper over the NATS client protocol. The easiest way to learn to use the client is by reading the NATS client protocol documentation. The main entry point into the library’s API is the Client struct.

TLS support is powered by the native-tls crate.


use futures::stream::StreamExt;
use rants::Client;

// A NATS server must be running on ``
let address = "".parse().unwrap();
let client = Client::new(vec![address]);

// Configure the client to receive messages even if it sent the message

// Connect to the server

// Create a new subject called "test"
let subject = "test".parse().unwrap();

// Subscribe to the "test" subject
let (_, mut subscription) = client.subscribe(&subject, 1024).await.unwrap();

// Publish a message to the "test" subject
   .publish(&subject, b"This is a message!")

// Read a message from the subscription
let message = subscription.recv().await.unwrap();
let message = String::from_utf8(message.into_payload()).unwrap();
println!("Received '{}'", message);

// Disconnect from the server


nats Error and Result


An address used to connect to a NATS server

The entry point to the NATS client protocol

A type for returning a reference to data behind Client’s internal mutex

A type for returning a mutable reference to data behind Client’s internal mutex

The CONNECT message sent by the client

The INFO message sent by the server

Receives values from the associated Sender.

Sends values to the associated Receiver.

The MSG message sent by the server

A subject to publish or subscribe to

A subscription to receive messages from a particular Subject

Receives values from the associated Sender.


The methods of client authorization set in the Connect message

Client states

The -ERR messages sent from the server


Type Definitions

The type used for subscription IDs