Skip to main content

Crate agile_config_client

Crate agile_config_client 

Source
Expand description

AgileConfig client for the config crate.

This crate talks to an AgileConfig cluster over HTTP and WebSocket and exposes configuration through two types:

  • Client loads published key/value items, optionally caches them on disk, and can keep a WebSocket session for live reload notifications.
  • Source implements config::AsyncSource so the snapshot can be composed with other sources (files, environment variables, and so on).

§Building a client

Construct ClientOptions directly or use Client::builder:

use agile_config_client::{Client, ClientOptions};

let from_struct = Client::new(ClientOptions {
    app_id: "app".into(),
    secret: "secret".into(),
    nodes: vec!["http://localhost:5000".into()],
    env: "DEV".into(),
    ..ClientOptions::default()
})?;

let from_builder = Client::builder()
    .app_id("app")
    .secret("secret")
    .nodes(["http://localhost:5000"])
    .env("DEV")
    .build()?;

§One-shot load with config

Source::collect (via Client::source) performs HTTP (and cache fallback). It does not open a WebSocket.

use agile_config_client::{Client, ClientOptions};

let client = Client::new(ClientOptions {
    app_id: "app".into(),
    secret: "secret".into(),
    nodes: vec!["http://localhost:5000".into()],
    ..ClientOptions::default()
})?;

let settings = config::Config::builder()
    .add_async_source(client.source())
    .build()
    .await?;

let connection = settings.get_string("db.connection")?;

Keys that the C# client exposes as group:key become dotted paths for the config crate (db:connectiondb.connection).

§Live updates

Call Client::connect to pull configuration and start WebSocket reconnect/heartbeat. Keep the Client alive, then listen with Client::subscribe. This crate never rebuilds config::Config for you.

use agile_config_client::{Client, ClientOptions};

let client = Client::new(ClientOptions {
    app_id: "app".into(),
    secret: "secret".into(),
    nodes: vec!["http://localhost:5000".into()],
    ..ClientOptions::default()
})?;
client.connect().await?;

let mut rx = client.subscribe();
while rx.changed().await.is_ok() {
    let snapshot = client.snapshot();
    // Rebuild `config::Config` or swap application state here.
    let _ = snapshot.get("db:connection");
}

Lookups on ConfigSnapshot are case-sensitive.

§Features

FeatureDefaultPurpose
cache-encryptoffAES-ECB encryption for the local cache file (C# compatible)

Structs§

CacheOptions
Local cache of the last successfully pulled configuration JSON.
Client
Client for an AgileConfig cluster.
ClientBuilder
Fluent builder for Client / ClientOptions.
ClientOptions
Connection and cache settings for Client.
ConfigItem
One published configuration item as returned by the HTTP API.
ConfigSnapshot
Point-in-time view of configuration pulled from AgileConfig.
Source
Read-only configuration source backed by a crate::Client.

Enums§

Error
Failures that can occur while configuring, loading, or connecting.