Qonduit
Qonduit is a Rust implementation of the Command Query Responsibility Segregation (CQRS) architectural pattern. This library offers a structured approach to separate state-changing operations (commands) from data retrieval operations (queries) in your applications.
Features
- Command Handling: Define commands that change the state of your system.
- Query Handling: Retrieve data without mutating state.
- Event Handling (Fan-out): Publish immutable domain events to multiple handlers (e.g. projections, notifications).
- Handler Registration Macros:
command_bus!,query_bus!,event_bus!, and matching*_registry!helpers. - Async Support: Fully asynchronous handling via
async_trait. - Lightweight & Type-Safe: Minimal abstractions over strongly typed handlers.
Installation
Add qonduit to your Cargo.toml:
[]
= "0.2.0"
Usage
Here's an example showing how to set up Qonduit to handle an AddProductCommand in an inventory system:
use async_trait;
use Command;
use CommandHandler;
use command_bus;
// Define a command to add a product to inventory
// Define possible errors
// Define the command response
// Implement the Command trait
// Create a handler for processing the command
// Implement the command handling logic
async
Event System
The event system lets you broadcast immutable domain events to multiple handlers (fan‑out). Each handler receives a cloned copy of the event and executes sequentially.
Example:
use async_trait;
use ;
use event_bus;
// Define an event
// First handler
;
// Second handler
;
async
See the examples/event.rs example for a more complete version (including manual registry construction).
Documentation
License
Licensed under either of
- Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.