Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Copy of the original sample, but uses PostgreSQL

Notifications You must be signed in to change notification settings

Eventuous/dotnet-sample-postgres

Folders and files

NameName
Last commit message
Last commit date

Latest commit

71b9b87 · Jun 27, 2024

History

15 Commits
Sep 22, 2022
Sep 23, 2022
Sep 23, 2022
Sep 22, 2022
Sep 22, 2022
Sep 22, 2022
Sep 22, 2022
Sep 22, 2022
Sep 22, 2022
Sep 22, 2022
Sep 23, 2022
Sep 22, 2022
Jun 27, 2024
Sep 22, 2022

Repository files navigation

Deprecation notice

Samples are moved to the core repository.

Bookings sample application - Postgres

This projects shows some of the features of Eventuous:

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

Usage

Start the infrastructure using Docker Compose from the repository root:

docker compose up

Run both Bookings and Bookings.Payments projects and then open http://localhost:5051/swagger/index.html and http://localhost:5000/swagger/index.html respectively. Here you can use SwaggerUI to initiate commands that will result in events being raised.

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 documents in MongoDB:
    • 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 MongoDB document in the Bookings collection using the read-model subscription.
Loading
graph TB
    HTTP --> RecordPayment
    subgraph Payments 
    direction LR
    RecordPayment -- aggregate --> PaymentRecorded[PaymentRecorded<br>domain event]
    Reactor --> PR[PaymentRecorded<br>integration event]
    end
    subgraph Postgres
    PaymentRecorded -- eventstore --> PGSQL[(PGSQL)]
    PGSQL -- 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 --> PGSQL
    PGSQL -- subscription --> Projections
    end
    subgraph MongoDB
    Projections --> BC[(BookingState)]
    Projections --> MB[(MyBookings)]
    end