UNPKG

@citrineos/util

Version:

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

66 lines (65 loc) 2.94 kB
import { AbstractMessageSender, IMessage, IMessageConfirmation, IMessageSender, MessageState, OcppError, OcppRequest, OcppResponse, SystemConfig } from '@citrineos/base'; import * as amqplib from 'amqplib'; import { ILogObj, Logger } from 'tslog'; /** * Implementation of a {@link IMessageSender} using RabbitMQ as the underlying transport. */ export declare class RabbitMqSender extends AbstractMessageSender implements IMessageSender { /** * Constants */ private static readonly QUEUE_PREFIX; /** * Fields */ protected _connection?: amqplib.Connection; protected _channel?: amqplib.Channel; /** * Constructor for the class. * * @param {SystemConfig} config - The system configuration. * @param {Logger<ILogObj>} [logger] - The logger object. */ constructor(config: SystemConfig, logger?: Logger<ILogObj>); /** * Methods */ /** * Sends a request message with an optional payload and returns a promise that resolves to the confirmation message. * * @param {IMessage<OcppRequest>} message - The message to be sent. * @param {OcppRequest | undefined} payload - The optional payload to be sent with the message. * @return {Promise<IMessageConfirmation>} A promise that resolves to the confirmation message. */ sendRequest(message: IMessage<OcppRequest>, payload?: OcppRequest | undefined): Promise<IMessageConfirmation>; /** * Sends a response message and returns a promise of the message confirmation. * * @param {IMessage<OcppResponse | OcppError>} message - The message to send. * @param {OcppResponse | OcppError} payload - The payload to include in the response. * @return {Promise<IMessageConfirmation>} - A promise that resolves to the message confirmation. */ sendResponse(message: IMessage<OcppResponse | OcppError>, payload?: OcppResponse | OcppError): Promise<IMessageConfirmation>; /** * Sends a message and returns a promise that resolves to a message confirmation. * * @param {IMessage<OcppRequest | OcppResponse | OcppError>} message - The message to be sent. * @param {OcppRequest | OcppResponse | OcppError} [payload] - The payload to be included in the message. * @param {MessageState} [state] - The state of the message. * @return {Promise<IMessageConfirmation>} - A promise that resolves to a message confirmation. */ send(message: IMessage<OcppRequest | OcppResponse | OcppError>, payload?: OcppRequest | OcppResponse | OcppError, state?: MessageState): Promise<IMessageConfirmation>; /** * Shuts down the sender by closing the client. * * @return {Promise<void>} A promise that resolves when the client is closed. */ shutdown(): Promise<void>; /** * Protected Methods */ /** * Connect to RabbitMQ */ protected _connect(): Promise<amqplib.Channel>; }