Skip to main content

Module service_discovery

Module service_discovery 

Source
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:

VariantDescription
StaticFixed list — no polling required.
EnvPrefixScan PREFIX_0, PREFIX_1, … environment variables.
FileRead one host:port per line from a file.
DnsA-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§

BackendPool
Thread-safe pool of backend addresses, optionally refreshed in the background.

Enums§

DiscoverySource
Controls how BackendPool discovers backend addresses.