ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

OverviewRPC controllersStreamingClientDeadlinesServerLinksTCPUDPNATSRedisRabbitMQMQTTKafka

Integrations

Operating

Reference

Microservices

Links

The same handlers over TCP, UDP, NATS, Redis, MQTT, RabbitMQ and Kafka, and what differs between the links.

A link is the crate that carries RPC frames: Tcp, Udp, Nats, Redis, Mqtt, RabbitMq or Kafka. A link goes into Server::new(link) on the server and into RpcClient::new(link, runtime) or RpcClientModule::for_root(link) on the client. Controllers do not name a link.

examples/28-rpc-links serves the handlers of examples/25-rpc-basics over any of the six wire links, chosen by a URL scheme:

src/lib.rs
pub fn bind(app: App<Connected>, url: &str) -> Result<App<Connected>, Box<dyn Error + Send + Sync>> {
    let (scheme, address) = split(url)?;
    Ok(match scheme {
        "tcp" => app.bind(Server::new(Tcp::new(address))),
        "nats" => app.bind(Server::new(Nats::url(url))),
        "redis" => app.bind(Server::new(Redis::url(url))),
        "mqtt" => app.bind(Server::new(Mqtt::url(url))),
        "amqp" => app.bind(Server::new(RabbitMq::url(url))),
        "kafka" => app.bind(Server::new(Kafka::brokers(address))),
        other => return Err(unknown(other)),
    })
}
cargo test -p ex-28-rpc-links
RPC_LINK=nats://127.0.0.1:4222 cargo run -p ex-28-rpc-links

Without RPC_LINK the handlers listen on TCP at PORT. The broker tests start each broker in a container and need Docker:

cargo test -p ex-28-rpc-links --features integration --test brokers

Each link crate runs the same conformance suite from ulo-rpc-conformance, which is published. A behaviour listed on this page as common to all links is held by a test per link, and a link written elsewhere can run the same suite.

What every link does alike

  • Replies, handler errors with their kind and message, and events behave as in RPC controllers.
  • Failures a link can signal reach the caller as the same RpcError kinds (see Client).
  • Calls carry deadline-ms and streams carry cancel (see Deadlines).
  • A call refused because the server is draining is unavailable with the phrase "the server is shutting down".
  • The default codec is JSON. .codec(Codec::Cbor) selects CBOR and binary payloads on every link.

The frames are one grammar on every link. A request is req, an event evt, a reply res or err, a reply stream item then end, and a streamed request opens with open and continues with in and in_end. TCP, UDP and Redis carry whole frames. On NATS, RabbitMQ, MQTT and Kafka the payload is the message body, headers are the broker's headers, and the correlation is the broker's own. A request published by hand with a reply address therefore reaches a handler: nats req invoices.create '{..}'.

What differs

TCPUDPNATSRedisMQTTRabbitMQKafka
URL / constructorTcp::new(addr)Udp::new(addr)Nats::url("nats://..")Redis::url("redis://..")Mqtt::url("mqtt://..")RabbitMq::url("amqp://..")Kafka::brokers("host:9092")
Pattern isin the framein the framea subjecta channela topica queuea topic
Streamed shapesyesnoyesyesyesyesyes
Request delivery to instancesaddressedaddressedcompeting (queue group)every instancecompeting ($share)competingcompeting (consumer group)
Event delivery to instancesaddressedaddressedone (queue group)every instanceone ($share)one (queue)one (consumer group)
Event declared every_instancerefused at listenrefused at listenevery instanceevery instanceevery instanceevery instanceevery instance
Orderper connectionnoneper publisher and subjectper channelper topic and QoSper queueper partition
Request guaranteeconnectionnoneat most onceat most onceby QoS (1 by default)at least once, ack after the handleroffset stored after the handler
Largest frame1 MiB, max_frame65,507 bytesthe server's max payloadnone declaredCONNACK max packetnone declared1,000,000 bytes
TLS.tls(Tls) on the servernonetls://rediss://, feature tlsmqtts://amqps://ssl://, feature tls
Unhandled patternunavailable, pattern_unhandledunavailable, pattern_unhandledunavailable, no_destinationunavailable, no_destinationunavailable, no_destination at QoS 1 and 2unavailable, no_destination unless the queue existscaller Timeout
Drain is confirmedyesnonoyesyesyesnothing to confirm

A pattern nothing handles

The caller's error depends on whether the link can tell. TCP and UDP answer from the server. A broker routes by subscription. A request for an unhandled pattern never reaches this server, and the client maps the broker's "no destination" signal to the same kind:

  • NATS: a no-responders status.
  • Redis: a PUBLISH receiver count of zero.
  • MQTT: a PUBACK or PUBREC with reason code 0x10 at QoS 1 and 2. At QoS 0 nothing is acknowledged, so the caller sees its own Timeout.
  • RabbitMQ: a returned mandatory publish, for a pattern whose queue no server ever declared. A queue outlives its server, so a request for a pattern that was once served waits in the queue for the next instance and the caller sees its own Timeout.
  • Kafka: nothing signals the miss. With the broker's auto.create.topics.enable on, the default, a publish to an unhandled pattern creates the topic and the caller waits out its Timeout.

Where the miss is the caller's own Timeout, only the link's declaration shows the difference: RabbitMQ and Kafka hold requests that arrive while no instance is consuming (the unserved_hold capability), and the next instance runs them.

Delivery to two instances

With two instances of one application on a broker, a request should run once, and so should an event.

  • TCP and UDP are addressed: the caller names the server.
  • NATS subscribes through a queue group and MQTT through a shared subscription $share/<group>/<topic>. RabbitMQ queues and Kafka consumer groups compete by construction. The group defaults to the application's root module's full type path and .group(..) overrides it on NATS, MQTT and Kafka. Two instances of one application share a group, and two different applications on one broker never compete for each other's patterns.
  • Redis Pub/Sub has no competing mode. Every server instance subscribed to a pattern runs a request's handler, and the client drops all but the first reply. Redis therefore supports one server instance for requests and for events left at the default, and the server logs a warning when it mounts either on it.

An event reaches one instance unless its handler is declared #[ulo_rpc::event("pattern", every_instance)], for a cache invalidation or a configuration reload. Such an event reaches every instance on NATS (a plain subscription), MQTT (a plain topic filter), RabbitMQ (a queue of the instance's own on the pattern's fanout exchange), Kafka (a consumer of the instance's own, outside the group) and Redis. TCP and UDP refuse the declaration when the server prepares, because the caller names one server.

Shapes and events

UDP is unary-only: a server that mounts a handler with a streamed shape is refused at listen, and a client refuses a streamed call before any I/O with Unimplemented and the reason shape_unsupported. A stream call is refused too, although a unary handler would answer it with one reply: request is the call for that. Every other link carries all four shapes. A streamed request on a broker opens with an empty body and a header ulo-t: open; the server answers ulo-t: opened before the caller sends anything more. The items, the end and any cancel travel on a control channel every instance reads (ulo.rpc.control on NATS, RabbitMQ and Kafka, ulo/rpc/control on MQTT, ulo:rpc:control on Redis).

Per-link pages

  • TCP and UDP: no broker.
  • NATS, Redis, MQTT, RabbitMQ, Kafka: connection settings and behaviour specific to each broker.

Server

Binding an RPC server to a link, its limits, what it refuses at startup, and how it drains.

TCP

The TCP link, frames multiplexed over one connection, with a tokio and a smol implementation.

On this page

What every link does alikeWhat differsA pattern nothing handlesDelivery to two instancesShapes and eventsPer-link pages