@team-supercharge/nest-amqp
Version:
AMQP 1.0 module for Nest framework
73 lines (72 loc) • 3.29 kB
TypeScript
import { Message, Source } from 'rhea-promise';
import { MessageControl } from '../../domain';
import { SendState } from '../../enum';
import { ListenOptions, SendOptions } from '../../interface';
import { AMQPService } from '../amqp/amqp.service';
import { ObjectValidatorService } from '../object-validator/object-validator.service';
/**
* Handles queue receivers and senders for the created connection.
*/
export declare class QueueService {
private readonly amqpService;
private readonly objectValidatorService;
private readonly receivers;
private readonly senders;
constructor(amqpService: AMQPService, objectValidatorService: ObjectValidatorService);
/**
* Creates a receiver which will listen to message on the given queue. The
* callback function will invoked with the body and the message control
* objects when a new message arrives on the queue. If a receiver is already
* created for the given queue then a new receiver won't be created.
*
* @param {string} source Name or Source object of the queue.
* @param {function(body: T, control: MessageControl, metadata: Omit<Message, 'body'>) => Promise<void>} callback Function what will invoked when message arrives.
* @param {ListenOptions<T>} options Options for message processing.
* @param {string} connection Name of the connection
*
* @public
*/
listen<T>(source: string | Source, callback: (body: T, control: MessageControl, metadata: Omit<Message, 'body'>) => Promise<void>, options: ListenOptions<T>, connection?: string): Promise<void>;
/**
* Creates a sender which will send messages to the given queue. If a sender
* is already created for the queue then a new sender won't be created.
*
* @param {string} target Name of the queue.
* @param {T} message Message body.
* @param {SendOptions} sendOptions Options for message sending.
* @param {string} connectionName Name of the connection the Sender should be attached to
*
* @return {Promise<SendState>} Result of sending the message.
*
* @public
*/
send<T>(target: string, message: T): Promise<SendState>;
send<T>(target: string, message: T, sendOptions: SendOptions): Promise<SendState>;
send<T>(target: string, message: T, connectionName: string): Promise<SendState>;
send<T>(target: string, message: T, sendOptions: SendOptions, connectionName: string): Promise<SendState>;
/**
* Closes the connection to the message broker. Waits for all running
* processes to complete.
*/
shutdown(): Promise<void>;
/**
* Clears the existing senders and receivers.
*/
clearSenderAndReceiverLinks(): void;
/**
* Removes listener from active listeners
*
* @param {string} source Name or Source object of the queue.
* @param {string} connection Name of the connection
*
* @returns {Promise<boolean>} Returns true if listener was removed, otherwise false. If listener was not found, returns false.
*
* @public
*/
removeListener(source: string | Source, connection?: string): Promise<boolean>;
private getReceiver;
private getSender;
private encodeMessage;
private decodeMessage;
private getLinkToken;
}