IMessageQueue.subscribe() method
Subscribes to the pub/sub channel with the given name and registers a handler for the data it delivers. The effective channel is <prefix>:<channel>.
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 a subscription is already open — an instance supports exactly one channel until IMessageQueue.unsubscribe() resets it
Remarks
Calling this repeatedly with the same channel name adds another handler rather than replacing the existing one, and all of them are invoked. The subscription uses its own connection, so it does not require IMessageQueue.start(), and it is re-established automatically after a reconnect.
Payloads are always plain JSON — IMQOptions.useGzip does not apply to pub/sub. Delivery is fire-and-forget: messages published while nobody is subscribed are lost, unlike queued messages.
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.