Module stream
Expand description
Stream supervision: open, read, reconnect with backoff. No protocol logic here.
A server-side stream can end at any time: the server closes it, the network breaks, or it goes
silent. supervise reopens it with a growing delay (backoff) and tells the consumer on every
successful open, so the consumer can resend its state. It keeps trying until it is cancelled (or the
receiving end of the channel is dropped), except when the broker refuses the stream in a way a repeat
cannot cure: a rejected token, no permission, the limit of open streams (80001, see fatal_open).
Then it reports the reason once and stops.
§Examples
use std::time::Duration;
use brokapi_tbank::stream::backoff;
// 500 ms doubling up to 30 s.
assert_eq!(backoff(0), Duration::from_millis(500));
assert_eq!(backoff(2), Duration::from_secs(2));
assert_eq!(backoff(40), Duration::from_secs(30));Structs§
- Last
Error - The last reason a stream closed, for error messages of calls that wait on a stream.
Functions§
- backoff
- Delay before reconnect attempt
n(0-based): 500 ms doubling to 30 s. The same range at BCS and Finam: none of the three brokers documents a reason for a different one. - fatal_
open - Whether the refusal to open a stream is final: a repeat will not help, so the supervisor stops and
reports it.
Some(reason)for a rejected token (Unauthenticated), no permission (PermissionDenied) and the limit of open streams (80001,streams_limit). Everything else (the network,Unavailable, a rate limit, the lifetime limit 80005) is worth another try. - sleep_
or_ cancel - Sleeps
dunless cancelled.falsewhen cancelled. - supervise
- Keeps one server-side stream open.
connectedgoes out after every successful open (then the consumer knows a break happened if it is not the first),wrapturns each message into a frame. A stream silent forstale_afteris closed and reopened (pings arrive on a healthy stream).