UNPKG

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