Documentation
    Preparing search index...

    Interface IMessageQueue

    Generic messaging queue implementation interface

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

    class SomeMQAdapter implements IMessageQueue extends EventEmitter {
    public async start(): Promise<SomeMQAdapter> {
    // ... implementation goes here
    return this;
    }
    public async stop(): Promise<SomeMQAdapter> {
    // ... implementation goes here
    return this;
    }
    public async send(
    toQueue: string,
    message: JsonObject,
    delay?: number
    ): Promise<string> {
    const messageId = uuid();
    // ... implementation goes here
    return messageId;
    }
    public async destroy(): Promise<void> {
    // ... implementation goes here
    }
    public async clear(): Promise<SomeMQAdapter> {
    // ... implementation goes here
    return this;
    }
    }
    ~~~
    interface IMessageQueue {
        clear(): Promise<IMessageQueue>;
        destroy(): Promise<void>;
        publish(data: JsonObject, toName?: string): Promise<void>;
        send(
            toQueue: string,
            message: JsonObject,
            delay?: number,
            errorHandler?: (err: Error) => void,
        ): Promise<string>;
        start(): Promise<IMessageQueue>;
        stop(): Promise<IMessageQueue>;
        subscribe(
            channel: string,
            handler: (data: JsonObject) => any,
        ): Promise<void>;
        unsubscribe(): Promise<void>;
    }

    Hierarchy

    Implemented by

    Index

    Methods

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

      Returns Promise<void>

    • 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)

      Parameters

      • data: JsonObject

        data to publish as channel message

      • OptionaltoName: string

        different name of the pubsub to publish to

      Returns Promise<void>

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

      Parameters

      • toQueue: string

        queue name to which message should be sent to

      • message: JsonObject

        message data

      • Optionaldelay: number

        if specified, message will be handled in the target queue after specified period of time in milliseconds.

      • OptionalerrorHandler: (err: Error) => void

        callback called only when internal error occurs during message send execution.

      Returns Promise<string>

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

      Parameters

      • channel: string

        channel name

      • handler: (data: JsonObject) => any

      Returns Promise<void>