ClusteredRedisQueue class

Scales a single logical queue horizontally across several redis instances. This is what IMQ.create() returns when IMQOptions.cluster or IMQOptions.clusterManagers is supplied.

Signature:

export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<EventMap> 

Implements: IMessageQueue, EventEmitter<EventMap>

Remarks

Distribution is asymmetric, and this is the most important thing to know about the class: ClusteredRedisQueue.send() routes each message to exactly one server, chosen by health-aware round-robin that skips instances whose writer connection is not ready. Every other operation — start, stop, clear, destroy, publish, subscribe, unsubscribe and queueLength — fans out to every server.

Every fan-out uses Promise.all, so one failing host fails the whole call with no partial-failure reporting and no rollback.

The class only implements the EventEmitter interface rather than extending it, so instanceof EventEmitter is false and every emitter method is a delegating shim — see the individual methods for their fan-out semantics, and note in particular that ClusteredRedisQueue.once() is per-server.

Constructors

Constructor

Modifiers

Description

(constructor)(name, options, _mode)

Creates a clustered queue.

Properties

Property

Modifiers

Type

Description

logger

ILogger

Logger used for this cluster's own messages, defaulting to IMQOptions.logger or console.

name

string

Name of this queue, used as the queue name for every per-host queue in the cluster.

Methods

Method

Modifiers

Description

addListener(args)

Registers a listener on every server's queue and on the internal template. Alias of ClusteredRedisQueue.on().

addServer(server)

protected

Adds a single server to the cluster and returns its registration record.

clear()

Deletes this queue's data on every redis host in the cluster, concurrently.

destroy()

Destroys every server's queue — closing their connections and removing their event listeners — then unregisters this cluster from all configured cluster managers.

emit(args)

Emits an event on every server's queue and on the internal template, so each listener registered through this class runs once per server.

eventNames()

Returns the event names reported by a single representative emitter.

getMaxListeners()

Returns the maximum listener count of the internal template emitter.

listenerCount(args)

Returns the listener count reported by a single representative emitter.

listeners(args)

Returns the listeners of every server's queue plus the internal template, concatenated.

off(args)

Removes a listener from every server's queue and from the internal template.

on(args)

Registers a listener on every server's queue and on the internal template used to seed servers that join later.

once(args)

Registers a one-shot listener on every server's queue and on the internal template.

prependListener(args)

Registers a listener at the front of the queue on every server's queue and on the internal template.

prependOnceListener(args)

Registers a one-shot listener at the front of the queue on every server's queue and on the internal template.

publish(data, toName)

Publishes the payload on every redis host in the cluster.

queueLength()

Returns the total number of messages waiting, summed across every redis host in the cluster.

rawListeners(args)

Returns the raw listeners of every server's queue plus the internal template, concatenated.

removeAllListeners(args)

Removes every listener from every server's queue and from the internal template, so servers that join later also start clean.

removeListener(args)

Removes a listener from every server's queue and from the internal template. Alias of ClusteredRedisQueue.off().

removeServer(server)

protected

Removes a server from the cluster, matching by id or by host and port.

send(toQueue, message, delay, errorHandler)

Sends a message to one server of the cluster, selected by health-aware round-robin.

setMaxListeners(args)

Sets the maximum listener count on every server's queue and on the internal template.

start()

Starts every server's queue concurrently.

stop()

Stops message handling on every server concurrently.

subscribe(channel, handler)

Subscribes the given handler on every redis host in the cluster, and remembers the subscription so servers that join later are subscribed automatically.

unsubscribe()

Unsubscribes from the channel on every redis host and forgets the remembered subscription, so servers joining later are no longer subscribed automatically.

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