Skip to main content

Crate dynamic_config_etcd

Crate dynamic_config_etcd 

Source
Expand description

Read dynamic-config configuration from an etcd v3 key/value store.

etcd speaks gRPC, so its client is async — which is why this implements the async AsyncRemoteSource trait rather than the blocking one.

use dynamic_config_etcd::Etcd;

DbConfig::set_remote_async(
    Etcd::new(["http://etcd.internal:2379"], "myapp/db.json").await?,
);

// Fetching is explicit; the load that follows touches no network.
DbConfig::refresh_remote_async().await?;

§What it reads

One key, whose value is a whole configuration document — the same bytes that would be in a config file. The format comes from the key’s extension, or from with_format.

§The connection is made once, and lazily

Etcd::new builds the client and fetch reuses it — a source that reconnected on every read would turn a refresh loop into a connection storm.

The underlying client connects lazily, so new succeeding does not mean the endpoints are reachable: an unreachable etcd surfaces on the first fetch, not at construction. That is the client’s behaviour rather than a choice made here, and papering over it with an eager round trip would make every construction cost one.

§Watching

etcd’s watch is a real push stream, so Etcd::watch is a future the caller spawns and cancels by dropping — no runtime is imposed and no flag is polled.

let task = tokio::spawn(async move {
    etcd.watch(move |document| sink(document)).await
});

// Dropping or aborting the task stops the watch.
task.abort();

Structs§

Certificatetls
etcd’s TLS types, behind this crate’s tls feature.
Client
etcd’s own connection options, re-exported so authenticating needs no direct dependency on etcd-client. Asynchronous etcd client using v3 API.
ConnectOptions
etcd’s own connection options, re-exported so authenticating needs no direct dependency on etcd-client. Options for Connect operation.
Etcd
A key in etcd, as a configuration source.
Identitytls
etcd’s TLS types, behind this crate’s tls feature.
TlsOptionstls
etcd’s TLS types, behind this crate’s tls feature.