LockTar / eventuous-dotnet-sample-sqlserver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bookings sample application - SQL Server

This projects shows some of the features of Eventuous:

  • Event-sourced domain model using Aggregate and AggregateState
  • Aggregate persistence using SQL ServerQL
  • Read models in SQL Server
  • Integration between services using messaging (RabbitMQ)

Prerequisites

  • Create a new SQL Server database Bookings and run the script Create-Tables.sql to create the necessary tables for the projections.

Usage

  • Open the app.http file in Visual Studio and execute the commands to interact with the API.
  • You can also use SwaggerUI to interact with the API.
  • Create a booking by executing the booking/book api.
  • Record a payment by executing the booking/recordPayment api.
  • Get the booking state by executing the bookings api.
  • Get the booking projection by executing the projections/sql/bookings api.

Example commands

Bookings -> BookRoom (/bookings/book)

  • This command raises an event, which gets stored in the database.
  • A real-time subscription triggers a projection, which adds or updates two records in SQL Server:
    • one for the booking
    • one for the guest

Bookings.Payments -> RecordPayment (/recordPayment)

  • When this command is executed, it raises a PaymentRecorded event, which gets persisted to the database.
  • A gateway inside the Payments service subscribes to this event and publishes an integration event to RabbitMQ.
  • An integration RabbitMQ subscription receives the integration event and calls the Bookings service to execute the RecordPayment command, so it acts as a Reactor.
  • When that command gets executed, it raises a PaymentRecorded event, which gets persisted to the database. It might also raise a BookingFullyPaid or BookingOverpaid events, depending on the amount.
  • Those new events are projected to SQL Server document in the Bookings collection using the read-model subscription.
graph TB
    HTTP --> RecordPayment
    subgraph Payments 
    direction LR
    RecordPayment -- aggregate --> PaymentRecorded[PaymentRecorded<br>domain event]
    Reactor --> PR[PaymentRecorded<br>integration event]
    end
    subgraph SQL Server
    PaymentRecorded -- eventstore --> SQLSERVER[(SQL SERVER)]
    SQLSERVER -- gateway --> Reactor
    end
    subgraph Broker
    PR --> RabbitMQ[[RabbitmQ]]
    end
    subgraph Bookings
    direction RL
    RabbitMQ -- subscription --> IH[Integration<br>handler]
    IH --> RP[RecordPayment]
    RP -- aggregate --> PR1[PaymentRecorded]
    PR1 -- eventstore --> SQLSERVER
    SQLSERVER -- subscription --> Projections
    end
    subgraph SQL Server
    Projections --> BC[(BookingState)]
    Projections --> MB[(MyBookings)]
    end
Loading

About


Languages

Language:C# 92.3%Language:TypeScript 5.6%Language:TSQL 1.1%Language:Dockerfile 1.0%