An open API service indexing awesome lists of open source software.

https://github.com/locktar/eventuous-dotnet-sample-sqlserver


https://github.com/locktar/eventuous-dotnet-sample-sqlserver

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# 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.

```mermaid
graph TB
HTTP --> RecordPayment
subgraph Payments
direction LR
RecordPayment -- aggregate --> PaymentRecorded[PaymentRecorded
domain event]
Reactor --> PR[PaymentRecorded
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
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
```