rabbit-queue
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -27,2 +27,3 @@ import Rabbit from './rabbit'; | ||
handleError(err: any, msg: any): void; | ||
getTime(): number; | ||
logTime(startTime: number, correlationId: string): void; | ||
@@ -29,0 +30,0 @@ setTimeout(time: any): Promise<{}>; |
@@ -53,3 +53,3 @@ "use strict"; | ||
try { | ||
const startTime = new Date().getTime(); | ||
const startTime = this.getTime(); | ||
var body = msg.content.toString(); | ||
@@ -82,4 +82,7 @@ const event = JSON.parse(body); | ||
} | ||
getTime() { | ||
return new Date().getTime(); | ||
} | ||
logTime(startTime, correlationId) { | ||
this.logger.debug(`[${correlationId}] Queue processing took [${this.queueName}] ${(new Date().getTime() - startTime)} ms`); | ||
this.logger.debug(`[${correlationId}] Queue processing took ${(new Date().getTime() - startTime)} ms`); | ||
} | ||
@@ -86,0 +89,0 @@ setTimeout(time) { |
{ | ||
"name": "rabbit-queue", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "AMQP/RabbitMQ queue management library.", | ||
"main": "js/index.js", | ||
"keywords": [ | ||
"rabbitmq", | ||
"rabbit", | ||
"queue", | ||
"amqp", | ||
"amqplib" | ||
], | ||
"scripts": { | ||
@@ -7,0 +14,0 @@ "tsc": "tsc -p ts", |
@@ -13,13 +13,13 @@ # Rabbit Queue | ||
This module is based on [WRabbit](https://github.com/Workable/wrabbit) | ||
and [jackrabbit](https://github.com/hunterloftis/jackrabbit). | ||
and [Jackrabbit](https://github.com/hunterloftis/jackrabbit). | ||
It makes [RabbitMQ](http://www.rabbitmq.com/) managemnent and integration easy. Provides an abstraction layer | ||
It makes [RabbitMQ](http://www.rabbitmq.com/) management and integration easy. Provides an abstraction layer | ||
above [amqplib](https://github.com/squaremo/amqp.node). | ||
It is written in typescript and requires node v6.0.0 or higher. If you want to use it | ||
with an older version please dowload the sources and build them with target (`/ts/tsconfig.json`). | ||
It is written in typescript and requires node v6.0.0 or higher. | ||
## Connectint to [RabbitMQ](http://www.rabbitmq.com/) | ||
## Connecting to RabbitMQ | ||
```javascript | ||
const {Rabbit} = require('rabbit-queue'); | ||
const rabbit = new Rabbit(process.env.RABBIT_URL || 'amqp://localhost', { | ||
@@ -47,3 +47,2 @@ prefetch: 1, //default prefetch from queue | ||
const {Rabbit} = require('rabbit-queue'); | ||
const rabbit = new Rabbit('amqp://localhost'); | ||
@@ -71,3 +70,3 @@ | ||
await rabbit.createQueue('queueName', { durable: false }, (msg, ack) => { | ||
rabbit.createQueue('queueName', { durable: false }, (msg, ack) => { | ||
console.log(msg.content.toString()); | ||
@@ -77,8 +76,8 @@ ack('response'); | ||
await rabbit.bindToExchange('queueName', 'amq.topic', 'routingKey'); | ||
//shortcut await rabbit.bindToTopic('queueName', 'routingKey'); | ||
rabbit.bindToExchange('queueName', 'amq.topic', 'routingKey'); | ||
//shortcut rabbit.bindToTopic('queueName', 'routingKey'); | ||
await rabbit.publishExchange('amq.topic', 'routingKey', { test: 'data' }, { correlationId: '1' }) | ||
rabbit.publishExchange('amq.topic', 'routingKey', { test: 'data' }, { correlationId: '1' }) | ||
.then(() => console.log('message published')); | ||
//shortcut await rabbit.publishTopic( 'routingKey', { test: 'data' }, { correlationId: '1' }); | ||
//shortcut rabbit.publishTopic( 'routingKey', { test: 'data' }, { correlationId: '1' }); | ||
@@ -91,3 +90,2 @@ ``` | ||
const rabbit = new Rabbit('amqp://localhost'); | ||
class DemoHandler extends BaseQueueHandler { | ||
@@ -118,3 +116,3 @@ handle({msg, event, correlationId, startTime}) { | ||
```javascript | ||
const rabbit = new Rabbit(process.env.RABBIT_URL || 'amqp://localhost'); | ||
const rabbit = new Rabbit(process.env.RABBIT_URL || 'amqp://localhost'); | ||
class DemoHandler extends BaseQueueHandler { | ||
@@ -140,3 +138,3 @@ handle({msg, event, correlationId, startTime}) { | ||
await rabbit.getReply('demoQueue', { test: 'data' }, { correlationId: '5' }) | ||
rabbit.getReply('demoQueue', { test: 'data' }, { correlationId: '5' }) | ||
.then((reply) => console.log('received reply', reply)); | ||
@@ -167,3 +165,3 @@ ``` | ||
await rabbit.getReply('demoQueue', { test: 'data' }, { correlationId: '5' }) | ||
rabbit.getReply('demoQueue', { test: 'data' }, { correlationId: '5' }) | ||
.then((reply) => console.log('received reply', reply)); //reply will be ''; | ||
@@ -170,0 +168,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
319417
721
168