Crates.io | natsclient |
lib.rs | natsclient |
version | 0.0.7 |
source | src |
created_at | 2019-04-12 16:03:32.339176 |
updated_at | 2020-03-18 15:09:27.680848 |
description | NATS client designed for both an ergonomic API and performance |
homepage | https://github.com/encabulators/natsclient |
repository | https://github.com/encabulators/natsclient |
max_upload_size | |
id | 127487 |
size | 100,714 |
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.
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);
The following is a list of features currently supported and planned by this client: