diff --git a/amqplib/amqplib-tests.ts b/amqplib/amqplib-tests.ts
index 7a1f512002..f99a3bde1a 100644
--- a/amqplib/amqplib-tests.ts
+++ b/amqplib/amqplib-tests.ts
@@ -1,5 +1,6 @@
///
+// promise api tests
import amqp = require("amqplib");
var msg = "Hello World";
@@ -19,3 +20,34 @@ amqp.connect("amqp://localhost")
.then(channel => channel.consume("myQueue", newMsg => console.log("New Message: " + newMsg.content.toString())))
.ensure(() => connection.close());
});
+
+// callback api tests
+import amqpcb = require("amqplib/callback_api");
+
+amqpcb.connect("amqp://localhost", (err, connection) => {
+ if(!err) {
+ connection.createChannel((err, channel) => {
+ if (!err) {
+ channel.assertQueue("myQueue", {}, (err, ok) => {
+ if(!err) {
+ channel.sendToQueue("myQueue", new Buffer(msg));
+ }
+ });
+ }
+ });
+ }
+});
+
+amqpcb.connect("amqp://localhost", (err, connection) => {
+ if(!err) {
+ connection.createChannel((err, channel) => {
+ if (!err) {
+ channel.assertQueue("myQueue", {}, (err, ok) => {
+ if(!err) {
+ channel.consume("myQueue", newMsg => console.log("New Message: " + newMsg.content.toString()));
+ }
+ });
+ }
+ });
+ }
+});
diff --git a/amqplib/amqplib.d.ts b/amqplib/amqplib.d.ts
index 0c7f0720a6..f125aaa070 100644
--- a/amqplib/amqplib.d.ts
+++ b/amqplib/amqplib.d.ts
@@ -1,22 +1,12 @@
// Type definitions for amqplib 0.3.x
// Project: https://github.com/squaremo/amqp.node
-// Definitions by: Michael Nahkies
+// Definitions by: Michael Nahkies , Ab Reitsma
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///
///
-declare module "amqplib" {
-
- import events = require("events");
- import when = require("when");
-
- interface Connection extends events.EventEmitter {
- close(): when.Promise;
- createChannel(): when.Promise;
- createConfirmChannel(): when.Promise;
- }
-
+declare module "amqplib/properties" {
module Replies {
interface Empty {
}
@@ -25,6 +15,9 @@ declare module "amqplib" {
messageCount: number;
consumerCount: number;
}
+ interface PurgeQueue {
+ messageCount: number;
+ }
interface DeleteQueue {
messageCount: number;
}
@@ -100,6 +93,22 @@ declare module "amqplib" {
fields: Object;
properties: Object;
}
+}
+
+declare module "amqplib" {
+
+ import events = require("events");
+ import when = require("when");
+ import shared = require("amqplib/properties")
+ import Replies = shared.Replies;
+ import Options = shared.Options;
+ import Message = shared.Message;
+
+ interface Connection extends events.EventEmitter {
+ close(): when.Promise;
+ createChannel(): when.Promise;
+ createConfirmChannel(): when.Promise;
+ }
interface Channel extends events.EventEmitter {
close(): when.Promise;
@@ -108,7 +117,7 @@ declare module "amqplib" {
checkQueue(queue: string): when.Promise;
deleteQueue(queue: string, options?: Options.DeleteQueue): when.Promise;
- purgeQueue(queue: string): when.Promise;
+ purgeQueue(queue: string): when.Promise;
bindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise;
unbindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise;
@@ -142,3 +151,68 @@ declare module "amqplib" {
function connect(url: string, socketOptions?: any): when.Promise;
}
+
+declare module "amqplib/callback_api" {
+
+ import events = require("events");
+ import shared = require("amqplib/properties")
+ import Replies = shared.Replies;
+ import Options = shared.Options;
+ import Message = shared.Message;
+
+ interface Connection extends events.EventEmitter {
+ close(callback?: (err: any) => void): void;
+ createChannel(callback: (err: any, channel: Channel) => void): void;
+ createConfirmChannel(callback: (err: any, confirmChannel: ConfirmChannel) => void): void;
+ }
+
+ interface Channel extends events.EventEmitter {
+ close(callback: (err: any) => void): void;
+
+ assertQueue(queue?: string, options?: Options.AssertQueue, callback?: (err:any, ok: Replies.AssertQueue) => void): void;
+ checkQueue(queue: string, callback?: (err: any, ok: Replies.AssertQueue) => void): void;
+
+ deleteQueue(queue: string, options?: Options.DeleteQueue, callback?: (err:any, ok: Replies.DeleteQueue) => void): void;
+ purgeQueue(queue: string, callback?: (err:any, ok: Replies.PurgeQueue) => void): void;
+
+ bindQueue(queue: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void;
+ unbindQueue(queue: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void;
+
+ assertExchange(exchange: string, type: string, options?: Options.AssertExchange, callback?: (err: any, ok: Replies.AssertExchange) => void): void;
+ checkExchange(exchange: string, callback?: (err: any, ok: Replies.Empty) => void): void;
+
+ deleteExchange(exchange: string, options?: Options.DeleteExchange, callback?: (err: any, ok: Replies.Empty) => void): void;
+
+ bindExchange(destination: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void;
+ unbindExchange(destination: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void;
+
+ publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish): boolean;
+ sendToQueue(queue: string, content: Buffer, options?: Options.Publish): boolean;
+
+ consume(queue: string, onMessage: (msg: Message) => any, options?: Options.Consume, callback?: (err: any, ok: Replies.Consume) => void): void;
+
+ cancel(consumerTag: string, callback?: (err: any, ok: Replies.Empty) => void): void;
+ get(queue: string, options?: Options.Get, callback?: (err: any, ok: Message | boolean) => void): void;
+
+ ack(message: Message, allUpTo?: boolean): void;
+ ackAll(): void;
+
+ nack(message: Message, allUpTo?: boolean, requeue?: boolean): void;
+ nackAll(requeue?: boolean): void;
+ reject(message: Message, requeue?: boolean): void;
+
+ prefetch(count: number, global?: boolean): void;
+ recover(callback?: (err: any, ok: Replies.Empty) => void): void;
+ }
+
+ interface ConfirmChannel extends Channel {
+ publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): boolean;
+ sendToQueue(queue: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): boolean;
+
+ waitForConfirms(callback?: (err: any) => void): void;
+ }
+
+ function connect(callback: (err: any, connection: Connection) => void): void;
+ function connect(url: string, callback: (err: any, connection: Connection) => void): void;
+ function connect(url: string, socketOptions: any, callback: (err: any, connection: Connection) => void): void;
+}