ruststream-nats connects a RustStream service to NATS over
async-nats. Handlers, routing, codecs and middleware come
from the framework; this crate is the transport.
Features
- Core NATS and JetStream:
CoreSubjectandCoreWildcardfor subjects and patterns with queue groups,JetStreamSubjectfor a stream read through a pull consumer. - Batches on either transport: a JetStream pull batch, or batches assembled on the client for Core NATS.
- Native JetStream acknowledgement, delayed redelivery included; Core NATS reports that it has none.
- Two publishers: Core NATS with request/reply, and JetStream with the stream's acknowledgement and per-message deduplication ids and position expectations.
- AsyncAPI with the specification's
natsbinding, behind theasyncapifeature. - Tests run the production app:
TestApp::start(app())connectsNatsBrokerin process, with no server.
Install
[]
= { = "0.7", = ["macros", "json"] }
= "0.7"
= { = "1", = ["derive"] }
[]
= { = "0.7", = ["testing"] }
Add the asyncapi feature to fill the generated document with NATS's own vocabulary.
Write a service
use *;
use ;
async
#[ruststream::app] generates main, so the binary understands run and asyncapi gen.
Scaffold a fresh project from a template, Core NATS or a durable JetStream consumer:
Test it
The app main runs, handed to the harness unchanged: TestApp::start connects NatsBroker in
process, with no server, and the test addresses it by that type.
use TestApp;
let tb = start.await?;
// `publish` returns once the handlers it woke have settled.
tb.
.message
.to
.publish
.await?;
tb.
.subscriber
.assert_called_once
.settled;
tb.
.
.assert_called_once;
TestApp::start_live(app()) runs the same test against a running server (just test-brokers).
Documentation
- Getting started - installation and a first service against a local NATS server.
- Guides - subjects and queue groups, streams and consumers, acknowledgement, publishing to streams, retries, request-reply, testing and a production cluster.
- Components - one page per part of the crate: the broker, subscriptions, settlement, the JetStream context, publishing, request-reply, AsyncAPI and testing.
- Architecture - how the crate sits between
async-natsand the runtime. - Benchmarks - what the crate costs over the raw client.
- API reference - every item on docs.rs.
- The framework: https://powersemmi.github.io/ruststream/latest/
Minimum supported Rust version
The MSRV is 1.95, edition 2024.
Contributing
See CONTRIBUTING.md.
License
Licensed under the Apache-2.0 license.