Skip to content

stevsharp/OutboxSagaDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MassTransit Order Saga Demo

A working example of an Order Processing Saga using:

  • MassTransit
  • RabbitMQ
  • Entity Framework Core
  • PostgreSQL (with EF Core Migrations)
  • Outbox Pattern

πŸ“¦ Features

  • Saga State Machine for managing the order lifecycle
  • Event-driven messaging with RabbitMQ
  • Outbox Pattern for reliable message delivery
  • Entity Framework Core repository for saga persistence
  • Example consumers for handling stock and payment events
  • PostgreSQL schema & migration scripts included

πŸ—‚ Project Structure

  • src/
  • β”œβ”€β”€ Consumers/ # Event consumers
  • β”œβ”€β”€ Messages/ # Message contracts
  • β”œβ”€β”€ Sagas/ # State machine & state model
  • β”œβ”€β”€ Program.cs # Application entry point
  • β”œβ”€β”€ OrdersSagaDbContext.cs
  • └── ...

πŸ›  Requirements


πŸš€ Running Locally

1️⃣ Clone the repository

git clone https://github.com/<your-username>/mass-transit-order-saga.git
cd mass-transit-order-saga

##2️⃣ Set up PostgreSQL & RabbitMQ (via Docker)

docker-compose up -d
(docker-compose.yml is included in this repo)

3️⃣ Apply EF Core migrations

dotnet ef database update

##4️⃣ Run the app

dotnet run

πŸ”„ Workflow

OrderSubmitted event starts the saga. Saga requests stock reservation. If stock is available, saga requests payment authorization. Once payment is authorized, saga completes the order. Saga is marked as completed and archived.

πŸ§ͺ Testing You can send events using any message publisher (MassTransit client, Postman with RabbitMQ HTTP API, etc.).

Example payload for OrderSubmitted:

{
  "OrderId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
  "CustomerEmail": "[email protected]",
  "Total": 99.99
}

Connect with Me

LinkedIn

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages