Sagas: Workflows That Remember
Learn how to build long-running workflows that remember state using Sagas
When Do You Need Sagas?
Creating Your First Saga
Step 1: Define the Saga Structure
#[Saga]
final class OrderProcess
{
private function __construct(
#[Identifier] private string $orderId, // π Unique ID to find this saga
private OrderStatus $status, // π Current state
private bool $isPaid = false, // π Remember payment status
private bool $isShipped = false, // π Remember shipping status
) {}
}Step 2: Start the Saga
Storage
Step 3: React to Events and Take Actions
Triggering Commands
Alternative: Using Command Bus
Step 4: Publishing Events and Timeouts
Publishing Events
Setting Up Timeouts
Advanced Patterns
Conditional Event Handling
Querying Saga State
Handling Unordered Events
Saga Identification and Correlation
Finding the Right Saga Instance
Using Correlation IDs
Testing Sagas with Ecotone Lite
Setting Up Saga Tests
Testing Saga State Changes
Summary: When to Use Sagas
Last updated
Was this helpful?