pub struct BackendPool { /* private fields */ }Expand description
Thread-safe pool of backend addresses, optionally refreshed in the background.
Clone this type freely — all clones share the same underlying RwLock<Vec>.
Implementations§
Source§impl BackendPool
impl BackendPool
Sourcepub fn static(backends: Vec<String>) -> Self
pub fn static(backends: Vec<String>) -> Self
Create a pool from a fixed list of backends.
The list is available immediately; start() is a no-op.
Sourcepub fn env_prefix(prefix: impl Into<String>) -> Self
pub fn env_prefix(prefix: impl Into<String>) -> Self
Create a pool whose backends are read from environment variables
PREFIX_0, PREFIX_1, … at startup and every poll_interval_secs.
Sourcepub fn file(path: impl Into<String>) -> Self
pub fn file(path: impl Into<String>) -> Self
Create a pool whose backends are read from a file (one host:port per line).
Sourcepub fn dns(hostname: impl Into<String>, port: u16) -> Self
pub fn dns(hostname: impl Into<String>, port: u16) -> Self
Create a pool whose backends are discovered via DNS A-record lookup.
Sourcepub fn dns_srv(record: impl Into<String>) -> Self
pub fn dns_srv(record: impl Into<String>) -> Self
Create a pool whose backends are discovered via DNS SRV lookup (e.g.
_http._tcp.my-service.default.svc.cluster.local for a Kubernetes
headless Service). See DiscoverySource::DnsSrv for the
priority/weight handling.
Sourcepub fn consul(addr: impl Into<String>, service: impl Into<String>) -> Self
pub fn consul(addr: impl Into<String>, service: impl Into<String>) -> Self
Create a pool whose backends are discovered via a Consul agent’s
/v1/health/service/:name endpoint. addr is host:port of the
agent, e.g. "127.0.0.1:8500". Only instances passing all health
checks are returned.
Sourcepub fn docker(label: impl Into<String>) -> Self
pub fn docker(label: impl Into<String>) -> Self
Create a pool whose backends are discovered from running Docker
containers carrying label, using the default socket path
(/var/run/docker.sock). See DiscoverySource::Docker for the
label-value-is-the-address convention. Unix-only; a no-op elsewhere.
Sourcepub fn docker_with_socket(
label: impl Into<String>,
socket_path: impl Into<String>,
) -> Self
pub fn docker_with_socket( label: impl Into<String>, socket_path: impl Into<String>, ) -> Self
Same as BackendPool::docker but against a non-default Docker
socket path.
Sourcepub fn etcd(endpoints: Vec<String>, prefix: impl Into<String>) -> Self
pub fn etcd(endpoints: Vec<String>, prefix: impl Into<String>) -> Self
Create a pool whose backends are discovered from an etcd v3 key
prefix, kept live via a watch stream once BackendPool::start is
called. endpoints is a list of host:port etcd cluster members —
only the first is used today (no client-side failover yet). Plain
HTTP only. See DiscoverySource::EtcdWatch.
Sourcepub fn poll_interval_secs(self, secs: u64) -> Self
pub fn poll_interval_secs(self, secs: u64) -> Self
Override the background refresh interval (default: 30 seconds).
Only meaningful for File and Dns sources.
Sourcepub fn start(&self)
pub fn start(&self)
Start the background refresh thread.
For Static sources this is a no-op. For all others, an immediate
refresh() is performed before spawning the background thread so that
the first backends() call returns a populated list.
EtcdWatch is special-cased: instead of the generic sleep-and-poll
loop, a dedicated thread holds a long-lived connection to etcd’s watch
stream and applies PUT/DELETE events to the backend list as they
arrive — no polling interval involved after the initial refresh().
Trait Implementations§
Source§impl Clone for BackendPool
impl Clone for BackendPool
Source§fn clone(&self) -> BackendPool
fn clone(&self) -> BackendPool
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more