Batata Client
A Rust client library for Nacos service discovery and configuration management.
English | 中文
Features
-
Configuration Management
- Get, publish, and remove configurations
- Listen for configuration changes with callbacks
- Search configurations with pagination
- Local caching with MD5 validation
-
Service Discovery
- Register, deregister, and update service instances
- Query service instances (all or healthy only)
- Subscribe to service change notifications
- Automatic heartbeat for ephemeral instances
-
Authentication
- Username/Password authentication
- AccessKey/SecretKey authentication (Alibaba Cloud style)
- Automatic token refresh
-
Enterprise Features
- TLS/SSL support
- Multiple server addresses with load balancing
- Automatic failover and retry
- Local file cache for disaster recovery
Installation
Add to your Cargo.toml:
[]
= "0.0.1"
= { = "1", = ["full"] }
Quick Start
Basic Usage
use ;
async
With Authentication
use BatataClient;
// Username/Password authentication
let client = builder
.server_addr
.username_password
.build
.await?;
// AccessKey/SecretKey authentication
let client = builder
.server_addr
.access_key
.build
.await?;
With TLS
use ;
let client = builder
.server_addr
.tls_config
.build
.await?;
Listen for Configuration Changes
use ;
let client = builder
.server_addr
.build
.await?;
let config_service = client.config_service;
// Add listener with callback
config_service.add_callback_listener;
// Start config service to enable listening
client.start_config_service.await?;
Subscribe to Service Changes
use ;
let client = builder
.server_addr
.build
.await?;
let naming_service = client.naming_service;
// Subscribe with callback
naming_service.subscribe_callback.await?;
Search Configurations
let config_service = client.config_service;
// Search with pagination
let = config_service
.search_config
.await?;
println!;
for item in items
Update Service Instance
use Instance;
let naming_service = client.naming_service;
// Update instance weight and status
let instance = new
.with_weight
.with_enabled
.with_metadata;
naming_service.update_instance.await?;
Local Cache for Failover
let client = builder
.server_addr
.cache_dir
.build
.await?;
Configuration Options
| Option | Description | Default |
|---|---|---|
server_addr |
Nacos server address | localhost:8848 |
server_addrs |
Multiple server addresses | - |
namespace |
Namespace ID | public |
app_name |
Application name | - |
timeout_ms |
Request timeout in milliseconds | 3000 |
retry_times |
Number of retry attempts | 3 |
username_password |
Username and password for auth | - |
access_key |
Access key and secret key for auth | - |
tls |
Enable TLS | false |
tls_config |
TLS configuration | - |
cache_dir |
Local cache directory | - |
Examples
Run the examples:
# Configuration example
# Naming example
License
Apache License 2.0