swarm-queue-client: expose the announced payload limit
A publisher of variable-size rows has to size them against the server's limit before it publishes, because exceeding it is not a truncation: the server answers `Maximum Payload Violation` and closes the connection, so the row is lost and the client reconnects. The limit belongs to the queue's NixOS module, which is the only place that chooses it. Reading it off the connection rather than restating it as a constant keeps it spelled once — a client-side copy would be a second opinion about a number it does not own, and would go stale the day an operator raised the real one. No test: the value comes from the server's INFO line, so anything asserted about it without a running server would only be re-asserting async-nats's own pre-connect default. Refs #3805
This commit is contained in:
parent
767a863cf1
commit
da7fbd20b8
1 changed files with 20 additions and 0 deletions
|
|
@ -634,6 +634,26 @@ pub fn ensure_connected(client: &async_nats::Client) -> Result<(), Error> {
|
||||||
Ok(())
|
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
|
/// 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.
|
/// and minting a fresh one only when the cached one is near expiry.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue