UNPKG

3.5 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import * as events from "events";
4import { ConsumeMessage, GetMessage, Message, Options, Replies, ServerProperties } from "./properties";
5export * from "./properties";
6
7export interface Connection extends events.EventEmitter {
8 close(): Promise<void>;
9 createChannel(): Promise<Channel>;
10 createConfirmChannel(): Promise<ConfirmChannel>;
11 connection: {
12 serverProperties: ServerProperties;
13 };
14}
15
16export interface Channel extends events.EventEmitter {
17 connection: Connection;
18
19 close(): Promise<void>;
20
21 assertQueue(queue: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
22 checkQueue(queue: string): Promise<Replies.AssertQueue>;
23
24 deleteQueue(queue: string, options?: Options.DeleteQueue): Promise<Replies.DeleteQueue>;
25 purgeQueue(queue: string): Promise<Replies.PurgeQueue>;
26
27 bindQueue(queue: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
28 unbindQueue(queue: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
29
30 assertExchange(
31 exchange: string,
32 type: "direct" | "topic" | "headers" | "fanout" | "match" | string,
33 options?: Options.AssertExchange,
34 ): Promise<Replies.AssertExchange>;
35 checkExchange(exchange: string): Promise<Replies.Empty>;
36
37 deleteExchange(exchange: string, options?: Options.DeleteExchange): Promise<Replies.Empty>;
38
39 bindExchange(destination: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
40 unbindExchange(destination: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
41
42 publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish): boolean;
43 sendToQueue(queue: string, content: Buffer, options?: Options.Publish): boolean;
44
45 consume(
46 queue: string,
47 onMessage: (msg: ConsumeMessage | null) => void,
48 options?: Options.Consume,
49 ): Promise<Replies.Consume>;
50
51 cancel(consumerTag: string): Promise<Replies.Empty>;
52 get(queue: string, options?: Options.Get): Promise<GetMessage | false>;
53
54 ack(message: Message, allUpTo?: boolean): void;
55 ackAll(): void;
56
57 nack(message: Message, allUpTo?: boolean, requeue?: boolean): void;
58 nackAll(requeue?: boolean): void;
59 reject(message: Message, requeue?: boolean): void;
60
61 prefetch(count: number, global?: boolean): Promise<Replies.Empty>;
62 recover(): Promise<Replies.Empty>;
63}
64
65export interface ConfirmChannel extends Channel {
66 publish(
67 exchange: string,
68 routingKey: string,
69 content: Buffer,
70 options?: Options.Publish,
71 callback?: (err: any, ok: Replies.Empty) => void,
72 ): boolean;
73 sendToQueue(
74 queue: string,
75 content: Buffer,
76 options?: Options.Publish,
77 callback?: (err: any, ok: Replies.Empty) => void,
78 ): boolean;
79
80 waitForConfirms(): Promise<void>;
81}
82
83export const credentials: {
84 amqplain(username: string, password: string): {
85 mechanism: string;
86 response(): Buffer;
87 username: string;
88 password: string;
89 };
90 external(): {
91 mechanism: string;
92 response(): Buffer;
93 };
94 plain(username: string, password: string): {
95 mechanism: string;
96 response(): Buffer;
97 username: string;
98 password: string;
99 };
100};
101
102export function connect(url: string | Options.Connect, socketOptions?: any): Promise<Connection>;