Registry / messaging / redis-streams-broker

redis-streams-broker

JSON →
library0.0.15jsnpmunverified

A lightweight broker for Redis Streams that provides guaranteed message delivery via consumer acknowledgements and consumer group functionality, similar to Kafka. Version 0.0.15 (beta) supports only ioredis as the Redis client. It offers publishing, consumer group subscriptions, pending message summary, and memory footprint monitoring. The package is in early development with potential breaking changes between minor versions.

npm install redis-streams-broker
INSTALL
IMPORT
SIG · REDIS-STREAMS-BROK
R
redis-streams-broker
messagingjavascriptv0.0.15
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StreamChannelBroker
import { StreamChannelBroker } from 'redis-streams-broker'
const StreamChannelBroker = require('redis-streams-broker')
ESM import is recommended; the package ships TypeScript types.
broker (default import)
import redisStreamsBroker from 'redis-streams-broker'
const broker = require('redis-streams-broker')
Default import resolves to the main module; named import is preferred for clarity.
StreamChannelBroker
const { StreamChannelBroker } = require('redis-streams-broker')
const StreamChannelBroker = require('redis-streams-broker')
CommonJS destructuring is necessary; direct require returns the module, not the class.

Demonstrates connecting to Redis, publishing a message, creating a consumer group, subscribing with a consumer, and acknowledging messages.

import Redis from 'ioredis'; import { StreamChannelBroker } from 'redis-streams-broker'; const redisClient = new Redis(process.env.REDIS_URL ?? 'redis://127.0.0.1:6379'); const broker = new StreamChannelBroker(redisClient, 'myQueue'); async function main() { const payloadId = await broker.publish({ a: 'Hello', b: 'World' }); console.log('Published payload ID:', payloadId); const consumerGroup = await broker.joinConsumerGroup('MyGroup'); const subscriptionHandle = await consumerGroup.subscribe('Consumer1', async (payloads) => { for (const element of payloads) { console.log('Payload ID:', element.id); console.log('Channel:', element.channel); console.log('Payload:', element.payload); try { await element.markAsRead(); } catch (err) { console.error('Ack failed:', err); } } }); // Keep process alive to receive messages process.on('SIGINT', () => { consumerGroup.unsubscribe(subscriptionHandle); process.exit(); }); } main().catch(console.error);
Debug
Known issues
gotchaOnly ioredis is supported as the Redis client; other clients (e.g., node-redis) will not work.
fix
Use ioredis explicitly: npm install ioredis
affects: >=0.0.1
breakingVersion 0.0.x is in beta; minor versions may introduce breaking changes without notice.
fix
Pin to exact version and test upgrades thoroughly.
affects: 0.0.x
deprecatedThe require pattern shown in examples uses CommonJS without destructuring, which may lead to 'StreamChannelBroker is not a constructor' error.
fix
Use destructured require: const { StreamChannelBroker } = require('redis-streams-broker');
affects: >=0.0.1
gotchaConsumer group subscription requires a callback that receives an array of payloads; if the callback throws, the message might be lost unless handled inside the callback.
fix
Wrap callback logic in try-catch and handle errors gracefully.
affects: >=0.0.1
gotchaThe `markAsRead` method must be called for each payload; otherwise messages remain pending and may accumulate.
fix
Always call await element.markAsRead() after processing each payload.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: StreamChannelBroker is not a constructor
Using require('redis-streams-broker') directly instead of destructuring the named export.
fix
Use const { StreamChannelBroker } = require('redis-streams-broker');
Error: ERR unknown command 'XGROUP'
Redis server version is too old (pre-5.0) or module not loaded; consumer group commands require Redis 5.0+.
fix
Upgrade Redis to version 5.0 or later.
TypeError: redisClient.pipeline is not a function
The provided Redis client does not support pipeline (only ioredis supports it natively).
fix
Use an ioredis client instance.
Upgrade
Version history
0.0.15latest on npm
Audit
Dependencies
ioredisrequiredOnly supported Redis client for injecting
nanoidrequiredAuto-generating subscription handles
redis-scripto2requiredLoading Lua scripts for Redis commands
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
redis-streams-broker — npm install redis-streams-broker · libregistry