Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ license = "Apache-2.0"
keywords = ["cqrs", "event-sourcing", "eventsourcingdb", "cqrs-es"]

[dependencies]
cqrs-es = "0.4.12"
eventsourcingdb = "1.1.0"
async-trait = "0.1.89"
chrono = { version = "0.4.44", features = ["serde"] }
cqrs-es = "0.5.0"
eventsourcingdb = "2.0.1"
futures = "0.3.32"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
thiserror = "2.0.18"
tokio = "1.50.0"
url = "2.5.8"
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,37 @@ An [EventSourcingDB](https://docs.eventsourcingdb.io) implementation of the `Per

---

## Conventions and assumptions

This adapter follows the naming guidance from the [EventSourcingDB documentation](https://docs.eventsourcingdb.io/) and assumes the following storage conventions:

- Subjects use the form `/<aggregate-type>/<aggregate-id>`, for example `/books/42`.
- Event types in EventSourcingDB use reverse-domain notation, kebab-case names, and an explicit major version suffix, for example `io.eventsourcingdb.library.book-acquired.v1`.
- Event type names are mapped to `cqrs-es` event names by converting between kebab-case and PascalCase.
- Only major event versions are stored in EventSourcingDB (`v1`, `v2`, ...). On the `cqrs-es` side they are exposed as `1.0`, `2.0`, and so on.
- Legacy unversioned event types are still read as version `1.0`, but new writes always use an explicit `.v1` suffix.
- Event payload and metadata are stored in an adapter envelope so `cqrs-es` metadata survives round-trips.

## Mapping EventSourcingDB ids to `cqrs-es` sequences

`cqrs-es` expects each aggregate stream to have a continuous sequence `1, 2, 3, ...`, while EventSourcingDB ids are global chronological integers encoded as strings for CloudEvents compatibility. This adapter remaps the global id stream to per-aggregate logical sequence numbers, uses the last EventSourcingDB id as the optimistic-write precondition, and stores that id in snapshots so loading after a snapshot can continue from the correct global boundary.

## Usage

Add the following to your `Cargo.toml`:

```toml
[dependencies]
cqrs-es = "0.4.12"
cqrs-es = "0.5"
eventsourcingdb-es = "0.1.0"
```

## Features implemented

- [x] Persist events
- [x] Read events by subject (aggregate type and ID)
- [x] Read last events by subject
- [x] Stream events for subject
- [x] Stream all events for aggregate type
- [x] Write snapshots
- [x] Read snapshots
21 changes: 19 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
services:
eventsourcingdb:
image: thenativeweb/eventsourcingdb
image: thenativeweb/eventsourcingdb:1.2.0
container_name: eventsourcingdb
restart: always
restart: unless-stopped
ports:
- 3000:3000
command:
Expand All @@ -12,3 +12,20 @@ services:
- --http-enabled
- --https-enabled=false
- --with-ui
healthcheck:
test:
[
"CMD-SHELL",
"wget -S --spider http://eventsourcingdb:3000/api/v1/health 2>&1 | grep 'HTTP/1.1 200 OK'",
]
# ["CMD", "curl", "-f", "http://eventsourcingdb:3000/api/v1/not-exists"]
interval: 5s
timeout: 5s
retries: 5
# command: "mongod --replSet rs0"
# healthcheck:
# test: |
# mongosh --quiet --eval "try { rs.status().ok } catch (e) { rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'localhost:27017' }] }).ok }"
# interval: 5s
# timeout: 5s
# retries: 5
Loading