pub struct Client { /* private fields */ }Expand description
Client for an AgileConfig cluster.
Client owns HTTP loading, the optional local cache, and the WebSocket
session used for live reload notifications. Obtain a Source with
Self::source to integrate with the config crate.
Keep at least one Client clone alive for as long as you want the
WebSocket connection to stay up. The last drop cancels background tasks.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(options: ClientOptions) -> Result<Self, Error>
pub fn new(options: ClientOptions) -> Result<Self, Error>
Creates a client from an options struct.
§Errors
Returns Error::EmptyAppId or Error::EmptyNodes when required
fields are missing.
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Starts a builder that constructs ClientOptions then this client.
Sourcepub fn options(&self) -> &ClientOptions
pub fn options(&self) -> &ClientOptions
Returns the normalized options used by this client.
Sourcepub fn source(&self) -> Source
pub fn source(&self) -> Source
Returns an AsyncSource bound to this client.
Sourcepub fn snapshot(&self) -> Arc<ConfigSnapshot> ⓘ
pub fn snapshot(&self) -> Arc<ConfigSnapshot> ⓘ
Returns the latest configuration snapshot.
Sourcepub fn subscribe(&self) -> Receiver<Arc<ConfigSnapshot>>
pub fn subscribe(&self) -> Receiver<Arc<ConfigSnapshot>>
Subscribes to snapshot updates.
The library never rebuilds a config::Config value. After receiving
a change, the caller should snapshot again and apply it to application
state.
Sourcepub async fn load(&self) -> Result<(), Error>
pub async fn load(&self) -> Result<(), Error>
Pulls configuration via HTTP, falling back to the local cache.
§Errors
Returns Error::LoadFailed when every node fails and no cache exists.
Sourcepub async fn connect(&self) -> Result<(), Error>
pub async fn connect(&self) -> Result<(), Error>
Loads configuration and starts the WebSocket session.
A WebSocket failure is not fatal; the method still succeeds when HTTP
or the cache produced a snapshot. Background reconnect and heartbeat
loops keep running until Self::disconnect or the last clone is
dropped.
§Errors
Returns Error::LoadFailed when no configuration could be obtained.
Sourcepub async fn disconnect(&self)
pub async fn disconnect(&self)
Stops reconnecting and closes the WebSocket.