-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rabbit-bus): outbox pattern first implementation
- Loading branch information
Showing
7 changed files
with
226 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"language": "en", | ||
"words": ["fizzbuds"] | ||
"language": "en", | ||
"words": [ | ||
"fizzbuds", | ||
"replset" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,71 @@ | ||
{ | ||
"name": "@fizzbuds/ddd-toolkit-rabbit-bus", | ||
"version": "0.0.35", | ||
"description": "", | ||
"author": "Gabriele Toselli, Luca Giovenzana", | ||
"private": false, | ||
"license": "Apache-2.0", | ||
"main": "dist/index", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "rimraf dist && tsc --project tsconfig.build.json", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage", | ||
"check": "cspell lint --quiet src" | ||
"name": "@fizzbuds/ddd-toolkit-rabbit-bus", | ||
"version": "0.0.35", | ||
"description": "", | ||
"author": "Gabriele Toselli, Luca Giovenzana", | ||
"private": false, | ||
"license": "Apache-2.0", | ||
"main": "dist/index", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "rimraf dist && tsc --project tsconfig.build.json", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage", | ||
"check": "cspell lint --quiet src" | ||
}, | ||
"dependencies": { | ||
"@fizzbuds/ddd-toolkit": "workspace:^" | ||
}, | ||
"peerDependencies": { | ||
"amqplib": "^0.10.3", | ||
"mongodb": "^4.0.0 || ^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/amqplib": "^0.10.5", | ||
"@types/jest": "^29.5.2", | ||
"@types/lodash": "^4.14.195", | ||
"@types/node": "^20.3.1", | ||
"@types/uuid": "^9.0.2", | ||
"@typescript-eslint/eslint-plugin": "^6.18.1", | ||
"@typescript-eslint/parser": "^6.18.1", | ||
"amqplib": "^0.10.3", | ||
"cspell": "^8.3.2", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.2", | ||
"husky": "^8.0.0", | ||
"jest": "^29.5.0", | ||
"lint-staged": "^14.0.1", | ||
"prettier": "^3.1.1", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.0", | ||
"ts-node": "^10.9.1", | ||
"tsconfig-paths": "^4.2.0", | ||
"typescript": "^5.1.3", | ||
"mongodb": "^4.17.2", | ||
"mongodb-memory-server": "^8.13.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "src", | ||
"testRegex": ".*spec\\.ts$", | ||
"testPathIgnorePatterns": [ | ||
".api-spec.ts$" | ||
], | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"dependencies": { | ||
"@fizzbuds/ddd-toolkit": "workspace:^" | ||
}, | ||
"peerDependencies": { | ||
"amqplib": "^0.10.3" | ||
}, | ||
"devDependencies": { | ||
"@types/amqplib": "^0.10.5", | ||
"@types/jest": "^29.5.2", | ||
"@types/lodash": "^4.14.195", | ||
"@types/node": "^20.3.1", | ||
"@types/uuid": "^9.0.2", | ||
"@typescript-eslint/eslint-plugin": "^6.18.1", | ||
"@typescript-eslint/parser": "^6.18.1", | ||
"amqplib": "^0.10.3", | ||
"cspell": "^8.3.2", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.2", | ||
"husky": "^8.0.0", | ||
"jest": "^29.5.0", | ||
"lint-staged": "^14.0.1", | ||
"prettier": "^3.1.1", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.0", | ||
"ts-node": "^10.9.1", | ||
"tsconfig-paths": "^4.2.0", | ||
"typescript": "^5.1.3" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "src", | ||
"testRegex": ".*spec\\.ts$", | ||
"testPathIgnorePatterns": [ | ||
".api-spec.ts$" | ||
], | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"collectCoverageFrom": [ | ||
"**/*.(t|j)s" | ||
], | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
} | ||
"collectCoverageFrom": [ | ||
"**/*.(t|j)s" | ||
], | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/ddd-tookit-rabbit-bus/src/mongo-bus-persistence.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ClientSession, Collection, MongoClient } from 'mongodb'; | ||
import { IEvent, ILogger } from '@fizzbuds/ddd-toolkit'; | ||
|
||
export interface IBusPersistence { | ||
init(): Promise<void>; | ||
|
||
terminate(): Promise<void>; | ||
|
||
persistEvent(event: IEvent<unknown>, status: 'pending' | 'published', session?: unknown): Promise<void>; | ||
|
||
getEventStatus(event: IEvent<unknown>): Promise<'pending' | 'published' | null>; | ||
|
||
getPendingEvents(): Promise<IEvent<unknown>[]>; | ||
} | ||
|
||
export class MongoBusPersistence implements IBusPersistence { | ||
private readonly collection: Collection<{ | ||
event: IEvent<unknown>; | ||
status: 'pending' | 'published'; | ||
}>; | ||
|
||
constructor( | ||
protected readonly mongoClient: MongoClient, | ||
private readonly logger: ILogger, | ||
) { | ||
this.collection = this.mongoClient.db().collection('bus_persistence'); | ||
} | ||
|
||
async init(): Promise<void> {} | ||
|
||
async persistEvent( | ||
event: IEvent<unknown>, | ||
status: 'pending' | 'published', | ||
session?: ClientSession, | ||
): Promise<void> { | ||
await this.collection.updateOne({ event }, { $set: { status } }, { upsert: true, session }); | ||
} | ||
|
||
async getEventStatus(event: IEvent<unknown>): Promise<'pending' | 'published' | null> { | ||
const doc = await this.collection.findOne({ event }); | ||
return doc?.status ?? null; | ||
} | ||
|
||
async terminate(): Promise<void> {} | ||
|
||
async getPendingEvents(): Promise<IEvent<unknown>[]> { | ||
const docs = await this.collection.find({ status: 'pending' }).toArray(); | ||
return docs.map((doc) => doc.event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.