rivven-client
Native Rust client library for Rivven.
Features
- Async/Await - Built on Tokio for high-performance async I/O
- Connection Pooling - Efficient connection management with configurable pool sizes
- Automatic Failover - Bootstrap server failover and reconnection
- Circuit Breaker - Fault tolerance with automatic recovery
- Retry with Exponential Backoff - Automatic retry with jitter for transient failures
- Health Monitoring - Real-time statistics and health checks
- TLS Support - Secure connections with rustls
- SCRAM-SHA-256 Authentication - Secure challenge-response authentication
Installation
[]
= "0.2"
# With TLS support
= { = "0.2", = ["tls"] }
Usage
Basic Client
For simple use cases, use the basic Client:
use Client;
async
Authentication
Rivven supports multiple authentication methods:
use Client;
async
Production-Grade Resilient Client
For production deployments, use ResilientClient which provides:
- Connection pooling across multiple servers
- Automatic retry with exponential backoff and jitter
- Circuit breaker pattern for fault isolation
- Real-time health monitoring
use ;
use Duration;
async
Circuit Breaker Behavior
The circuit breaker protects against cascading failures:
- Closed (Normal): Requests flow normally. Failures are counted.
- Open (Failing): After threshold failures, the circuit opens. All requests fail fast without attempting connection.
- Half-Open (Recovery): After recovery timeout, one request is allowed through. If successful, circuit closes; if failed, circuit reopens.
// Circuit breaker configuration
let config = builder
.servers
.circuit_breaker_failure_threshold // Open after 5 failures
.circuit_breaker_recovery_timeout // Try recovery after 30s
.build;
Retry with Exponential Backoff
Failed operations are automatically retried with exponential backoff and jitter:
let config = builder
.servers
.max_retries // Retry up to 3 times
.retry_initial_delay // Start with 100ms delay
.retry_max_delay // Cap at 5 seconds
.retry_multiplier // Double delay each retry
.build;
Health Monitoring
Monitor client and server health in real-time:
let stats = client.stats.await;
println!;
println!;
println!;
println!;
println!;
for server in &stats.servers
Admin Operations
use ResilientClient;
async
Configuration Reference
ResilientClientConfig
| Option | Default | Description |
|---|---|---|
servers |
Required | List of server addresses |
pool_size_per_server |
10 | Maximum connections per server |
connection_timeout |
10s | Timeout for establishing connections |
request_timeout |
30s | Timeout for individual requests |
max_retries |
3 | Maximum retry attempts |
retry_initial_delay |
100ms | Initial retry delay |
retry_max_delay |
5s | Maximum retry delay |
retry_multiplier |
2.0 | Delay multiplier between retries |
circuit_breaker_failure_threshold |
5 | Failures before circuit opens |
circuit_breaker_recovery_timeout |
30s | Time before attempting recovery |
Error Handling
The client provides typed errors for different failure modes:
use ;
match client.publish.await
TLS Configuration
Enable TLS for secure connections:
= { = "0.2", = ["tls"] }
use ;
let tls_config = builder
.ca_cert_path
.client_cert_path
.client_key_path
.build?;
let client = connect_with_tls.await?;
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
See root LICENSE file.