Registry / messaging / fastify-redis-channels

fastify-redis-channels

JSON →
library1.3.2jsnpmunverified

A Fastify plugin implementing a message broker using Redis streams, supporting pub/sub, IoT, and scalable consumer groups. Current stable version is 1.3.2. Release cadence is irregular. Key differentiators: seamless scaling from single Redis to cluster without code changes, native Promises, and automatic channel cleanup on Fastify close. Suitable for real-time applications like chat, SSE, and statistics processing.

npm install fastify-redis-channels
INSTALL
IMPORT
SIG · FASTIFY-REDIS-CHAN
F
fastify-redis-channels
messagingjavascriptv1.3.2
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.

default
import fastifyRedisChannels from 'fastify-redis-channels'
const fastifyRedisChannels = require('fastify-redis-channels')
Default import for ESM; CommonJS require also works but TypeScript might need esModuleInterop.
fastify-redis-channels (plugin)
fastify.register(require('fastify-redis-channels'), { /* options */ })
fastify.use(require('fastify-redis-channels'))
Must use register() as it's a Fastify plugin, not use().
RedisChannelsError
const { RedisChannelsError } = require('fastify-redis-channels')
const RedisChannelsError = require('fastify-redis-channels').RedisChannelsError
Named export for RedisChannelsError; available after registering.

Demonstrates registering the plugin with Redis configuration, producing a message to a channel, and consuming messages using a consumer group.

import fastify from 'fastify'; import fastifyRedisChannels from 'fastify-redis-channels'; const app = fastify(); await app.register(fastifyRedisChannels, { redis: { host: process.env.REDIS_HOST || 'localhost', port: parseInt(process.env.REDIS_PORT || '6379') } }); // Produce a message app.channels.produce('my-channel', { message: 'Hello, world!' }); // Consume messages (as a consumer group) app.channels.consume('my-channel', 'consumer-group-1', 'consumer-1', async (message) => { console.log('Received:', message); }); app.listen({ port: 3000 }, (err) => { if (err) console.error(err); });
Debug
Known issues
gotchaThe plugin uses @hearit-io/redis-channels under the hood; options passed to register are forwarded to RedisChannels. Not all options are documented in the plugin's README.
fix
Refer to @hearit-io/redis-channels documentation for all available options.
affects: *
gotchaChannels are automatically closed when the Fastify instance closes, but manual cleanup may be needed if you stop consuming early.
fix
Use app.channels.close() to close all channels manually if needed.
affects: *
gotchaThe consumer callback does not automatically acknowledge messages; you may need to manually acknowledge using message.ack() if using consumer groups with manual acknowledgment.
fix
Call message.ack() after processing to prevent message reprocessing.
affects: *
Errors
Common errors & fixes
Error: REQUEST_TIMEOUT: Redis is unreachable
Redis connection not configured or wrong host/port.
fix
Set correct REDIS_HOST and REDIS_PORT environment variables or pass options with correct redis host.
TypeError: Cannot read properties of undefined (reading 'channels')
Plugin not registered before accessing fastify.channels.
fix
Ensure app.register(fastifyRedisChannels, ...) is called before any route or decorator that uses channels.
Error: Channel 'my-channel' does not exist
Trying to consume from a channel that hasn't been created yet.
fix
Create the channel by producing a message to it first, or use an option to auto-create channels.
Upgrade
Version history
1.3.2latest on npm
Audit
Dependencies
fastifyrequiredRequired to register as a Fastify plugin; cannot be used standalone.
@hearit-io/redis-channelsrequiredUnderlying implementation of Redis stream channels; options are passed through.
ioredisoptionalUsed for Redis connection; the plugin expects a Redis instance.
Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
fastify-redis-channels — npm install fastify-redis-channels · libregistry