@citrineos/util
Version:
The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.
51 lines (50 loc) • 1.98 kB
TypeScript
import * as amqplib from 'amqplib';
import { ILogObj, Logger } from 'tslog';
import { AbstractMessageHandler, CallAction, ICache, IModule, SystemConfig } from '@citrineos/base';
/**
* Implementation of a {@link IMessageHandler} using RabbitMQ as the underlying transport.
*/
export declare class RabbitMqReceiver extends AbstractMessageHandler {
/**
* Constants
*/
private static readonly QUEUE_PREFIX;
private static readonly CACHE_PREFIX;
/**
* Fields
*/
protected _cache: ICache;
protected _connection?: amqplib.Connection;
protected _channel?: amqplib.Channel;
constructor(config: SystemConfig, logger?: Logger<ILogObj>, module?: IModule, cache?: ICache);
/**
* 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>;
/**
* Protected Methods
*/
/**
* Connect to RabbitMQ
*/
protected _connect(): Promise<amqplib.Channel>;
/**
* Underlying RabbitMQ message handler.
*
* @param message The AMQPMessage to process
*/
protected _onMessage(message: amqplib.ConsumeMessage | null, channel: amqplib.Channel): Promise<void>;
}