You're viewing archived documentation for @imqueue/core v1.15.0. APIs may differ from the current release. View the latest version ↗

IMessageQueue interface

Generic messaging queue implementation interface

Signature:

export interface IMessageQueue extends EventEmitter 

Extends: EventEmitter

Example

~~~typescript import { IMessageQueue, EventEmitter, uuid } from '@imqueue/core';

class SomeMQAdapter implements IMessageQueue extends EventEmitter { 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 = uuid(); // ... 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 queue data in queue host application. Supposed to be an async function.

destroy()

Safely destroys current queue, unregistered all set event listeners and connections. Supposed to be an async function.

publish(data, toName)

Publishes data to current queue channel

If toName specified will publish to pubsub with different name. This can be used to implement broadcasting some messages to other subscribers on other pubsub channels. Different name should be in the same namespace (same imq prefix)

send(toQueue, message, delay, errorHandler)

Sends a message to given queue name with the given data. Supposed to be an async function.

start()

Starts the messaging queue. Supposed to be an async function.

stop()

Stops the queue (should stop handle queue messages). Supposed to be an async function.

subscribe(channel, handler)

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

unsubscribe()

Closes subscription channel

{Promise}