@gabliam/amqp
Version:
amqp plugin for gabliam
82 lines (81 loc) • 2.79 kB
TypeScript
/// <reference types="node" />
import { ValueExtractor } from '@gabliam/core';
import { Message } from 'amqplib';
import { ConsumeOptions, ConsumerHandler, Controller, SendOptions } from './interfaces';
import { RabbitHandler } from './metadatas';
import { Queue } from './queue';
/**
* Amqp Connection
*/
export declare class AmqpConnection {
indexConfig: number;
name: string;
private url;
private undefinedValue;
private queues;
private valueExtractor;
private gzipEnabled;
private logger;
private state;
private connection;
private channel;
private consumerList;
private extractArgs;
constructor(indexConfig: number, name: string, url: string, undefinedValue: string, queues: Queue[], valueExtractor: ValueExtractor, gzipEnabled: boolean);
/**
* Start the connection
*/
start(): Promise<void>;
/**
* Add a consumer for a queue
*/
addConsume(queue: string, handler: ConsumerHandler, options?: ConsumeOptions): void;
/**
* contrust consumer with controller instance and HandlerMetadata
*/
constructAndAddConsume(propKey: string, handlerMetadata: RabbitHandler, controller: Controller): void;
/**
* Send a content to a queue.
* Content can be undefined
*/
sendToQueue(queue: string, content: any, options?: SendOptions): Promise<void>;
/**
* Send a content to a queue and Ack the message
* Content can be undefined
*/
sendToQueueAck(queue: string, content: any, msg: Message, options?: SendOptions): Promise<void>;
/**
* Basic RPC pattern with conversion.
* Send a Javascrip object converted to a message to a queue and attempt to receive a response, converting that to a Java object.
* Implementations will normally set the reply-to header to an exclusive queue and wait up for some time limited by a timeout.
*/
sendAndReceive<T = any>(queue: string, content: any, options?: SendOptions, timeout?: number): Promise<T>;
/**
* Stop the connection
*/
stop(): Promise<void>;
/**
* Test if queue exist
*/
queueExist(queueName: string): boolean;
/**
* Get the real queueName
*
* Search if the queueName is the index of the map of queues => return queueName
* Search if the queueName is a key value => return the value
* else return the queue passed on parameter
*/
getQueueName(queueName: string): any;
/**
* Convert content to buffer for send in queue
*/
contentToBuffer(content: any): Promise<Buffer>;
/**
* Parse content in message
*/
parseContent(msg: Message): Promise<any>;
private constructListener;
private constructConsumer;
private getExtractArgs;
private getChannel;
}