Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventSourcedOrchestratingAggregate added #52

Merged
merged 1 commit into from
Jan 18, 2025

Conversation

idugalic
Copy link
Member

Orchestrating Event Sourced Aggregate - composing deciders and sagas in single transaction

It uses a Decider and Saga to compute new events based on the current/stored events and the new command.
If the decider is combined from many deciders via the combine function, a saga could be used to react to new events and send new commands to the decider recursively in a single transaction!

#[tokio::test]
async fn orchestrated_event_sourced_aggregate_test() {
    let combined_decider = order_decider()
        .combine(shipment_decider()) // Decider<Sum<OrderCommand, ShipmentCommand>, (OrderState, ShipmentState), Sum<OrderEvent, ShipmentEvent>>
        .map_command(&command_from_sum) // Decider<Command, (OrderState, ShipmentState), Sum<OrderEvent, ShipmentEvent>>
        .map_event(&event_from_sum, &sum_to_event); // Decider<Command, (OrderState, ShipmentState), Event>
    let combined_saga = order_saga()
        .combine(shipment_saga())
        .map_action(&sum_to_command)
        .map_action_result(&event_from_sum);
    let repository = InMemoryEventRepository::new();
    let aggregate = Arc::new(EventSourcedOrchestratingAggregate::new(
        repository,
        combined_decider.map_error(&|()| AggregateError::DomainError("Decider error".to_string())),
        combined_saga,
    ));
...

Check the aggregate_combined_test.rs for more details.

@idugalic idugalic merged commit 33613d7 into main Jan 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant