Status
Motivation
Rust may be one the most interesting new languages the NATS ecosystem has seen. We believe this client will have a large impact on NATS, distributed systems, and embedded and IoT environments. With Rust we wanted to be as idiomatic as we could be and lean into the strengths of the language. We moved many things that would have been runtime checks and errors to the compiler, most notably options on connections, and having subscriptions generate multiple styles of iterators, since iterators are a first class citizen in Rust. We also wanted to be aligned with the NATS philosophy of simple, secure, and fast!
Feedback
We encourage all folks in the NATS and Rust ecosystems to help us
improve this library. Please open issues, submit PRs, etc. We're
available in the rust
channel on the NATS slack
as well!
Example Usage
> cargo run --example nats-box -- -h
Basic connections, and those with options. The compiler will force these to be correct.
#
This will attempt to bind to an existing consumer if it exists, otherwise it will create a new internally managed consumer resource that gets destroyed when the subscription is dropped.
Minimum Supported Rust Version (MSRV)
The minimum supported Rust version is 1.53.0.
Sync vs Async
The Rust ecosystem has a diverse set of options for async programming. This client library can be used with any async runtime out of the box, such as async-std and tokio.
The async interface provided by this library is implemented as just a thin wrapper around its sync interface. Those two interface styles look very similar, and you're free to choose whichever works best for your application.
NOTE: This crate uses thread pool from blocking crate. By default it limits number of threads to 500. It can be ovverided by setting BLOCKING_MAX_THREADS
environment variable and set between 1 and 10000. Be careful when spinning a lot async operations, as it may drain the thread pool and block foverer until it's reworked
Features
The following is a list of features currently supported and planned for the near future.
- Basic Publish/Subscribe
- Request/Reply - Singelton and Streams
- Authentication
- Token
- User/Password
- Nkeys
- User JWTs (NATS 2.0)
- Reconnect logic
- TLS support
- Direct async support
- Crates.io listing
- Header Support
Miscellaneous TODOs
- Ping timer
- msg.respond
- Drain mode
- COW for received messages
- Sub w/ handler can't do iter()
- Backup servers for option
- Travis integration