@prodforcode/event-forge-nestjs 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,8 @@ pnpm add @prodforcode/event-forge-nestjs @prodforcode/event-forge-core
|
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
15
|
-
- **Automatic Polling Management**: Outbox polling starts automatically on application bootstrap and stops gracefully on shutdown
|
|
15
|
+
- **Automatic Polling Management**: Outbox and Inbox polling starts automatically on application bootstrap and stops gracefully on shutdown
|
|
16
|
+
- **Inbox Retry with Exponential Backoff**: Failed messages are automatically retried with configurable backoff strategy
|
|
16
17
|
- **Configurable Lifecycle**: Control automatic polling behavior via `lifecycle.autoStart` option
|
|
17
18
|
- **Dependency Injection**: Full NestJS DI support for repositories and services
|
|
18
19
|
- **Database Agnostic**: Works with any database adapter (TypeORM, Mongoose, etc.)
|
|
@@ -27,7 +28,7 @@ The simplest setup automatically manages polling lifecycle:
|
|
|
27
28
|
import { Module } from '@nestjs/common';
|
|
28
29
|
import { InboxOutboxModule } from '@prodforcode/event-forge-nestjs';
|
|
29
30
|
import { TypeOrmOutboxRepository } from '@prodforcode/event-forge-typeorm';
|
|
30
|
-
import { RabbitMQPublisher } from '@prodforcode/event-forge-rabbitmq';
|
|
31
|
+
import { RabbitMQPublisher } from '@prodforcode/event-forge-rabbitmq-publisher';
|
|
31
32
|
|
|
32
33
|
@Module({
|
|
33
34
|
imports: [
|
|
@@ -92,6 +93,62 @@ export class AppModule {
|
|
|
92
93
|
}
|
|
93
94
|
```
|
|
94
95
|
|
|
96
|
+
### Inbox Retry Polling
|
|
97
|
+
|
|
98
|
+
When `enableRetry: true` is set in inbox config, the `InboxService` will automatically poll for failed messages that are due for retry:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
@Module({
|
|
102
|
+
imports: [
|
|
103
|
+
InboxOutboxModule.forRootAsync({
|
|
104
|
+
useFactory: () => ({
|
|
105
|
+
inbox: {
|
|
106
|
+
repository: TypeOrmInboxRepository,
|
|
107
|
+
config: {
|
|
108
|
+
enableRetry: true, // Enable retry polling
|
|
109
|
+
retryPollingInterval: 5000, // Check every 5 seconds
|
|
110
|
+
maxRetries: 5,
|
|
111
|
+
backoffBaseSeconds: 10,
|
|
112
|
+
maxBackoffSeconds: 1800, // 30 minutes max
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
// ... other config
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
119
|
+
})
|
|
120
|
+
export class AppModule {}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
With this configuration:
|
|
124
|
+
- Failed messages are automatically retried with exponential backoff
|
|
125
|
+
- Polling starts automatically when the application boots (if `lifecycle.autoStart` is true)
|
|
126
|
+
- Messages exceeding `maxRetries` are marked as permanently failed
|
|
127
|
+
|
|
128
|
+
#### Manual Retry Polling Control
|
|
129
|
+
|
|
130
|
+
If you need fine-grained control over retry polling:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
|
134
|
+
import { InboxService } from '@prodforcode/event-forge-core';
|
|
135
|
+
|
|
136
|
+
@Injectable()
|
|
137
|
+
export class RetryPollingService implements OnModuleInit, OnModuleDestroy {
|
|
138
|
+
constructor(private readonly inboxService: InboxService) {}
|
|
139
|
+
|
|
140
|
+
onModuleInit() {
|
|
141
|
+
// Start retry polling manually
|
|
142
|
+
this.inboxService.startRetryPolling();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
onModuleDestroy() {
|
|
146
|
+
// Stop retry polling on shutdown
|
|
147
|
+
this.inboxService.stopRetryPolling();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
95
152
|
## Configuration
|
|
96
153
|
|
|
97
154
|
### Lifecycle Options
|
|
@@ -121,6 +178,14 @@ InboxOutboxModule.forRootAsync({
|
|
|
121
178
|
},
|
|
122
179
|
inbox: {
|
|
123
180
|
repository: InboxRepositoryClass,
|
|
181
|
+
config: {
|
|
182
|
+
// Retry configuration for failed messages
|
|
183
|
+
enableRetry: true, // Enable automatic retry polling (default: false)
|
|
184
|
+
retryPollingInterval: 5000, // Poll interval in ms (default: 5000)
|
|
185
|
+
maxRetries: 3, // Max retry attempts (default: 3)
|
|
186
|
+
backoffBaseSeconds: 5, // Base delay for exponential backoff (default: 5)
|
|
187
|
+
maxBackoffSeconds: 3600, // Max delay cap in seconds (default: 3600 = 1 hour)
|
|
188
|
+
},
|
|
124
189
|
},
|
|
125
190
|
publisher: PublisherClass,
|
|
126
191
|
lifecycle: {
|
|
@@ -130,6 +195,43 @@ InboxOutboxModule.forRootAsync({
|
|
|
130
195
|
});
|
|
131
196
|
```
|
|
132
197
|
|
|
198
|
+
### Inbox Configuration Options
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
interface InboxConfig {
|
|
202
|
+
/**
|
|
203
|
+
* Enable automatic retry polling for failed messages
|
|
204
|
+
* @default false
|
|
205
|
+
*/
|
|
206
|
+
enableRetry?: boolean;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Polling interval in milliseconds to check for messages due for retry
|
|
210
|
+
* @default 5000
|
|
211
|
+
*/
|
|
212
|
+
retryPollingInterval?: number;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Maximum number of retry attempts before marking as permanently failed
|
|
216
|
+
* @default 3
|
|
217
|
+
*/
|
|
218
|
+
maxRetries?: number;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Base delay in seconds for exponential backoff calculation
|
|
222
|
+
* Formula: min(backoffBaseSeconds × 2^retryCount, maxBackoffSeconds)
|
|
223
|
+
* @default 5
|
|
224
|
+
*/
|
|
225
|
+
backoffBaseSeconds?: number;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Maximum delay in seconds for exponential backoff
|
|
229
|
+
* @default 3600 (1 hour)
|
|
230
|
+
*/
|
|
231
|
+
maxBackoffSeconds?: number;
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
133
235
|
## Advanced Usage
|
|
134
236
|
|
|
135
237
|
### Accessing the Lifecycle Service
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prodforcode/event-forge-nestjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "NestJS module for Universal Inbox-Outbox Pattern",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"author": "Event-Forge",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@prodforcode/event-forge-core": "1.
|
|
20
|
+
"@prodforcode/event-forge-core": "1.2.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@nestjs/common": "^10.0.0",
|