跳到主要内容
本页尚未翻译

下面显示的是英文原文。

NATS bindings

With the asyncapi feature the generated document speaks NATS: the server, the queue group of each operation, the JetStream settings of each channel.

The core builds the AsyncAPI document from the app, before anything connects. This crate fills in what only NATS knows. The server is the host and port of each configured address. A receive operation reports its queue group in the specification's nats binding, version 0.1.0. A channel read by a JetStream consumer, or written by a publisher that requires a stream, reports those settings under x-ruststream-jetstream. A reply answered on the request's inbox reports the header its address travels in.

The specification's nats binding has one field, the queue group, and JetStream has no binding of its own. So the JetStream settings travel under an extension key, which carries no bindingVersion. A subscription or a publisher with nothing to report adds nothing, not an empty object.

Everything comes from the service's own declarations: the broker, the descriptors, the publish policies and the destinations the mount sites resolved. The document is published and shared, so no part of it carries a credential. The binary #[ruststream::app] writes prints the document with asyncapi gen.

Example​

The dependency line:

ruststream-nats = { version = "0.7", features = ["asyncapi"] }

The service registers its broker under the label nats, the key of its server in the document. cargo run --example nats_asyncapi --features asyncapi -- asyncapi gen prints the document.

fn service(broker: NatsBroker) -> impl App<State = ()> {
RustStream::new(AppInfo::new("orders", "1.0.0")).with_broker_labeled("nats", broker, |b| {
b.include(confirm);
b.include(archive);
b.include(issue)
.out_reply(JetStreamPublish::default().expect_stream("RECEIPTS"));
b.include(quote).out_reply(Publish).transform(ReplyTo);
})
}

#[ruststream::app]
fn app() -> impl App<State = ()> {
let password = env::var("NATS_PASSWORD").unwrap_or_default();
service(broker(&password))
}