UNPKG

@team-supercharge/nest-amqp

Version:
65 lines (64 loc) 2.64 kB
/// <reference types="node" /> import { EventEmitter } from 'events'; import { AwaitableSender, Connection, EventContext, Receiver, Source } from 'rhea-promise'; import { AMQPConnectionOptions } from '../../interface'; /** * Can create a single connection and manage the senders and receivers for it. * * @public */ export declare class AMQPService { /** * Event emitter for AMQP to show what is happening with the created connection. */ static readonly eventEmitter: EventEmitter; /** * Parses the connection URI and connect to the message broker by the given * information. * * NOTE: If the connection closes and there was no error then the service will * attempt to reconnect to the message broker but only once. * * ```ts * const connection = await AMQPService.createConnection({ connectionUri: 'amqp://user:password@localhost:5672' }); * ``` * * @param {QueueModuleOptions} options Options for the module. * @param {string} [connectionToken] Name of the connection that is created * * @return {Connection} The created `rhea-promise` Connection. * @static */ static createConnection(options: AMQPConnectionOptions, connectionToken?: string): Promise<Connection>; /** * Returns the connection object with which the AMQP connection was created. * * @return {AMQPConnectionOptions} Connection options. */ getConnectionOptions(connection?: string): AMQPConnectionOptions; /** * Closes all the created connections. */ disconnect(): Promise<void>; /** * Creates a sender object which will send the message to the given queue. * * @param {string} queue Name of the queue. * @param {string} [connectionName] Name of the connection the sender will use * * @return {AwaitableSender} Sender. */ createSender(queue: string, connectionName?: string): Promise<AwaitableSender>; /** * Creates a receiver object which will send the message to the given queue. * * @param {string} source Name of the queue. * @param {number} credits How many message can be processed parallel. * @param {function(context: EventContext): Promise<void>} onMessage Function what will be invoked when a message arrives. * @param {string} [connectionToken] Name of the connection the receiver is on * * @return {Receiver} Receiver. */ createReceiver(source: string | Source, credits: number, onMessage: (context: EventContext) => Promise<void>, connectionToken?: string): Promise<Receiver>; private static getTransport; }