Microservices
RabbitMQ
The RabbitMQ link, a queue per pattern with reply_to, correlation_id and publisher confirms.
The RabbitMQ link speaks AMQP 0-9-1. Each pattern is a queue. A request reaches it through the default exchange and an event through the pattern's fanout exchange ulo.rpc.event.<pattern>. The payload is the body with AMQP headers, and replies come back through RabbitMQ's direct reply-to using reply_to and correlation_id.
app.bind(ulo_rpc::Server::new(ulo_rpc_rabbitmq::RabbitMq::url("amqp://guest:guest@mq:5672/%2f")));Settings
| Method | Effect |
|---|---|
RabbitMq::url(url) | amqp:// or amqps:// |
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 broker. 30 seconds unset. A wait that runs out fails with ConnectTimedOut |
with_handle(Handle) | the tokio runtime, when the link is built outside one |
A server's listen needs the app's Timer.
Behaviour
- Handlers must be idempotent. Delivery is at least once: the ack is sent after the handler completes, so a request delivered again after a failure runs again. An unhandled event is rejected without requeue.
- In-flight limit. One prefetch window serves every pattern and follows the server's
max_inflight(1,024 unset, 64 underCount::Unlimited). A request over the bound waits in its queue instead of being refused. - Misses. The client publishes in confirm mode, a request with
mandatory. A pattern whose queue no server ever declared is returned by the broker and maps tounavailablewith the reasonno_destination. - Queues outlive servers. A queue is neither auto-delete nor exclusive. A request sent while no instance is consuming waits in the queue for the next one, and its caller sees its own
Timeout. The link holds unserved requests (theunserved_holdcapability). - Events. An event is published to the fanout exchange
ulo.rpc.event.<pattern>, which is bound to the pattern's shared queue, so one instance handles it. An event declared#[ulo_rpc::event("pattern", every_instance)]goes instead to an exclusive auto-delete queue of each instance's own,ulo.rpc.event.<pattern>.<uuid>, bound to the same exchange. Every running instance handles it, and an event emitted while none runs reaches none. - Name limits. AMQP caps an exchange name, a queue name, a routing key and a header name at 255 bytes. The link serves a pattern of at most 241 bytes, whose event exchange is then 255, and an
every_instanceevent on a pattern of at most 208. A server refuses a longer pattern when it prepares, with one configuration failure naming each pattern, its length and the limit. A client fails a call before publishing when an exchange name, routing key or header name would pass the limit, withBadRequestand the reasonname_too_long. The connection carries the frames after it. - Servers before clients. A client declares the pattern's exchange and publishes each event to it, and a queue is bound to the exchange once a server has declared the pattern. Until then the broker drops the client's events with no error at the client. Start the servers first. A server of
ulo-rpc-rabbitmq0.1.0-alpha.2 or earlier binds no queue to that exchange. - Ordering. Per queue, with a single consumer.
- Lost connection. A call waiting when the client's connection drops fails
Unavailable, since a direct reply-to address dies with its channel. - Streams. A streamed request opens with
ulo-t: openand is answeredulo-t: opened. Items, end andcanceltravel through the fanout exchangeulo.rpc.control, which binds one queue per server instance. - Drain. The server cancels its consumers (
basic.cancel) and waits for each acknowledgement. - Connect limit. lapin cannot stop a connection that has not finished connecting. A
listenthat runs out against a broker that accepts the socket and never answers the handshake leaves one I/O thread and one socket until the process exits, so a supervisor retrying the start in-process against a silent broker leaks one of each per attempt.