Expand description
Dynamic backend pool with pluggable discovery sources.
BackendPool maintains a thread-safe list of "host:port" addresses that
can be refreshed on a background thread. Discovery is delegated to a
DiscoverySource:
| Variant | Description |
|---|---|
Static | Fixed list — no polling required. |
EnvPrefix | Scan PREFIX_0, PREFIX_1, … environment variables. |
File | Read one host:port per line from a file. |
Dns | A-record lookup — resolve hostname to all IPs. |
§Example
use rust_web_server::service_discovery::BackendPool;
// Fixed list — no background thread needed.
let pool = BackendPool::r#static(vec!["10.0.0.1:8080".into(), "10.0.0.2:8080".into()]);
println!("{:?}", pool.backends());
// Env-var discovery, refreshed every 60 seconds.
let pool = BackendPool::env_prefix("MY_SVC_BACKEND")
.poll_interval_secs(60);
pool.start();
println!("{:?}", pool.backends());Structs§
- Backend
Pool - Thread-safe pool of backend addresses, optionally refreshed in the background.
Enums§
- Discovery
Source - Controls how
BackendPooldiscovers backend addresses.