1 unstable release
Uses old Rust 2015
0.1.0 | May 30, 2016 |
---|
#35 in #nats
60KB
1.5K
SLoC
nats-rs
Still very much a work in progress
NATS client for Rust
Usage
Connecting
let mut conn = NatsConn::new(Config::default()).unwrap();
Subscribing
let channel_sub = conn.subscribe_channel("subject", Some("queue")).unwrap();
let message = channel_sub.receiver.recv().unwrap();
let async_sub = conn.subscribe_async("subject", None, move |message| {
println!("received message");
}).unwrap();
Publishing
conn.publish("subject", Some("reply"), b"data").unwrap();
let msg = Message {
// contents
}
conn.publish_message(msg).unwrap();
Unsubscribing
conn.unsubscribe(&sub).unwrap();
conn.auto_unsubscribe(&sub, 3).unwrap();
Requests
let msg = conn.request("subject", b"data").unwrap();
TLS
let mut ssl_context = SslContext::new(SslMethod::Tlsv1_2).unwrap();
let path = Path::new("certs/ca.pem");
ssl_context.set_CA_file(&path).unwrap();
let config = config::Config {ssl_context: Some(ssl_context), ..Default::default()};
let mut conn = connection::NatsConn::new(config).unwrap();
Dependencies
~4–5MB
~125K SLoC