Skip to main content

Crate angzarr_client

Crate angzarr_client 

Source
Expand description

Ergonomic Rust client for Angzarr gRPC services.

This crate provides typed clients with fluent builder APIs for interacting with Angzarr aggregate coordinator and query services.

§Quick Start

use angzarr_client::{DomainClient, CommandBuilderExt, QueryBuilderExt};
use uuid::Uuid;

async fn example() -> angzarr_client::Result<()> {
    // Connect to a domain's coordinator
    let client = DomainClient::connect("http://localhost:1310").await?;

    // Execute a command
    let cart_id = Uuid::new_v4();
    let response = client.command_handler
        .command("cart", cart_id)
        .with_command("type.googleapis.com/examples.CreateCart", &create_cart)
        .execute()
        .await?;

    // Query events
    let events = client.query
        .query("cart", cart_id)
        .range(0)
        .get_pages()
        .await?;
    Ok(())
}

§Mocking for Tests

Implement the GatewayClient and QueryClient traits to create mock clients:

use angzarr_client::traits::{GatewayClient, QueryClient};
use angzarr_client::proto::CommandBook;
use async_trait::async_trait;

struct MockAggregate;

#[async_trait]
impl GatewayClient for MockAggregate {
    async fn execute(&self, _cmd: CommandBook)
        -> angzarr_client::Result<angzarr_client::proto::CommandResponse>
    {
        // Return mock response
        Ok(angzarr_client::proto::CommandResponse::default())
    }
}

Re-exports§

pub use client::CommandHandlerClient;
pub use client::DomainClient;
pub use client::QueryClient;
pub use client::SpeculativeClient;
pub use error::ClientError;
pub use error::Result;
pub use builder::CommandBuilderExt;
pub use builder::QueryBuilderExt;
pub use builder::decode_event;
pub use builder::events_from_response;
pub use builder::root_from_cover;
pub use convert::full_type_name;
pub use convert::full_type_url;
pub use convert::now;
pub use convert::parse_timestamp;
pub use convert::proto_to_uuid;
pub use convert::try_unpack;
pub use convert::type_matches;
pub use convert::type_name_from_url;
pub use convert::type_url;
pub use convert::type_url_matches_exact;
pub use convert::unpack;
pub use convert::uuid_to_proto;
pub use convert::TYPE_URL_PREFIX;
pub use proto_ext::CommandBookExt;
pub use proto_ext::CommandPageExt;
pub use proto_ext::CoverExt;
pub use proto_ext::EditionExt;
pub use proto_ext::EventBookExt;
pub use proto_ext::EventPageExt;
pub use proto_ext::ProtoUuidExt;
pub use proto_ext::UuidExt;
pub use router::event_book_from;
pub use router::event_page;
pub use router::new_event_book;
pub use router::new_event_book_multi;
pub use router::pack_event;
pub use router::BoxedHandlerFactory;
pub use router::HandlerFactory;
pub use router::HandlerHOF;
pub use router::BoxedUpcasterHandler;
pub use router::UpcasterHandler;
pub use router::UpcasterHandlerHOF;
pub use router::UpcasterMode;
pub use router::UpcasterRouter;
pub use router::CloudEventsHandler;
pub use router::CloudEventsProjector;
pub use router::CloudEventsRouter;
pub use router::CommandHandlerDomainHandler;
pub use router::CommandHandlerMode;
pub use router::CommandHandlerRouter;
pub use router::CommandRejectedError;
pub use router::CommandResult;
pub use router::EventApplier;
pub use router::EventApplierHOF;
pub use router::StateFactory;
pub use router::StateRouter;
pub use router::ProcessManagerDomainHandler;
pub use router::ProcessManagerMode;
pub use router::ProcessManagerResponse;
pub use router::ProcessManagerRouter;
pub use router::ProjectorDomainHandler;
pub use router::ProjectorMode;
pub use router::ProjectorRouter;
pub use router::RejectionHandlerResponse;
pub use router::SagaContext;
pub use router::SagaDomainHandler;
pub use router::SagaHandlerResponse;
pub use router::SagaMode;
pub use router::SagaRouter;
pub use router::UnpackAny;
pub use handler::CloudEventsGrpcHandler;
pub use handler::CommandHandlerGrpc;
pub use handler::ProcessManagerGrpcHandler;
pub use handler::ProjectorHandler;
pub use handler::SagaHandler;
pub use handler::StatePacker;
pub use handler::UpcasterGrpcHandler;
pub use handler::UpcasterHandleClosureFn;
pub use handler::UpcasterHandleFn;
pub use server::run_cloudevents_projector;
pub use server::run_command_handler_server;
pub use server::run_process_manager_server;
pub use server::run_projector_server;
pub use server::run_saga_server;
pub use server::run_upcaster_server;
pub use server::ServerConfig;
pub use validation::require_exists;
pub use validation::require_non_negative;
pub use validation::require_not_empty;
pub use validation::require_not_empty_str;
pub use validation::require_not_exists;
pub use validation::require_positive;
pub use validation::require_status;
pub use validation::require_status_not;

Modules§

builder
Fluent builders for commands and queries.
client
Default client implementations wrapping tonic gRPC clients.
convert
Conversion helpers for protobuf types.
error
Error types for the Angzarr client library.
handler
gRPC service handlers for aggregates, sagas, and process managers.
proto
Generated protobuf types for Angzarr.
proto_ext
Extension traits for proto types.
router
Unified router for aggregates, sagas, process managers, and projectors.
server
gRPC server utilities for running aggregate and saga services.
traits
Client traits for gateway and query operations.
validation
Validation helpers for command handler precondition checks.

Macros§

dispatch_command
Helper macro for dispatching commands by type URL suffix.
dispatch_event
Helper macro for dispatching events by type URL suffix.

Constants§

VERSION
Version of the angzarr-client crate, injected at build time from VERSION file.

Attribute Macros§

aggregate
Marks an impl block as an aggregate with command handlers.
applies
Marks a method as an event applier for state reconstruction.
handles
Marks a method as a command handler.
prepares
Marks a method as a prepare handler for destination declaration.
process_manager
Marks an impl block as a process manager with event handlers.
projector
Marks an impl block as a projector with event handlers.
projects
Marks a method as a projector event handler.
rejected
Marks a method as a rejection handler.
saga
Marks an impl block as a saga with event handlers.