natsclient

Crates.ionatsclient
lib.rsnatsclient
version0.0.7
sourcesrc
created_at2019-04-12 16:03:32.339176
updated_at2020-03-18 15:09:27.680848
descriptionNATS client designed for both an ergonomic API and performance
homepagehttps://github.com/encabulators/natsclient
repositoryhttps://github.com/encabulators/natsclient
max_upload_size
id127487
size100,714
Kevin Hoffman (autodidaddict)

documentation

https://docs.rs/natsclient

README

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:

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

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

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

To publish a message:

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

And to utilize the request/response pattern:

 let reply = client.request(
    "symbolquery",
    r#"{"symbol": "NATS"}"#.as_bytes(),
    Duration::from_millis(100),
)?;

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

Features

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

  • - Request/Reply
  • - Subscribe
  • - Publish
  • - All authentication models, including NATS 2.0 JWT and seed keys
  • - Adherance to protocol v1, accepts new server information whenever it's sent from NATS
  • - Automatic reconnect upon connection failure
  • - TLS support
  • - NATS Streaming (STAN)
Commit count: 0

cargo fmt