UNPKG

@citrineos/util

Version:

The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.

48 lines (47 loc) 2 kB
import type { CallAction, IModule } from '@citrineos/base'; import { AbstractMessageHandler } from '@citrineos/base'; import * as amqplib from 'amqplib'; import type { ILogObj } from 'tslog'; import { Logger } from 'tslog'; import { RabbitMQChannelManager } from './ChannelManager.js'; /** * Implementation of a {@link IMessageHandler} using RabbitMQ as the underlying transport. */ export declare class RabbitMqReceiver extends AbstractMessageHandler { private exchange; /** * Constants */ private static readonly QUEUE_PREFIX; private static readonly CHANNEL_ID; /** * Fields */ protected _channelManager: RabbitMQChannelManager; protected _consumerTags: Map<string, string[]>; constructor(exchange: string, channelManager: RabbitMQChannelManager, logger?: Logger<ILogObj>, module?: IModule); /** * Methods */ /** * Binds queue to an exchange given identifier and optional actions and filter. * Note: Due to the nature of AMQP 0-9-1 model, if you need to filter for the identifier, you **MUST** provide it in the filter object. * * @param {string} identifier - The identifier of the channel to subscribe to. * @param {CallAction[]} actions - Optional. An array of actions to filter the messages. * @param {{ [k: string]: string; }} filter - Optional. An object representing the filter to apply on the messages. * @return {Promise<boolean>} A promise that resolves to true if the subscription is successful, false otherwise. */ subscribe(identifier: string, actions?: CallAction[], filter?: { [k: string]: string; }): Promise<boolean>; unsubscribe(identifier: string): Promise<boolean>; shutdown(): Promise<void>; /** * Underlying RabbitMQ message handler. * * @param message The AMQPMessage to process * @param channel */ protected _onMessage(message: amqplib.ConsumeMessage | null, channel: amqplib.Channel): Promise<void>; }