ioredis-streams 2.0.0 → 2.1.1
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 +75 -3
- package/dist/redis-client.d.ts +1 -0
- package/dist/redis-client.js.map +1 -1
- package/dist/stream-consumer.d.ts +26 -0
- package/dist/stream-consumer.js +85 -2
- package/dist/stream-consumer.js.map +1 -1
- package/dist/types.d.ts +14 -1
- package/docs/api.md +395 -0
- package/docs/configuration.md +131 -0
- package/docs/dead-letters.md +132 -0
- package/docs/examples.md +339 -0
- package/package.json +2 -2
- package/src/redis-client.ts +3 -0
- package/src/stream-consumer.ts +85 -1
- package/src/types.ts +14 -1
- package/test/events.spec.ts +1 -1
- package/test/redis-streams.spec.ts +23 -3
- package/test/stream-consumer.integration.spec.ts +149 -0
- package/test/stream-consumer.spec.ts +206 -1
package/README.md
CHANGED
|
@@ -1,5 +1,77 @@
|
|
|
1
1
|
# ioredis-streams
|
|
2
|
-
redis streams with events handlers
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/ioredis-streams)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A TypeScript library for working with **Redis Streams** using consumer groups, typed events, and a fluent API. Built on top of [ioredis](https://github.com/luin/ioredis).
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Fluent, chainable API for producing and consuming stream events
|
|
11
|
+
- Fully typed event factories with TypeScript generics
|
|
12
|
+
- Consumer groups with **parallel** or **serial** processing modes
|
|
13
|
+
- Automatic backlog recovery and idle message claiming
|
|
14
|
+
- Request/reply pattern with `eventWithReply` and `.wait()`
|
|
15
|
+
- Dead letter queue for messages that exceed retry limits
|
|
16
|
+
- Redis Cluster support
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install ioredis-streams
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { RedisStreams, event } from 'ioredis-streams';
|
|
28
|
+
|
|
29
|
+
// Define typed event factories
|
|
30
|
+
const UserEvents = {
|
|
31
|
+
...event('user.created').of<{ userId: string; email: string }>(),
|
|
32
|
+
...event('user.deleted').of<{ userId: string }>(),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Create the streams client (reads REDIS_HOST / REDIS_PORT from env by default)
|
|
36
|
+
const streams = new RedisStreams('my-service');
|
|
37
|
+
|
|
38
|
+
// Get a typed stream handle
|
|
39
|
+
const userStream = streams
|
|
40
|
+
.group('user-processors')
|
|
41
|
+
.stream('users')
|
|
42
|
+
.with(UserEvents);
|
|
43
|
+
|
|
44
|
+
// Produce an event
|
|
45
|
+
await userStream['user.created']({ userId: '42', email: 'zaid@example.com' });
|
|
46
|
+
|
|
47
|
+
// Consume events
|
|
48
|
+
userStream
|
|
49
|
+
.handle('user.created', async (id, event) => {
|
|
50
|
+
console.log('New user:', event.data.userId);
|
|
51
|
+
})
|
|
52
|
+
.handle('user.deleted', async (id, event) => {
|
|
53
|
+
console.log('Deleted user:', event.data.userId);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const { stop } = await userStream.consume();
|
|
57
|
+
|
|
58
|
+
// Later, to shut down gracefully:
|
|
59
|
+
stop();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
| Topic | Description |
|
|
65
|
+
|---|---|
|
|
66
|
+
| [Configuration](docs/configuration.md) | Redis connection, env vars, cluster setup, stream tuning |
|
|
67
|
+
| [API Reference](docs/api.md) | All classes, methods, and TypeScript types |
|
|
68
|
+
| [Examples](docs/examples.md) | Real-world patterns: pub/sub, request/reply, batch producing |
|
|
69
|
+
| [Dead Letters](docs/dead-letters.md) | Handling messages that exceed retry limits |
|
|
70
|
+
|
|
71
|
+
## Author
|
|
72
|
+
|
|
73
|
+
**Zaid Al-Omari**
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|
package/dist/redis-client.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface IRedisClient {
|
|
|
4
4
|
xreadgroup(...args: any[]): Promise<any>;
|
|
5
5
|
xpending(...args: any[]): Promise<any>;
|
|
6
6
|
xclaim(...args: any[]): Promise<any>;
|
|
7
|
+
xinfo?(...args: any[]): Promise<any>;
|
|
7
8
|
xadd(...args: any[]): Promise<any>;
|
|
8
9
|
xack(stream: string, group: string, ...ids: string[]): Promise<number>;
|
|
9
10
|
publish(channel: string, message: string): Promise<number>;
|
package/dist/redis-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-client.js","sourceRoot":"","sources":["../src/redis-client.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAgD;
|
|
1
|
+
{"version":3,"file":"redis-client.js","sourceRoot":"","sources":["../src/redis-client.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAgD;AAyBzC,MAAM,kBAAkB,GAAG,CAAC,UAAkB,EAAoC,EAAE,CACzF,UAAU;KACP,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KACtB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAJhD,QAAA,kBAAkB,sBAI8B;AAE7D,kGAAkG;AAC3F,MAAM,sBAAsB,GAAG,GAAgB,EAAE;IACtD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IACzC,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;IAE1D,IAAI,YAAY,EAAE;QAChB,OAAO,IAAA,0BAAkB,EAAC,YAAY,CAAC,CAAC;KACzC;IACD,IAAI,CAAC,SAAS,IAAI,SAAS,KAAK,EAAE,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;KAClE;IACD,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;KAClE;IACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC9C,CAAC,CAAC;AAfW,QAAA,sBAAsB,0BAejC;AAEK,MAAM,iBAAiB,GAAG,CAC/B,SAAsB,IAAA,8BAAsB,GAAE,EAC9C,iBAAiC,EAAE,EACrB,EAAE;IAChB,IAAI,MAAM,YAAY,KAAK,EAAE;QAC3B,OAAO,IAAI,iBAAK,CAAC,OAAO,CAAC,MAAM,EAAE,cAAc,CAA4B,CAAC;KAC7E;IACD,OAAO,IAAI,iBAAK,CAAC,MAAM,CAA4B,CAAC;AACtD,CAAC,CAAC;AARW,QAAA,iBAAiB,qBAQ5B;AAEF,iDAAiD;AACpC,QAAA,sBAAsB,GAAG,CAAC,GAAG,EAAE;IAC1C,IAAI,OAAiC,CAAC;IACtC,OAAO,CAAC,SAAsB,IAAA,8BAAsB,GAAE,EAAE,iBAAiC,EAAE,EAAgB,EAAE;QAC3G,IAAI,CAAC,OAAO;YAAE,OAAO,GAAG,IAAA,yBAAiB,EAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAClE,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -3,6 +3,8 @@ import { IRedisClient } from './redis-client';
|
|
|
3
3
|
import { ConsumerBuffer } from './consumer-buffer';
|
|
4
4
|
import { ConsumerConfigs, IEvent, IWaitEvent } from './types';
|
|
5
5
|
export declare type EventProcessor = <T>(id: string, event: string, eventObj: IEvent<T> | IWaitEvent<T>) => Promise<any>;
|
|
6
|
+
export declare const DEFAULT_DEAD_CONSUMER_IDLE_TIME: number;
|
|
7
|
+
export declare const DEFAULT_DEAD_CONSUMER_CHECK_INTERVAL: number;
|
|
6
8
|
export declare class StreamConsumer {
|
|
7
9
|
protected readonly redis: IRedisClient;
|
|
8
10
|
protected readonly processEvent: EventProcessor;
|
|
@@ -12,6 +14,7 @@ export declare class StreamConsumer {
|
|
|
12
14
|
protected lastReadId: string;
|
|
13
15
|
protected checkBacklog: boolean;
|
|
14
16
|
protected readonly buffer: ConsumerBuffer;
|
|
17
|
+
protected readingLoop: Promise<void>;
|
|
15
18
|
constructor(redis: IRedisClient, processEvent: EventProcessor, config: ConsumerConfigs);
|
|
16
19
|
get size(): number;
|
|
17
20
|
init(): Promise<void>;
|
|
@@ -21,6 +24,29 @@ export declare class StreamConsumer {
|
|
|
21
24
|
protected doClaim(): Promise<boolean>;
|
|
22
25
|
protected doRead(): Promise<boolean>;
|
|
23
26
|
protected processMessage<T>(id: string, message: string[]): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Stops reading and waits for the in-flight read/claim iteration (and everything it buffered) to finish.
|
|
29
|
+
*
|
|
30
|
+
* This consumer is deliberately NOT removed from the group: XGROUP DELCONSUMER would discard its pending
|
|
31
|
+
* entries (messages whose handler failed and that are waiting for a retry). They stay pending, so the
|
|
32
|
+
* live consumers' `doClaim()` retries them, exactly as for a crashed consumer. Instead, the dead-consumer
|
|
33
|
+
* cleanup runs once here, and its name is removed by a later cleanup once it is idle and owns nothing.
|
|
34
|
+
*/
|
|
24
35
|
dispose(): Promise<void>;
|
|
36
|
+
protected lastTimeConsumersCleanup: number;
|
|
37
|
+
/**
|
|
38
|
+
* Removes consumers that have been idle (XINFO CONSUMERS `idle`) longer than `deadConsumerIdleTime` and
|
|
39
|
+
* own no pending messages, e.g. names left behind by stopped or killed pods.
|
|
40
|
+
*
|
|
41
|
+
* Runs from the reading loop every `deadConsumerCheckInterval`, and on `dispose()` (`force`).
|
|
42
|
+
* Live consumers poll (XREADGROUP BLOCK) every `readBlockTime`, so their idle time stays far below the
|
|
43
|
+
* threshold. Uses plain sequential Redis 5.0 commands; never throws.
|
|
44
|
+
*/
|
|
45
|
+
protected cleanupDeadConsumers(force?: boolean): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Re-checks that `consumer` owns no pending messages, then runs XGROUP DELCONSUMER
|
|
48
|
+
* (which would otherwise discard them). Returns false when the consumer was kept.
|
|
49
|
+
*/
|
|
50
|
+
protected removeConsumerIfNoPending(consumer: string): Promise<boolean>;
|
|
25
51
|
publishDeadLetters(...messages: [string, string[]][]): Promise<void>;
|
|
26
52
|
}
|
package/dist/stream-consumer.js
CHANGED
|
@@ -3,9 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.StreamConsumer = void 0;
|
|
6
|
+
exports.StreamConsumer = exports.DEFAULT_DEAD_CONSUMER_CHECK_INTERVAL = exports.DEFAULT_DEAD_CONSUMER_IDLE_TIME = void 0;
|
|
7
7
|
const log4js_api_1 = __importDefault(require("@log4js-node/log4js-api"));
|
|
8
8
|
const consumer_buffer_1 = require("./consumer-buffer");
|
|
9
|
+
exports.DEFAULT_DEAD_CONSUMER_IDLE_TIME = 24 * 60 * 60 * 1000;
|
|
10
|
+
exports.DEFAULT_DEAD_CONSUMER_CHECK_INTERVAL = 6 * 60 * 60 * 1000;
|
|
11
|
+
// XINFO CONSUMERS returns each consumer as a flat [key, value, key, value, ...] array (RESP2)
|
|
12
|
+
// or as an object (RESP3 / some clients).
|
|
13
|
+
function parseInfoEntry(raw) {
|
|
14
|
+
if (Array.isArray(raw)) {
|
|
15
|
+
const out = {};
|
|
16
|
+
for (let i = 0; i + 1 < raw.length; i += 2)
|
|
17
|
+
out[String(raw[i])] = raw[i + 1];
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
return (raw && typeof raw === 'object') ? raw : {};
|
|
21
|
+
}
|
|
9
22
|
class StreamConsumer {
|
|
10
23
|
redis;
|
|
11
24
|
processEvent;
|
|
@@ -15,6 +28,7 @@ class StreamConsumer {
|
|
|
15
28
|
lastReadId = '0-0';
|
|
16
29
|
checkBacklog = true;
|
|
17
30
|
buffer;
|
|
31
|
+
readingLoop = Promise.resolve();
|
|
18
32
|
constructor(redis, processEvent, config) {
|
|
19
33
|
this.redis = redis;
|
|
20
34
|
this.processEvent = processEvent;
|
|
@@ -49,10 +63,12 @@ class StreamConsumer {
|
|
|
49
63
|
}
|
|
50
64
|
async start() {
|
|
51
65
|
this.logger.trace('Started...');
|
|
52
|
-
|
|
66
|
+
this.readingLoop = this.tryReading();
|
|
67
|
+
await this.readingLoop;
|
|
53
68
|
}
|
|
54
69
|
async tryReading() {
|
|
55
70
|
while (!this.disposing) {
|
|
71
|
+
await this.cleanupDeadConsumers();
|
|
56
72
|
try {
|
|
57
73
|
const claimedAnything = await this.doClaim();
|
|
58
74
|
if (claimedAnything && !this.disposing)
|
|
@@ -137,8 +153,75 @@ class StreamConsumer {
|
|
|
137
153
|
}
|
|
138
154
|
return result;
|
|
139
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Stops reading and waits for the in-flight read/claim iteration (and everything it buffered) to finish.
|
|
158
|
+
*
|
|
159
|
+
* This consumer is deliberately NOT removed from the group: XGROUP DELCONSUMER would discard its pending
|
|
160
|
+
* entries (messages whose handler failed and that are waiting for a retry). They stay pending, so the
|
|
161
|
+
* live consumers' `doClaim()` retries them, exactly as for a crashed consumer. Instead, the dead-consumer
|
|
162
|
+
* cleanup runs once here, and its name is removed by a later cleanup once it is idle and owns nothing.
|
|
163
|
+
*/
|
|
140
164
|
async dispose() {
|
|
141
165
|
this.disposing = true;
|
|
166
|
+
await this.readingLoop;
|
|
167
|
+
await this.cleanupDeadConsumers(true);
|
|
168
|
+
}
|
|
169
|
+
lastTimeConsumersCleanup = 0;
|
|
170
|
+
/**
|
|
171
|
+
* Removes consumers that have been idle (XINFO CONSUMERS `idle`) longer than `deadConsumerIdleTime` and
|
|
172
|
+
* own no pending messages, e.g. names left behind by stopped or killed pods.
|
|
173
|
+
*
|
|
174
|
+
* Runs from the reading loop every `deadConsumerCheckInterval`, and on `dispose()` (`force`).
|
|
175
|
+
* Live consumers poll (XREADGROUP BLOCK) every `readBlockTime`, so their idle time stays far below the
|
|
176
|
+
* threshold. Uses plain sequential Redis 5.0 commands; never throws.
|
|
177
|
+
*/
|
|
178
|
+
async cleanupDeadConsumers(force = false) {
|
|
179
|
+
const { streamName, groupName, peerName, readBlockTime, claimIdleTime } = this.config;
|
|
180
|
+
const idleTime = this.config.deadConsumerIdleTime ?? exports.DEFAULT_DEAD_CONSUMER_IDLE_TIME;
|
|
181
|
+
if (!(idleTime > 0) || !this.redis.xinfo)
|
|
182
|
+
return;
|
|
183
|
+
if (!force) {
|
|
184
|
+
const interval = this.config.deadConsumerCheckInterval ?? exports.DEFAULT_DEAD_CONSUMER_CHECK_INTERVAL;
|
|
185
|
+
if (!(interval > 0))
|
|
186
|
+
return;
|
|
187
|
+
if (this.lastTimeConsumersCleanup + interval > Date.now())
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this.lastTimeConsumersCleanup = Date.now();
|
|
191
|
+
const threshold = Math.max(idleTime, 2 * (readBlockTime + claimIdleTime));
|
|
192
|
+
try {
|
|
193
|
+
const consumers = await this.redis.xinfo('CONSUMERS', streamName, groupName);
|
|
194
|
+
for (const raw of consumers ?? []) {
|
|
195
|
+
const info = parseInfoEntry(raw);
|
|
196
|
+
const name = info.name !== undefined ? String(info.name) : undefined;
|
|
197
|
+
if (!name || name === peerName)
|
|
198
|
+
continue;
|
|
199
|
+
if (Number(info.pending) !== 0 || !(Number(info.idle) > threshold))
|
|
200
|
+
continue;
|
|
201
|
+
if (await this.removeConsumerIfNoPending(name)) {
|
|
202
|
+
this.logger.info(`Removed dead consumer '${name}' (idle ${info.idle}ms) from group '${groupName}'`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
this.logger.warn(`Error while cleaning up dead consumers of group '${groupName}'`, err);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Re-checks that `consumer` owns no pending messages, then runs XGROUP DELCONSUMER
|
|
212
|
+
* (which would otherwise discard them). Returns false when the consumer was kept.
|
|
213
|
+
*/
|
|
214
|
+
async removeConsumerIfNoPending(consumer) {
|
|
215
|
+
const { streamName, groupName } = this.config;
|
|
216
|
+
const pending = await this.redis.xpending(streamName, groupName, '-', '+', 1, consumer);
|
|
217
|
+
if (pending && pending.length)
|
|
218
|
+
return false;
|
|
219
|
+
const discarded = Number(await this.redis.xgroup('DELCONSUMER', streamName, groupName, consumer));
|
|
220
|
+
if (discarded > 0) {
|
|
221
|
+
this.logger.warn(`Removing consumer '${consumer}' from group '${groupName}' discarded ${discarded} pending message(s) ` +
|
|
222
|
+
`on stream '${streamName}'. Is the consumer name (peerName) used by more than one process?`);
|
|
223
|
+
}
|
|
224
|
+
return true;
|
|
142
225
|
}
|
|
143
226
|
async publishDeadLetters(...messages) {
|
|
144
227
|
if (!this.config.deadLetters)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-consumer.js","sourceRoot":"","sources":["../src/stream-consumer.ts"],"names":[],"mappings":";;;;;;AAAA,yEAAoD;AAEpD,uDAAmD;
|
|
1
|
+
{"version":3,"file":"stream-consumer.js","sourceRoot":"","sources":["../src/stream-consumer.ts"],"names":[],"mappings":";;;;;;AAAA,yEAAoD;AAEpD,uDAAmD;AAStC,QAAA,+BAA+B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACtD,QAAA,oCAAoC,GAAG,CA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batchSize: number;
|
|
49
49
|
mode: 'parallel' | 'serial';
|
|
50
50
|
maxLen: number;
|
|
51
|
+
/**
|
|
52
|
+
* Consumers in the group that have been idle (XINFO CONSUMERS `idle`) longer than this and own no
|
|
53
|
+
* pending messages are removed from the group (e.g. names left behind by stopped or killed pods).
|
|
54
|
+
* `0` disables the cleanup. Default: 86400000 (24 hours). Values lower than
|
|
55
|
+
* `2 × (readBlockTime + claimIdleTime)` are raised to that floor.
|
|
56
|
+
*/
|
|
57
|
+
deadConsumerIdleTime?: number;
|
|
58
|
+
/**
|
|
59
|
+
* How often each consumer runs the dead-consumer cleanup. It also runs once on startup and once when
|
|
60
|
+
* the consumer is stopped. `0` disables the periodic run (it still runs on stop).
|
|
61
|
+
* Default: 21600000 (6 hours).
|
|
62
|
+
*/
|
|
63
|
+
deadConsumerCheckInterval?: number;
|
|
51
64
|
};
|
|
52
65
|
export declare type ConsumerConfigs = StreamConfigs & {
|
|
53
66
|
peerName: string;
|
|
@@ -62,7 +75,7 @@ export declare type ConsumerConfigs = StreamConfigs & {
|
|
|
62
75
|
export declare type NamedEventHandler<E = IEvent<any>> = (id: string, event: E) => Promise<any>;
|
|
63
76
|
export declare type ConsumeFunctions = {
|
|
64
77
|
consume: () => Promise<{
|
|
65
|
-
stop: () => void
|
|
78
|
+
stop: () => Promise<void>;
|
|
66
79
|
continue: () => void;
|
|
67
80
|
}>;
|
|
68
81
|
};
|