ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

OverviewRPC controllersStreamingClientDeadlinesServerLinksTCPUDPNATSRedisRabbitMQMQTTKafka

Integrations

Operating

Reference

Microservices

Server

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

ulo_rpc::Server::new(link) is the server for any link. It is attached to the app with bind after connect, and listen acquires the sockets or broker sessions.

use ulo_rpc::Server;
use ulo_rpc_tcp::Tcp;
use ulo_runtime_tokio::{Tokio, shutdown_signal};

let app = builder()
    .runtime(Tokio::current())
    .wire()?
    .connect()
    .await?
    .bind(Server::new(Tcp::new("127.0.0.1:7000")))
    .listen()
    .await?;
for bound in app.addresses() {
    println!("listening on tcp://{}", bound.addr);
}
app.serve(shutdown_signal()).await?;

This is examples/25-rpc-basics/src/main.rs, trimmed. Broker links report no address.

Limits

use ulo_rpc::config::{Bound, Count};

Server::new(Tcp::new("127.0.0.1:7000"))
    .max_inflight(Count::Max(256))
    .max_queued_items(Count::Max(64))
    .timeout_grace(Bound::After(Duration::from_secs(2)))

Count and Bound come from ulo_rpc::config.

SettingDefaultEffect
max_inflight(Count)1,024 callscalls running at once. Over the bound, a call is answered unavailable with a RetryAfter detail. Count::Unlimited removes the bound
max_queued_items(Count)1,024 itemsitems of one streamed request waiting for the handler to read them. The item past the limit ends that call with unavailable and the reason overflow
max_queued_bytes(u64)4 MiBthe encoded bytes of those waiting items. The item that would take them past it ends the call as an item past max_queued_items does. An item over the bound on its own ends the call bad_request with the reason payload_too_large. u64::MAX removes the bound
shed_retry_after(Duration)1 secondthe wait the RetryAfter detail asks of a caller refused over max_inflight, in whole seconds rounded up. An event over the bound gets none
timeout_grace(Bound)1 secondhow long error handlers may take with the Timeout a passed deadline offers them before the plain timeout error is sent

Two links apply max_inflight differently. RabbitMQ stops taking requests at the bound by setting its prefetch window, and Kafka pauses its partitions, so excess requests wait in the broker instead of being refused. Count::Unlimited leaves RabbitMQ a prefetch of 64. A queue is bounded by whichever of the two limits its next item passes first. Count::Unlimited on max_queued_items leaves max_queued_bytes alone bounding the queue, and removing both lets a client that sends faster than its handler reads grow the server's memory without limit.

What listen refuses

The server checks its configuration before it acquires anything and reports every problem together:

  • two handlers for one pattern,
  • a handler whose shape the link cannot carry, such as a streamed shape on UDP,
  • an #[event] handler with a streamed shape,
  • a handler with a binary payload on a link using the JSON codec,
  • max_inflight(Count::Max(0)), max_queued_items(Count::Max(0)), max_queued_bytes(0) and timeout_grace(Bound::After(Duration::ZERO)),
  • an event declared every_instance on a link whose caller names one server (TCP, UDP),
  • whatever the link finds wrong with its own settings: an unparsable endpoint, a TLS file that does not load, an empty group name, and on RabbitMQ a pattern whose queue or exchange name AMQP cannot carry (over 241 bytes, or 208 for an every_instance event).

A link built outside a tokio runtime and never given one fails here too, naming .with_handle(..). NATS, RabbitMQ and Kafka wait at listen for at most connect_within, 30 seconds unset, and fail with ConnectTimedOut when it runs out. On Kafka the bound covers the topics' creation, the starting commit and the assignment of the server's own consumers, the control topic's and the every-instance events'. A record produced to those topics after listen returns is read. Redis and MQTT have no connect_within.

A server on Redis, whose link delivers every request and every event left at one instance to every instance, logs one warning naming how many request patterns and how many one-instance event patterns it mounts.

Shutdown

serve(signal) runs until the signal resolves, then the app drains and closes. For RPC:

StepWhat happens
drainthe link stops taking new calls: TCP sends goaway on every connection, NATS drains, RabbitMQ cancels its consumers, Redis and MQTT unsubscribe and wait for the broker's acknowledgement, Kafka pauses its partitions
drain windowcalls in flight finish and streams end. A call arriving now is answered unavailable with the phrase "the server is shutting down"
window endscalls still running are cancelled with the reason Drain and answered unavailable
closethe link closes. The server logs, at warn, how many refusals or deliveries were left unanswered

A link can lose a request that is already on its way when the drain begins, and the caller then sees its own Timeout instead of Unavailable. NATS and UDP declare that their drain is unconfirmed in this way. Links lists which links hold unserved requests instead (RabbitMQ and Kafka keep them for the next instance).

A client built with RpcClientModule closes with the app. A client made with RpcClient::new closes its link when its last handle drops.

Wiring the shutdown signal itself is covered in Deployment.

Deadlines

How a caller's remaining time travels with an RPC call, and what the callee does when it runs out.

Links

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

On this page

LimitsWhat listen refusesShutdown