From a87ec5fe4911f3979cdcee9fa5b3ee6fbba1f8b8 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Sun, 11 Jun 2017 12:31:34 +0200 Subject: [PATCH] Update bunnymq definition (2.3.2). --- types/bunnymq/bunnymq-tests.ts | 21 ++++------------ types/bunnymq/index.d.ts | 45 +++++++++------------------------- 2 files changed, 16 insertions(+), 50 deletions(-) diff --git a/types/bunnymq/bunnymq-tests.ts b/types/bunnymq/bunnymq-tests.ts index 4105363f25..e83fe606da 100644 --- a/types/bunnymq/bunnymq-tests.ts +++ b/types/bunnymq/bunnymq-tests.ts @@ -4,31 +4,20 @@ import * as bunnymq from "bunnymq"; var instance = bunnymq({ host: 'amqp://localhost' }); // Publisher -instance.producer.produce('queue:name', 'Hello World!'); +instance.publish("queue:name", "message"); // Subscriber -instance.consumer.consume('queue:name', message => { }); +instance.subscribe('queue:name', (message: string) => "hello,world"); // RPC Support -instance.producer.produce('queue:name', { message: 'content' }, { rpc: true }) - .then(function (consumerResponse) { - console.log(consumerResponse); - }); - -// Routing keys -instance.producer.produce('queue:name', { message: 'content' }, { routingKey: 'my-routing-key' }); +instance.publish('queue:name', { message: 'content' }, { routingKey: 'my-routing-key', rpc: true }).then((consumerResponse: string) => { }); // Config var custom = bunnymq({ host: 'amqp://localhost', - //number of fetched messages at once on the channel prefetch: 5, - //requeue put back message into the broker if consumer crashes/trigger exception requeue: true, - //time between two reconnect (ms) timeout: 1000, - consumerSuffix: '', - //generate a hostname so we can track this connection on the broker (rabbitmq management plugin) + consumerSuffix: "", hostname: "", - //the transport to use to debug. if provided, bunnymq will show some logs transport: new Object() -}); \ No newline at end of file +}); diff --git a/types/bunnymq/index.d.ts b/types/bunnymq/index.d.ts index 1167db21ed..867ebfd82c 100644 --- a/types/bunnymq/index.d.ts +++ b/types/bunnymq/index.d.ts @@ -1,25 +1,10 @@ -// Type definitions for node-bunnymq 2.2.1 +// Type definitions for node-bunnymq 2.3.2 // Project: https://github.com/dial-once/node-bunnymq // Definitions by: Cyril Schumacher // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module "bunnymq" { namespace bunnymq { - export type ConsumerCallback = (message: Object) => void; - - /** - * Consumer. - * @interface - */ - export interface Consumer { - /** - * Handle messages from a named queue. - * @param {string} queue A named queue. - * @param {ConsumerCallback} callback A callback. - */ - consume(queue: string, callback: ConsumerCallback): void; - } - /** * bunnymq instance. * @interface @@ -29,13 +14,13 @@ declare module "bunnymq" { * Consumer. * @type {Consumer} */ - consumer: Consumer; + subscribe(queueName: string, callback: (...args: any[]) => T): void; /** * Producer. * @type {Producer} */ - producer: Producer; + publish(queueName: string, message: any, options?: PublisherOptions): Promise; } /** @@ -73,6 +58,12 @@ declare module "bunnymq" { */ requeue?: boolean; + /** + * Default timeout for RPC calls. + * @type {number} + */ + rpcTimeout?: number; + /** * Time between two reconnect (in milliseconds). * @type {number} @@ -87,24 +78,10 @@ declare module "bunnymq" { } /** - * Producer. - * @inteface - */ - export interface Producer { - /** - * Send messages to a named queue. - * @param {string} queue A named queue. - * @param {Object} message A message. - * @return {Object} The consumer response. - */ - produce(queue: string, message: Object, options?: ProducerOptions): PromiseLike; - } - - /** - * Options for producer. + * Options for publisher. * @interface */ - export interface ProducerOptions { + export interface PublisherOptions { routingKey?: string; rpc?: boolean; }