@coolgk/utils
Version:
javascript, typescript utility and wrapper functions and classes: array, string, base64, ampq, bcrypt, cache, captcha, csv, email, jwt, number, pdf, tmp, token, unit conversion, url params, session, form data, google sign in, facebook sign in
64 lines (62 loc) • 1.9 kB
TypeScript
/*!
* @package @coolgk/utils
* @version 3.1.4
* @link https://github.com/coolgk/node-utils
* @license MIT
* @author Daniel Gong <daniel.k.gong@gmail.com>
*
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved.
* Licensed under the MIT License.
*/
/// <reference types="uuid" />
/*!
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved.
* Licensed under the MIT License.
*/
import { connect, Message, Replies } from 'amqplib';
import { v1 } from 'uuid';
export interface IAmqpConfig {
readonly url: string;
readonly connect?: typeof connect;
readonly uuid?: typeof v1;
readonly sslPem?: string;
readonly sslCa?: string;
readonly sslPass?: string;
}
export interface IConsumeConfig {
routes?: string | string[];
queueName?: string;
exchangeName?: string;
priority?: number;
prefetch?: number;
exchangeType?: string;
fallbackExchange?: string;
}
export interface IMessage {
rawMessage: Message | null;
message: any;
}
export interface IResponseMessage {
rawResponseMessage: Message | null;
responseMessage: any;
}
export declare class Amqp {
private _url;
private _sslPem;
private _sslCa;
private _sslPass;
private _uuid;
private _connect;
private _channel;
private _connection;
constructor(options: IAmqpConfig);
closeConnection(): void;
publish(message: any, callback?: (message: IResponseMessage) => any, {routes, exchangeName}?: {
routes?: string;
exchangeName?: string;
}): Promise<boolean[]>;
consume(callback: (message: IMessage) => any, {routes, queueName, exchangeName, exchangeType, priority, prefetch, fallbackExchange}?: IConsumeConfig): Promise<Replies.Consume[]>;
getChannel(): any;
private _publish(channel, exchangeName, routes, message, options);
}
export default Amqp;