Expand description
A client for NATS using
tokio and async-await.
There are still features missing, but it should be ready for use in simple situations.
§Installation
[dependencies]
tokio-nats = "0.4.2"§Usage
use tokio_nats::{NatsConfigBuilder, connect};
use futures_util::StreamExt;
async fn demo() {
let config = NatsConfigBuilder::default()
.server("127.0.0.1:4222")
.build()
.unwrap();
let mut client = connect(config).await.unwrap();
client.publish("MySubject", "hello world".as_bytes()).await.unwrap();
client.subscribe("MyOtherSubject").await.unwrap().for_each(|message| async move {
println!("Received message {:?}", message);
}).await;
}Structs§
- Nats
Client - A handle to a NATS connection, which allows subscribing and publishing messages.
- Nats
Config - Configuration used in creating a NATS connection
- Nats
Config Builder - Builder for
NatsConfig. - Nats
Message - A message that has been received by the NATS client.
- Nats
Subscription - A stream corresponding to a specific NATS subscription.
- TLSConn
Build - TlsConn
Params
Enums§
Functions§
- connect
- Make a new NATS connection. Return a
NatsClientwhich can be cloned to obtain multiple handles to the same connection.