Goal, Make this schema alive :
Described using Event Modeling All the post-its on the schema exists in the codebase
- Code : Full API of NATS JetStream in javascript(ish)
- What are Event Collaboration And Event Sourcing ?
- Anatomy of a NATS application
- NestJS NATS JetStream microservice library
And folder structure too
The whole schema : One folder per event model containing everything needed for the flow
Rows on the top : For each UI/Trigger on the schema an adapter.
NestJS controllers to adapt source protocol to domain's needs
- HTTP REST API
- Nats consumers :
-
trigger side effects (think saga)
-
keep read models up to date
-
dedicated consumer to limit blast radius if any destination has an issue
Blue post-its :
- Business logic : handles command, emits events.
- WARNING : Create, Update, Delete on the database is forbidden here !
- Better to use with one Command by file to make code more atomic.
- Consistency on the application : Infinite message deduplication in JetStream
- Publish domain events on nats subjects (JetStream or Core)
Green Post it :
- Consume events to manage read model's state
- Build needed read model(s) for this feature.
- Can be used for versionning and event.specversion management.
- Build a materialised view with an history using nats keystore
All DTOs are here :
- Shared accross all features on all domains and all teams
- One folder per domain (bottom rows on the schema)
- Mainly declarative
Orange Post its
- An event describe a finished action.
- A Domain Event describes an interesting action that occurred in the past and has an impact within the domain.
- Convention used : CloudEvents, a specification for describing event data in a common way
The row on the bottom :
- Where the events are gonna be stored or will be consumed.
- Conservation, deduplication, rate limit, ordering, ... are configured here
- Definition of a stream
- Multi Tenancy using Accounts
Our core domain
- A data model with an ID.
- Used to derivate other DTO : event, command, query results, ...
- Centralise validation rules using class validator with JSON Schema or AsyncAPI schema
- Modelina is the official AsyncAPI SDK to generate data models
docker run -d --name nats -p 4222:4222 -p 8222:8222 -p 6222:6222 nats --jetstream -m 8222
rush install
ts-node feature/hotel-booking/backend/main.ts
curl --request PUT \
--url http://127.0.0.1:3000/mutation/book-room \
--header 'Content-Type: application/json' \
--data '{
"data": {
"room": { "id" : 1},
"client": { "id": 1},
"date": "2022-12-12"
}
}'
curl --request PUT \
--url http://127.0.0.1:3000/mutation/cleanup \
--header 'Content-Type: application/json' \
--data '{
"data": {
"room": { "id" : 1},
"date": "2022-12-12"
}
}'
curl --request PUT \
--url http://127.0.0.1:3000/mutation/checkin \
--header 'Content-Type: application/json' \
--data '{
"data": {
"room": { "id" : 1 },
"client": { "id": 1},
"date": "2022-12-13"
}
}'
nats stream view room-booking --subject='booking.1.2022-12-12.1_2022-12-12'
nats stream view room-cleanup --subject='cleanup.1.2022-12-12.1_2022-12-12'
- Documentation
- AsyncAPI request and sub
- Websocket example
- NATS cli command doc to debug (or docker GUI ?)
- Event|Command validation
- Use CloudEvent as base event interface on driver
- Use CloudEvent as base command interface
- Middleware validation
- Idempotency
- publish options per event's emit
- Fix Expect last subject sequence not working (poc root)
- Shared state with materialized views
- allow access to nats JetStream KeyStore from client
- mapper to nats Keystore table.id.attributes = bucket.key.value
- watch in projection to compare with state
- handle state modification automatically
- QOS connection lost
- Implement heartbeat https://github.com/nats-io/nats.deno/blob/main/jetstream.md#heartbeats
- Audit log stream with 14 days memory, store command = event type, date, subject, id
- Correlation ID shared from start of process
- Auth and security
- configure nats accounts
- Set websocket access limits solutions
- Publishing
- publish event
- send message
- simplify NatsJetStreamClient+Proxy
- Subscribing
- Pull Subscription
- One specific consumer per destination
- consumer
- message handler with nats
- auto stream creation