pub struct Client { /* private fields */ }
Expand description
The main Apollo configuration client.
This struct provides the primary interface for interacting with Apollo configuration services. It manages multiple namespace caches, handles background refresh tasks, and provides event listener functionality for real-time configuration updates.
§Features
- Namespace Management: Automatically creates and manages caches for different namespaces
- Background Refresh: Optional background task that periodically refreshes all namespaces
- Event Listeners: Support for registering callbacks on configuration changes
- Cross-Platform: Works on both native Rust and WebAssembly targets
- Thread Safety: All operations are thread-safe and async-friendly
§Examples
use apollo_rust_client::{Client, client_config::ClientConfig};
Implementations§
Source§impl Client
impl Client
pub async fn add_listener(&self, namespace: &str, listener: EventListener)
Sourcepub async fn namespace(&self, namespace: &str) -> Result<Namespace, Error>
pub async fn namespace(&self, namespace: &str) -> Result<Namespace, Error>
Retrieves a namespace configuration from the Apollo server.
This method fetches the configuration for the specified namespace and automatically detects the format based on the namespace name. The format detection follows these rules:
- Properties format (default): No file extension
- JSON format:
.json
extension - YAML format:
.yaml
or.yml
extension - Text format:
.txt
extension - XML format:
.xml
extension (not yet supported)
§Arguments
namespace
- The namespace identifier string (e.g., “application”, “config.json”)
§Returns
Ok(Namespace)
- The configuration data in the appropriate formatErr(Error::Cache)
- If cache operations fail (network, I/O, etc.)Err(Error::Namespace)
- If namespace format detection or processing fails
§Errors
This method will return an error if:
- Network requests to the Apollo server fail
- Cache file operations fail (native targets only)
- JSON parsing fails during configuration retrieval
- Namespace format detection fails
- The requested namespace format is not supported (e.g., XML)
§Examples
use apollo_rust_client::{Client, client_config::ClientConfig};
Sourcepub async fn start(&mut self) -> Result<(), Error>
pub async fn start(&mut self) -> Result<(), Error>
Starts a background task that periodically refreshes all registered namespace caches.
This method spawns an asynchronous task using async_std::task::spawn
on native targets
or wasm_bindgen_futures::spawn_local
on wasm32 targets. The task loops indefinitely
(until stop
is called or the client is dropped) and performs the following actions
in each iteration:
- Iterates through all namespaces currently managed by the client.
- Calls the
refresh
method on each namespace’sCache
instance. - Logs any errors encountered during the refresh process.
- Sleeps for a predefined interval (currently 30 seconds) before the next refresh cycle.
§Returns
Ok(())
if the background task was successfully started.Err(Error::AlreadyRunning)
if the background task is already active.
§Errors
This method will return an error if:
- The background task is already running (
Error::AlreadyRunning
) - Task spawning fails (though this is rare and typically indicates system resource issues)
Sourcepub async fn stop(&mut self)
pub async fn stop(&mut self)
Stops the background cache refresh task.
This method sets the running
flag to false
, signaling the background task
to terminate its refresh loop.
On non-wasm32 targets, it also attempts to explicitly cancel the spawned task
by calling cancel()
on its JoinHandle
if it exists. This helps to ensure
that the task is properly cleaned up. On wasm32 targets, there is no direct
handle to cancel, so setting the running
flag is the primary mechanism for stopping.
Trait Implementations§
Source§impl FromWasmAbi for Client
impl FromWasmAbi for Client
Source§impl IntoWasmAbi for Client
impl IntoWasmAbi for Client
Source§impl LongRefFromWasmAbi for Client
impl LongRefFromWasmAbi for Client
Source§impl OptionFromWasmAbi for Client
impl OptionFromWasmAbi for Client
Source§impl OptionIntoWasmAbi for Client
impl OptionIntoWasmAbi for Client
Source§impl RefFromWasmAbi for Client
impl RefFromWasmAbi for Client
Source§impl RefMutFromWasmAbi for Client
impl RefMutFromWasmAbi for Client
Source§impl TryFromJsValue for Client
impl TryFromJsValue for Client
Source§impl VectorFromWasmAbi for Client
impl VectorFromWasmAbi for Client
Source§impl VectorIntoWasmAbi for Client
impl VectorIntoWasmAbi for Client
impl SupportsConstructor for Client
impl SupportsInstanceProperty for Client
impl SupportsStaticProperty for Client
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
Source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.