UNPKG

3.93 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 close(): Promise<void>;
29
30 assertQueue(queue: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
31 checkQueue(queue: string): Promise<Replies.AssertQueue>;
32
33 deleteQueue(queue: string, options?: Options.DeleteQueue): Promise<Replies.DeleteQueue>;
34 purgeQueue(queue: string): Promise<Replies.PurgeQueue>;
35
36 bindQueue(queue: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
37 unbindQueue(queue: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
38
39 assertExchange(exchange: string, type: 'direct' | 'topic' | 'headers' | 'fanout' | 'match' | string, options?: Options.AssertExchange): Promise<Replies.AssertExchange>;
40 checkExchange(exchange: string): Promise<Replies.Empty>;
41
42 deleteExchange(exchange: string, options?: Options.DeleteExchange): Promise<Replies.Empty>;
43
44 bindExchange(destination: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
45 unbindExchange(destination: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
46
47 publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish): boolean;
48 sendToQueue(queue: string, content: Buffer, options?: Options.Publish): boolean;
49
50 consume(queue: string, onMessage: (msg: ConsumeMessage | null) => void, options?: Options.Consume): Promise<Replies.Consume>;
51
52 cancel(consumerTag: string): Promise<Replies.Empty>;
53 get(queue: string, options?: Options.Get): Promise<GetMessage | false>;
54
55 ack(message: Message, allUpTo?: boolean): void;
56 ackAll(): void;
57
58 nack(message: Message, allUpTo?: boolean, requeue?: boolean): void;
59 nackAll(requeue?: boolean): void;
60 reject(message: Message, requeue?: boolean): void;
61
62 prefetch(count: number, global?: boolean): Promise<Replies.Empty>;
63 recover(): Promise<Replies.Empty>;
64}
65
66export interface ConfirmChannel extends Channel {
67 publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): boolean;
68 sendToQueue(queue: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): boolean;
69
70 waitForConfirms(): Promise<void>;
71}
72
73export const credentials: {
74 amqplain(username: string, password: string): {
75 mechanism: string;
76 response(): Buffer;
77 username: string;
78 password: string;
79 };
80 external(): {
81 mechanism: string;
82 response(): Buffer;
83 };
84 plain(username: string, password: string): {
85 mechanism: string;
86 response(): Buffer;
87 username: string;
88 password: string;
89 };
90};
91
92export function connect(url: string | Options.Connect, socketOptions?: any): Promise<Connection>;