Expand description
A Rust async bleeding edge client for the NATS.io ecosystem.
git clone https://github.com/nats-io/nats.rs
NATS.io is a simple, secure and high performance open source messaging
system for cloud native applications, IoT
messaging, and microservices
architectures.
For sync API refer https://crates.io/crates/nats
For more information see https://nats.io/.
§Examples
Below you can find some basic examples how to use this library.
For details, refer docs for specific method/struct.
§Complete example
use bytes::Bytes;
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), async_nats::Error> {
let client = async_nats::connect("demo.nats.io").await?;
let mut subscriber = client.subscribe("messages".into()).await?.take(10);
for _ in 0..10 {
client.publish("messages".into(), "data".into()).await?;
}
while let Some(message) = subscriber.next().await {
println!("Received message {:?}", message);
}
Ok(())
}
§Publish
let client = async_nats::connect("demo.nats.io").await?;
let subject = String::from("foo");
let data = Bytes::from("bar");
for _ in 0..10 {
client.publish("subject".into(), "data".into()).await?;
}
§Subscribe
let client = async_nats::connect("demo.nats.io").await?;
let mut subscriber = client.subscribe("foo".into()).await.unwrap();
while let Some(message) = subscriber.next().await {
println!("Received message {:?}", message);
}
Re-exports§
pub use header::HeaderMap;
pub use header::HeaderName;
pub use header::HeaderValue;
pub use message::Message;
pub use status::StatusCode;
pub use tokio_rustls::rustls;
Modules§
- NATS Message headers, leveraging http::header crate.
- JetStream is a NATS built-in persistence layer providing Streams with at least once and exactly once semantics.
- A Core NATS message.
- NATS status codes.
Structs§
- Error report from signing callback.
- Client is a
Cloneable
handle to NATS connection. Client should not be created directly. Instead, one of two methods can be used: crate::connect and crate::ConnectOptions::connect - Info to construct a CONNECT message.
- Connect options. Used to connect with NATS when custom config is needed.
- An error returned from the
Client::publish
,Client::publish_with_headers
,Client::publish_with_reply
orClient::publish_with_reply_and_headers
functions. - Used for building customized requests.
- Address of a NATS server.
- Information sent by the server back to this client during initial connection, and possibly again later.
- Retrieves messages from given
subscription
created by Client::subscribe.
Enums§
ClientOp
represents all actions ofClient
.- Protocol version used by the client.
Traits§
- Capability to convert into a list of NATS server addresses.
Functions§
- Connects to NATS with default config.
- Connects to NATS with specified options.