Skip to main content

Clients

The Angzarr SDK provides several client types for different use cases. All clients support both TCP endpoints and Unix Domain Sockets.


DomainClient

The recommended entry point for most applications. Combines QueryClient and AggregateClient into a single unified interface.

Benefits:

  • Single connection — one endpoint, one channel, reduced resource usage
  • Unified API — both queries and commands through one object
  • Builder access — fluent builders attached to the client instance
  • Simpler DI — inject one client instead of two
use angzarr_client::DomainClient;

// Connect to coordinator
let client = DomainClient::connect("http://localhost:1310").await?;

// Send a command
let response = client.aggregate.handle(command).await?;

// Query events
let events = client.query.get_events(query).await?;

QueryClient

Provides read access to aggregate event streams. Use for:

  • State reconstruction: Fetch events to rebuild aggregate state locally
  • Audit trails: Read complete history for debugging and compliance
  • Projections: Feed events to read-model projectors
  • Testing: Verify events were persisted correctly after commands
use angzarr_client::QueryClient;

let client = QueryClient::connect("http://localhost:1310").await?;

// Query events for an aggregate
let events = client.get_events(query).await?;

for page in events.pages {
println!("Event {}: {}", page.sequence, page.event.type_url);
}

AggregateClient

Sends commands to aggregates through the coordinator. Supports multiple execution modes:

ModeMethodDescription
Asynchandle()Fire-and-forget, returns immediately after acceptance
Synchandle_sync()Waits for persistence, returns resulting events
Speculativehandle_sync_speculative()What-if execution without persistence
use angzarr_client::AggregateClient;

let client = AggregateClient::connect("http://localhost:1310").await?;

// Async execution (fire-and-forget)
let response = client.handle(command).await?;

// Sync execution (wait for persistence)
let response = client.handle_sync(sync_command).await?;

Environment Variables

All clients support connecting via environment variables for deployment flexibility:

// Connect using env var with fallback
let client = DomainClient::from_env("ANGZARR_ENDPOINT", "http://localhost:1310").await?;

Unix Domain Sockets

All clients support Unix Domain Sockets for local communication with reduced overhead:

// Absolute path
let client = DomainClient::connect("/var/run/angzarr.sock").await?;

// Relative path
let client = DomainClient::connect("./angzarr.sock").await?;

// URI format
let client = DomainClient::connect("unix:///var/run/angzarr.sock").await?;

Next Steps