Home > @imqueue/rpc > IMessageQueue

IMessageQueue interface

Generic messaging queue implementation interface

Signature:

export interface IMessageQueue extends EventEmitter<EventMap> 

Extends: EventEmitter<EventMap>

Example

~~~typescript import { IMessageQueue, EventEmitter } from '@imqueue/core'; import { randomUUID } from 'node:crypto';

class SomeMQAdapter extends EventEmitter implements IMessageQueue { public async start(): Promise { // ... implementation goes here return this; } public async stop(): Promise { // ... implementation goes here return this; } public async send( toQueue: string, message: JsonObject, delay?: number, ): Promise { const messageId = randomUUID(); // ... implementation goes here return messageId; } public async destroy(): Promise { // ... implementation goes here } public async clear(): Promise { // ... implementation goes here return this; } } ~~~

Methods

Method

Description

clear()

Clears all queue data from the queue host application.

destroy()

Safely destroys the current queue, unregistering all event listeners and closing connections.

publish(data, toName)

Publishes data to the current queue channel

If toName is specified, publishes to a pubsub with a different name. This can be used to broadcast messages to other subscribers on different pubsub channels. Different names must be in the same namespace (same imq prefix).

queueLength()

Retrieves the current count of messages in the queue. Supposed to be an async function.

send(toQueue, message, delay, errorHandler)

Sends a message to the specified queue with the given data.

start()

Starts the messaging queue.

stop()

Stops the queue from handling messages.

subscribe(channel, handler)

Creates or uses a subscription channel with the given name and sets message handler on data receive

unsubscribe()

Closes the subscription channel