https://github.com/locktar/eventuous-dotnet-sample-sqlserver
https://github.com/locktar/eventuous-dotnet-sample-sqlserver
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/locktar/eventuous-dotnet-sample-sqlserver
- Owner: LockTar
- Created: 2024-05-27T15:08:49.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-06-21T11:15:17.000Z (10 months ago)
- Last Synced: 2024-06-22T07:51:42.469Z (10 months ago)
- Language: C#
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```