ClusteredRedisQueue.subscribe() method
Subscribes the given handler on every redis host in the cluster, and remembers the subscription so servers that join later are subscribed automatically.
Signature:
subscribe(channel: string, handler: (data: JsonObject) => void): Promise<void>;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
channel |
string |
channel name within the 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 this instance already remembers one - both are raised here, so they fire on an empty cluster too, where there is no underlying queue to raise them
Remarks
Only one channel per instance is supported. Calling this again with the same channel registers an additional handler — every registration is remembered and all of them are invoked, including the same function registered twice. Calling it with a different channel throws before any state is touched, so the remembered channel keeps naming the channel that is actually subscribed.
Servers joining later are given every handler registered before they joined, in registration order.
Subscription uses its own connection and does not require start(), even when a host's startup fails or stalls. Subscription changes serialise per host, so a call can wait behind an earlier operation that never settles.
A rejected call is not retryable: its registration remains remembered and may already be installed on some hosts. Calling again adds another copy, including for future hosts. To rebuild a known registration set, await unsubscribe() and then register the desired handlers again.
The handler receives one invocation per host that delivers the message.
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.