RedisQueue.subscribe() method

Creates a subscription channel over redis and sets up channel data read handler. The effective Redis channel is <prefix>:<channel>.

Signature:

subscribe(channel: string, handler: (data: JsonObject) => void): Promise<void>;

Parameters

Parameter

Type

Description

channel

string

channel name within this queue's prefix namespace

handler

(data: JsonObject) => void

invoked with the parsed payload of each published message

Returns:

Promise<void>

Exceptions

TypeError when no channel name is given, or when a different channel name is supplied while a subscription is already open — an instance supports exactly one channel until RedisQueue.unsubscribe() resets it

Remarks

Calling this again with the same channel adds another handler rather than replacing the existing one, and every handler is invoked for each message.

A dedicated subscription connection is created on demand, so RedisQueue.start() is not required, and the subscription is re-established automatically after a reconnect.

Payloads are parsed as plain JSON (IMQOptions.useGzip does not apply to pub/sub). Neither a parse error nor an exception thrown by the handler is contained by the queue, so handlers should not throw.

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.