Lifecycle
ZmqQueue::new records the endpoint, connect checks it,
each subscription and each publisher on the bind side attach a socket at startup, a publisher that
dials on its first publish. ZmqFanout and
ZmqRpc go through the same steps.
The diagram as text
- Broker: ZmqQueue::new (endpoint); ConnectedZmqQueue; Closed = ()
- On ZeroMQ: Endpoint recorded, no I/O; Address checked: tcp:// or ipc://; Each subscription binds or dials a socket of its own; Publishers attach: bind side at startup, dial side on first publish; Marked closed, nothing to flush
- ZmqQueue::new (endpoint) → ConnectedZmqQueue: connect(self)
- ConnectedZmqQueue → Closed = (): shutdown(self)
- Endpoint recorded, no I/O → Address checked: tcp:// or ipc://
- Address checked: tcp:// or ipc:// → Each subscription binds or dials a socket of its own
- Each subscription binds or dials a socket of its own → Publishers attach: bind side at startup, dial side on first publish
- Publishers attach: bind side at startup, dial side on first publish → Marked closed, nothing to flush
- A publisher that outlives the connection answers ZmqError::NotConnected, never a silent success
- A dropped subscription stops its task and frees the endpoint it bound
new does no I/O, so the service's builder stays synchronous. The runtime connects the broker
when the app starts. Connect checks that the address is tcp:// or ipc:// and opens no socket.
Another scheme fails the
start, with an error naming the address.
Each subscription attaches its socket as it opens. On an endpoint this service binds, the subscription listens there, and a bind the system refuses fails the start. One subscription holds a bound endpoint: a second one on the same broker is refused with an error naming both. On an endpoint this service connects to, the subscription dials it. Its peer is the sending end of the pattern, so from then on a publish through the same broker is refused before it dials.
A service that only consumes attaches no publisher socket. A publisher on the bind side attaches its own at startup, one that dials on its first publish, and a send retries for up to five seconds while the connection to its peer finishes the handshake.
Shutdown marks the connection closed and returns. Nothing is
buffered in this crate, so nothing is flushed, and the closed form carries no report. A publisher
handed out earlier answers ZmqError::NotConnected from then
on.
A subscription stops when the runtime drops it. Dropping it stops the task that reads its socket, since a receive on a socket with no peer never returns by itself. A subscription that bound its endpoint frees it at that moment, so a new one can bind the same address.