Skip to main content

Lifecycle

AmqpBroker::new records configuration, connect opens the connection and the publishers' session, startup attaches each subscription, and shutdown runs inwards.

The broker's states as types, and what each transition does on the wireBrokerOn the wireAmqpBroker::new(url)ConnectedAmqpBrokerShut down:Ok(()) or theinnermost errorRecords the URL,SASL, container id;no I/OSocket, TLS, SASL,open, and thepublishers' sessionPer subscription:a session, a receiverand its pump taskThe first publishto an address attachesits sender linkPumps end theirsessions, sender linksclose, the sessionends, then theconnectionA publisher kept from before connect or after shutdownanswers AmqpError::NotConnected, never a silent success
The diagram as text
  1. Broker: AmqpBroker::new (url); ConnectedAmqpBroker; Shut down: Ok(()) or the innermost error
  2. On the wire: Records the URL, SASL, container id; no I/O; Socket, TLS, SASL, open, and the publishers' session; Per subscription: a session, a receiver and its pump task; The first publish to an address attaches its sender link; Pumps end their sessions, sender links close, the session ends, then the connection
  3. AmqpBroker::new (url) → ConnectedAmqpBroker: connect(self)
  4. ConnectedAmqpBroker → Shut down: Ok(()) or the innermost error: shutdown(self)
  5. Records the URL, SASL, container id; no I/O → Socket, TLS, SASL, open, and the publishers' session
  6. Socket, TLS, SASL, open, and the publishers' session → Per subscription: a session, a receiver and its pump task
  7. Per subscription: a session, a receiver and its pump task → The first publish to an address attaches its sender link
  8. The first publish to an address attaches its sender link → Pumps end their sessions, sender links close, the session ends, then the connection
  9. A publisher kept from before connect or after shutdown answers AmqpError::NotConnected, never a silent success

new does no I/O, so the service's builder stays synchronous. The runtime connects the broker when the app starts. Connect parses the URL, opens the socket, authenticates, opens the connection and begins the session the publishers share. A URL that does not parse, a refused socket or a refused login fails the start with AmqpError::Connect.

Each subscription's descriptor resolves once, against the connected broker. An empty address is refused before any I/O. The subscription begins a session, attaches its receiver with its credit, and starts the pump task that owns the receiver. A broker that refuses the attach fails the start with AmqpError::Attach, naming the address.

A sender link is attached by the first publish to its address, not at startup. A service that only consumes attaches none.

Shutdown marks the connection closed and tears it down from the inside out: each pump detaches its receiver and ends its session, the sender links close, the publishers' session ends, and the connection closes last. Each layer still routes the broker's answer for the one inside it. Every step runs even after an earlier one failed, and the error reported is the innermost one. A subscription still open at shutdown yields the deliveries it holds and ends; settling one of them afterwards reports an error.

A broker cloned before it connected shares its connection with the clone. A clone that the test harness connected in process cannot then connect to a server, and the reverse is refused too.