batata-consul-client - Rust client for HashiCorp Consul
Overview
This library provides a Rust client for interacting with HashiCorp Consul,
supporting service discovery, health checking, key-value store, sessions,
ACL, and more.
Quick Start
use batata_consul_client::{Client, Config};
#[tokio::main]
async fn main() -> batata_consul_client::Result<()> {
let client = Client::new(Config::default())?;
let kv = client.kv();
kv.put_string("my/key", "my-value", None).await?;
let (pair, _meta) = kv.get("my/key", None).await?;
if let Some(p) = pair {
println!("Value: {:?}", p.value_string());
}
use batata_consul_client::api::agent::{AgentServiceRegistration, AgentServiceCheck};
let registration = AgentServiceRegistration::new("my-service")
.with_id("my-service-1")
.with_address("127.0.0.1")
.with_port(8080)
.with_check(AgentServiceCheck::http("http://127.0.0.1:8080/health", "10s"));
client.agent().service_register(®istration).await?;
let (services, _meta) = client.health().service_healthy("my-service", None).await?;
for service in services {
println!("Service: {} at {}:{}",
service.service.service,
service.service.address,
service.service.port
);
}
Ok(())
}
Features
- KV Store: Get, put, delete keys with CAS support and locking
- Agent: Register/deregister services, manage checks, TTL
- Catalog: Query nodes and services across the cluster
- Health: Health check queries with filtering
- Session: Distributed locking and leader election
- ACL: Token, policy, and role management