Перейти к основному содержимому
Эта страница ещё не переведена

Ниже показан английский оригинал.

Server

RustStream::server declares a server the document lists, from a ServerSpec that says how clients reach the broker.

server is for a broker no registration of the process describes, or to replace what a labeled broker says. The name is the server's key in the document. ServerSpec::new takes the host and the protocol. ServerSpec::from_url takes a broker URL and keeps only its host and port, so credentials in the URL never reach the document, which is published. protocol_version names the version clients speak, where one protocol name covers incompatible versions, as AMQP 0.9.1 and 1.0 do. description adds a note for the reader. A server spec holds coordinates, never configuration. How clients authenticate is security, and what the protocol adds is bindings. The example runs with cargo test --example asyncapi_servers --features macros,memory,asyncapi.

Example​

/// The cluster the service is deployed against, as its clients reach it.
fn production() -> ServerSpec {
ServerSpec::new("kafka.example.com:9093", "kafka")
.protocol_version("3.9")
.description("The production cluster")
}
fn app() -> Result<impl App, BindingError> {
let production = with_registry(secured(production()))?;
Ok(RustStream::new(AppInfo::new("orders", "0.1.0"))
// Declared: no broker of this process describes the cluster.
.server("production", production)
// Described by the broker itself, under its label.
.with_broker_labeled("in-process", MemoryBroker::new(), |b| {
b.include(accept);
}))
}