Crate apollo_rust_client

Crate apollo_rust_client 

Source
Expand description

§Apollo Rust Client

A robust Rust client for the Apollo Configuration Centre, with support for WebAssembly for browser and Node.js environments.

This crate provides a comprehensive client for interacting with Apollo configuration services. The client manages configurations for different namespaces, supports multiple configuration formats (Properties, JSON, Text), provides caching mechanisms, and offers real-time updates through background polling and event listeners.

§Key Features

  • Multiple Configuration Formats: Support for Properties, JSON, Text formats with automatic detection
  • Cross-Platform: Native Rust and WebAssembly targets with platform-specific optimizations
  • Real-Time Updates: Background polling with configurable intervals and event listeners
  • Comprehensive Caching: Multi-level caching with file persistence (native) and memory-only (WASM)
  • Type-Safe API: Compile-time guarantees and runtime type conversion
  • Error Handling: Detailed error diagnostics with comprehensive error types
  • Grayscale Release Support: IP and label-based configuration targeting

§Quick Start

use apollo_rust_client::{Client, client_config::ClientConfig};

let config = ClientConfig {
    app_id: "my-app".to_string(),
    config_server: "http://apollo-server:8080".to_string(),
    cluster: "default".to_string(),
    secret: None,
    cache_dir: None,
    label: None,
    ip: None,
    allow_insecure_https: None,
    #[cfg(not(target_arch = "wasm32"))]
    cache_ttl: None,
};

let mut client = Client::new(config);
client.start().await?;

let namespace = client.namespace("application").await?;

§Platform Support

The library supports different behavior for wasm32 and non-wasm32 targets:

  • Native Rust: Full feature set with file caching, background tasks, and threading
  • WebAssembly: Memory-only caching, single-threaded execution, JavaScript interop

Modules§

client_config
Configuration management for the Apollo client.
namespace
Namespace module for handling different configuration data formats.

Structs§

Client
The main Apollo configuration client.

Enums§

Error
Comprehensive error types that can occur when using the Apollo client.

Type Aliases§

EventListener
Type alias for event listeners that can be registered with the client. For native targets, listeners need to be Send and Sync to be safely shared across threads.