pub struct BrokerPool { /* private fields */ }Expand description
Pool of Arc<Connection> keyed by broker id. Connections are opened lazily
on first use and cached thereafter.
Implementations§
Source§impl BrokerPool
impl BrokerPool
Sourcepub fn new(bootstrap: Vec<SocketAddr>, options: ConnectionOptions) -> Self
pub fn new(bootstrap: Vec<SocketAddr>, options: ConnectionOptions) -> Self
Create a new pool with the given bootstrap addresses and connection options.
Sourcepub async fn get(&self, broker_id: i32) -> Result<Arc<Connection>, ClientError>
pub async fn get(&self, broker_id: i32) -> Result<Arc<Connection>, ClientError>
Get-or-connect to a specific broker id. The pool must have already
learned the (id, address) mapping via refresh_brokers.
Sourcepub async fn bootstrap_connection(&self) -> Result<Arc<Connection>, ClientError>
pub async fn bootstrap_connection(&self) -> Result<Arc<Connection>, ClientError>
Get-or-connect to the first reachable bootstrap address. The bootstrap
connection is cached under the synthetic broker id -1.
Sourcepub fn refresh_brokers(&self, brokers: &[BrokerInfo])
pub fn refresh_brokers(&self, brokers: &[BrokerInfo])
Update the (id, addr) address registry from a list of brokers, typically
sourced from a MetadataResponse. Does not open any new connections.
Brokers advertising port 0 are skipped: that is not a dialable address
(it shows up for in-process test brokers whose advertised port never got
rewritten to the real bound port). Leaving such an entry out means
get reports Disconnected for that id, letting a
caller fall back to the bootstrap connection rather than attempting a
doomed host:0 connect.
Sourcepub fn knows_broker(&self, broker_id: i32) -> bool
pub fn knows_broker(&self, broker_id: i32) -> bool
Whether the (id → addr) registry knows a dialable address for this
broker id (i.e. refresh_brokers learned
it and the port was not 0). A caller can use this to decide between
routing to a specific broker and falling back to the bootstrap
connection, without a speculative connect.