travis  license

NATS Client

A simple, developer-friendly NATS client designed with an ergonomic API designed to allow you to use this client anywhere, whether you're using tokio or single-threaded apps or traditional multi-threaded.

Usage

The following sample illustrates basic publish and subscribe features:

```rust let jwt = "..."; let seed = "...";

let opts = ClientOptions::builder() .clusteruris(vec!["nats://localhost:4222".into()]) .authentication(AuthenticationStyle::UserCredentials( jwt.tostring(), seed.to_string(), )) .build()?;

let client = Client::from_options(opts)?; client.connect()?;

client.subscribe("ticker", move |msg| { let symbol: SymbolReply = serdejson::fromslice(&msg.payload).unwrap(); info!("Received stock ticker: {:?}", symbol); Ok(()) })?; ```

To publish a message:

rust c.publish(&r, payload_bytes, None)?;

And to utilize the request/response pattern:

```rust let reply = client.request( "symbolquery", r#"{"symbol": "NATS"}"#.asbytes(), Duration::frommillis(100), )?;

let symbol: SymbolReply = serdejson::fromslice(&reply.payload).unwrap(); info!("Stock symbol response: {:?}", symbol); ```

Features

The following is a list of features currently supported and planned by this client: