AMQP bindings
With the asyncapi feature the generated document speaks AMQP 0.9.1: the server, the queue behind each channel and the properties of each send.
The core builds the AsyncAPI document from the app, before anything connects.
This crate adds the specification's amqp binding, version 0.3.0, to the parts it knows about.
The server reports the host and the AMQP version.
A channel reports the queue behind a subscription, or the exchange a publish leaves through.
An operation reports how a receive settles and which properties a send carries.
The exchanges a queue is bound to ride the crate's own extension, x-ruststream-amqp.
Everything comes from the service's own declarations: the broker, the queue descriptors and the publish policies.
The document is published and shared, so no binding carries a credential.
The binary #[ruststream::app] writes prints the document with asyncapi gen.
Example
The dependency line:
ruststream-lapin = { version = "0.7", features = ["asyncapi"] }
The service registers its broker under the label rabbit, the key of its server in the document.
cargo run --example lapin_asyncapi --features asyncapi -- asyncapi gen prints the document.
- Macros
- Manual
fn service(broker: LapinBroker) -> RustStream {
let inventory = AppInfo::new("inventory", "1.0.0");
RustStream::new(inventory).with_broker_labeled("rabbit", broker, |b| {
b.include(check)
.max_attempts(nonzero!(3u32))
.dead_letter("inventory.dead")
.out_reply(Publish::default().exchange("answers"))
.transform(DirectReplyTo);
b.include(on_event)
.out(
Restocks,
Publish::default()
.priority(4)
.expiration(Duration::from_secs(30)),
)
.build();
})
}
#[ruststream::app]
fn app() -> RustStream {
let password = env::var("AMQP_PASSWORD").unwrap_or_default();
service(broker(&password))
}
fn service(broker: LapinBroker) -> RustStream {
let inventory = AppInfo::new("inventory", "1.0.0");
RustStream::new(inventory).with_broker_labeled("rabbit", broker, |b| {
let check = subscriber(checks(), Check).reply().to("inventory.unrouted");
b.include(check.build())
.max_attempts(nonzero!(3u32))
.dead_letter("inventory.dead")
.out_reply(Publish::default().exchange("answers"))
.transform(DirectReplyTo);
b.include(subscriber(events(), OnEvent).build())
.out(
Restocks,
Publish::default()
.priority(4)
.expiration(Duration::from_secs(30)),
)
.build();
})
}
fn app() -> RustStream {
let password = env::var("AMQP_PASSWORD").unwrap_or_default();
service(broker(&password))
}