@halcyon-agile/node-event-sourcing
Advanced tools
Comparing version 1.0.35 to 1.0.36
@@ -48,3 +48,3 @@ "use strict"; | ||
events = (await EventStore_1.default.query(aggregateId, { | ||
limit: this.snapshotIn + 5, | ||
limit: this.snapshotIn + 1, | ||
reverse: true, | ||
@@ -51,0 +51,0 @@ })).Items; |
@@ -24,3 +24,3 @@ "use strict"; | ||
topic: eventsTopic, | ||
fromBeginning: false, | ||
fromBeginning: true, | ||
}); | ||
@@ -58,3 +58,3 @@ await this.kafkaConsumer.run({ | ||
await ErrorStore_1.default.create({ | ||
event: `${this.groupId}#${listener?.constructor?.name}`, | ||
event: `topic#${this.groupId}`, | ||
date: new Date().toISOString(), | ||
@@ -61,0 +61,0 @@ payload: { |
@@ -26,3 +26,3 @@ "use strict"; | ||
topic: eventsTopic, | ||
fromBeginning: false, | ||
fromBeginning: true, | ||
}); | ||
@@ -56,3 +56,3 @@ await this.kafkaConsumer.run({ | ||
await ErrorStore_1.default.create({ | ||
event: `${this.projector.name}`, | ||
event: `topic#${this.projector.name}`, | ||
date: new Date().toISOString(), | ||
@@ -59,0 +59,0 @@ payload: { |
{ | ||
"name": "@halcyon-agile/node-event-sourcing", | ||
"version": "1.0.35", | ||
"version": "1.0.36", | ||
"description": "> Opinionated OOP based node.js event sourcing library inspired by laravel-event-sourcing", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -40,7 +40,2 @@ # NODE EVENT SOURCING | ||
### Idempotent Consumer | ||
Both the Listener and Projector is a type of message consumer. Since we will rely on at least once guarantee of Kafka that would mean that the message could accidentally be consumed multiple times. | ||
In the event that the message is consumed multiple times the output should still be the same. | ||
## Getting Started | ||
@@ -195,25 +190,23 @@ | ||
Replaying events is very complicated hence we can only expose the EventStore API and let you do the work. | ||
To replay events you'll need to crawl the EventStore and processed it in order. Sample code below. | ||
### replay-events.js | ||
```ts | ||
const EventStore = require("@halcyon-agile/node-event-sourcing/EventStore"); | ||
```js | ||
const Replay = require("@halcyon-agile/node-event-sourcing/ReplayEvents"); | ||
async function replayEvents() { | ||
const scanAndUpdate = async () => { | ||
try { | ||
const data = await EventStore.documentClient.scan(params).promise(); | ||
// Replay all events and use all existing projectors | ||
Replay.run(); | ||
if (typeof data.LastEvaluatedKey !== "undefined") { | ||
params.ExclusiveStartKey = data.LastEvaluatedKey; | ||
await scanAndUpdate(); | ||
} | ||
} catch (error) { | ||
console.error( | ||
"Unable to scan the table. Error JSON:", | ||
JSON.stringify(error, null, 2) | ||
); | ||
} | ||
}; | ||
} | ||
// Replay specific projectors and event | ||
Replay.run( | ||
[path.resolve("./Projectors/HotProductsProjector")], | ||
["CartItemAdded"] | ||
); | ||
``` | ||
```bash | ||
node replay-events.js | ||
``` | ||
```bash | ||
node | ||
``` |
46999
211