UNPKG

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