Microservices
NATS
The NATS link, queue-group subscriptions, inbox replies and no-responders.
The NATS link publishes each request on a subject named by the pattern, with a reply subject in the _INBOX, and answers on that inbox.
app.bind(ulo_rpc::Server::new(ulo_rpc_nats::Nats::url("nats://bus:4222")));Because the payload is the message body and headers are NATS headers, a request made by hand reaches a handler: nats req invoices.create '{..}'. A body arriving with no reply subject is an event.
Settings
| Method | Effect |
|---|---|
Nats::url(url) | nats:// or tls:// |
group(name) | the queue group. Defaults to the application's root module's full type path, so instances of one application share it |
codec(Codec) | JSON by default; Codec::Cbor carries raw bytes |
connect_within(Duration) | how long a server's listen and a client's connect wait for the server's INFO. 30 seconds unset. A wait that runs out fails with ConnectTimedOut |
roots_timeout(Bound) | how long to wait for the platform's root certificates to load. 30 seconds unset |
with_handle(Handle) | the tokio runtime, when the link is built outside one |
Behaviour
- Delivery. Requests and events reach one instance of the queue group. An event declared
#[ulo_rpc::event("pattern", every_instance)]is subscribed through a plain subscription and reaches every instance. NATS is at most once, and ordered per publisher and subject. The largest frame is the server's maximum payload, read from itsINFO. - Misses. A request for a subject nobody subscribes to is answered by NATS's no-responders status, which the client maps to
unavailablewith the reasonno_destination. - Lost connection. A call waiting when the client's connection drops fails
Unavailable: async-nats resubscribes the inbox, but what was published to it meanwhile is gone. - TLS.
tls://selects TLS, and anats://server that requires it upgrades the connection. Both trust the platform's root certificates. The process reads them once while any link holds them and writes them to one PEM file in the OS temp directory, which is removed when the last link and connection holding it drop it. A process killed first leaves that one file, uniquely named and holding public data. - Streams. A streamed request opens with an empty body and the header
ulo-t: open. The server answersulo-t: openedon the reply subject, and the items, end andcanceltravel onulo.rpc.control, which every instance reads. - Drain. NATS's drain protocol is used, and async-nats ends it without waiting for the server to stop routing. A request routed to the draining instance in between can be lost, and its caller sees its own
Timeout.