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>) -> BackendPool
pub fn static(backends: Vec<String>) -> BackendPool
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>) -> BackendPool
pub fn env_prefix(prefix: impl Into<String>) -> BackendPool
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>) -> BackendPool
pub fn file(path: impl Into<String>) -> BackendPool
Create a pool whose backends are read from a file (one host:port per line).
Sourcepub fn dns(hostname: impl Into<String>, port: u16) -> BackendPool
pub fn dns(hostname: impl Into<String>, port: u16) -> BackendPool
Create a pool whose backends are discovered via DNS A-record lookup.
Sourcepub fn dns_srv(record: impl Into<String>) -> BackendPool
pub fn dns_srv(record: impl Into<String>) -> BackendPool
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>,
) -> BackendPool
pub fn consul( addr: impl Into<String>, service: impl Into<String>, ) -> BackendPool
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>) -> BackendPool
pub fn docker(label: impl Into<String>) -> BackendPool
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>,
) -> BackendPool
pub fn docker_with_socket( label: impl Into<String>, socket_path: impl Into<String>, ) -> BackendPool
Same as BackendPool::docker but against a non-default Docker
socket path.
Sourcepub fn etcd(endpoints: Vec<String>, prefix: impl Into<String>) -> BackendPool
pub fn etcd(endpoints: Vec<String>, prefix: impl Into<String>) -> BackendPool
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) -> BackendPool
pub fn poll_interval_secs(self, secs: u64) -> BackendPool
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 moreAuto Trait Implementations§
impl Freeze for BackendPool
impl RefUnwindSafe for BackendPool
impl Send for BackendPool
impl Sync for BackendPool
impl Unpin for BackendPool
impl UnsafeUnpin for BackendPool
impl UnwindSafe for BackendPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.