diff --git a/swarm-queue-client/src/lib.rs b/swarm-queue-client/src/lib.rs index 809304ff..0d353be3 100644 --- a/swarm-queue-client/src/lib.rs +++ b/swarm-queue-client/src/lib.rs @@ -634,6 +634,26 @@ pub fn ensure_connected(client: &async_nats::Client) -> Result<(), Error> { Ok(()) } +/// The largest payload this connection's server will accept, as the server +/// itself announced it at CONNECT. +/// +/// Read it from here rather than from a constant: the limit is set in the +/// queue's own NixOS module, so a client that hardcoded it would be asserting +/// a number it does not own and would keep asserting it after the operator +/// raised it. A publisher that exceeds the limit does not get a shortened +/// message — the server answers `Maximum Payload Violation` and closes the +/// connection, costing the row and a reconnect — so a publisher of +/// variable-size rows must size them against this before handing them over. +/// +/// ⚠️ The value is per connection. Before the first successful CONNECT the +/// client reports the library's own default, which is smaller than any +/// deployment sets; call this after [`ensure_connected`], and the answer is +/// the one this server actually announced. +#[must_use] +pub fn max_payload(client: &async_nats::Client) -> usize { + client.server_info().max_payload +} + /// Connect to the swarm queue, presenting a token on each connection attempt /// and minting a fresh one only when the cached one is near expiry. ///