UNPKG

2.22 kBTypeScriptView Raw
1import { connect, Connection, Channel } from 'amqplib';
2import { Logger } from '../log/LogManager';
3import { ReadyGate } from '../util/ReadyGate';
4import { RabbitmqClientConfig } from './RabbitmqConfig';
5export interface PublishOptions {
6 expiration?: string | number;
7 userId?: string;
8 CC?: string | string[];
9 mandatory?: boolean;
10 persistent?: boolean;
11 deliveryMode?: boolean | number;
12 BCC?: string | string[];
13 contentType?: string;
14 contentEncoding?: string;
15 headers?: any;
16 priority?: number;
17 correlationId?: string;
18 replyTo?: string;
19 messageId?: string;
20 timestamp?: number;
21 type?: string;
22 appId?: string;
23}
24export interface ConsumeOptions {
25 consumerTag?: string;
26 noLocal?: boolean;
27 noAck?: boolean;
28 exclusive?: boolean;
29 priority?: number;
30 arguments?: any;
31}
32export interface RepliesConsume {
33 consumerTag: string;
34}
35export declare abstract class RabbitmqClient {
36 protected channel: Channel;
37 protected connection: Connection;
38 protected logger: Logger;
39 protected clientConfig: RabbitmqClientConfig;
40 protected name: string;
41 /**
42 * Whether the connection should be closed. This is not a statud indicator that show whether the connection is closed.
43 * It is a flag that indicates whether the client has been purposely closed by code, as opposed to being closed because of an error.
44 */
45 protected closed: boolean;
46 protected reconnecting: boolean;
47 protected readyGate: ReadyGate;
48 protected shutdownFunction: () => void;
49 protected connectFunction: typeof connect;
50 constructor(clientConfig: RabbitmqClientConfig, name: string);
51 init(): Promise<void>;
52 /**
53 * Connect to RabbitMQ broker
54 */
55 protected connect(): Promise<void>;
56 private createConnection();
57 protected createChannel(): Promise<void>;
58 protected handleErrorOrClose(cause: string, err?: Error): void;
59 protected closeAllAndScheduleReconnection(): Promise<void>;
60 backoffWait(tryNum: number): Promise<void>;
61 attemptReconnection(): Promise<void>;
62 close(): Promise<void>;
63 private closeChannel();
64 private closeConnection();
65 protected debugMsg(str: any): string;
66}