Skip to content

Commit a6e1c63

Browse files
read me changes.
1 parent 1403de1 commit a6e1c63

3 files changed

Lines changed: 35 additions & 35 deletions

File tree

README.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,34 @@
22

33
![npm version](https://img.shields.io/npm/v/@plgworks/queue.svg?style=flat)
44

5-
PLG Works Queue helps with managing subscription and publish critical events using EventEmitter and RabbitMQ. All events get published using node EventEmitter and, if configured, events are also published through RabbitMQ, using topic-based exchange.
5+
PLG Works Queue helps with managing subscription and publish critical events using RabbitMQ. All events are published through RabbitMQ, using topic-based exchange.
66

7-
## Install
7+
## Prerequisites
8+
- Basic understanding of RabbitMQ - [reference](https://www.rabbitmq.com/tutorials/amqp-concepts.html)
9+
10+
## Installation
811

912
```bash
1013
npm install @plgworks/queue --save
1114
```
1215

1316
## Initialize
14-
While using this package initialize an instance of queue manager to use to publish an event or subscribe to an event(s). To initialize an instance RabbitMQ configuration is required. Using this instance various functional methods can be invoked. The configuration should include following parameters:
15-
- <b>username</b> [string] (mandatory)
16-
- <b>password</b> [string] (mandatory)
17-
- <b>host</b> [string] (mandatory)
18-
- <b>port</b> [string] (mandatory)
19-
- <b>heartbeats</b> [string] (mandatory) heartbeats defines after what period of time the peer TCP connection should be considered unreachable.
20-
- <b>clusterNodes</b> [Array] (mandatory) - List of RMQ hosts.
17+
RabbitMQ configuration is needed in initialization of the package. The configuration should include following parameters:
18+
- <b>username</b> [string] (mandatory) RabbitMQ connection credentials
19+
- <b>password</b> [string] (mandatory) RabbitMQ connection credentials
20+
- <b>host</b> [string] (mandatory) RabbitMQ host
21+
- <b>port</b> [string] (mandatory) RabbitMQ port
22+
- <b>heartbeats</b> [string] (mandatory) [heartbeats](https://www.rabbitmq.com/heartbeats.html) defines after what period of time the peer TCP connection should be considered unreachable.
23+
- <b>clusterNodes</b> [Array] (mandatory) - List of [RMQ cluster](https://www.rabbitmq.com/clustering.html#node-names) hosts.
2124
- <b>enableRabbitmq</b> [integer] (optional) 0 if local usage.
2225
- <b>switchHostAfterSec</b> [integer] (optional) Wait time before switching RMQ host.
2326
- <b>connectionTimeoutSec</b> [integer] (optional) Wait time for connection to establish.
2427

25-
Example snippet to initialize PLG Works queue manager.
26-
28+
Following snippet initializes PLG Works Queue Manager:
2729
```js
30+
// Import the queue module.
31+
const QueueManager = require('@plgworks/queue');
32+
2833
// Config Strategy for PLG Works Queue.
2934
configStrategy = {
3035
"rabbitmq": {
@@ -36,43 +41,39 @@ configStrategy = {
3641
"enableRabbitmq": 1
3742
}
3843
};
39-
// Import the queue module.
40-
const QueueManager = require('@plgworks/queue');
41-
const queueManagerInstance = await QueueManager.getInstance(configStrategy);
42-
```
4344

45+
// Create instance
46+
const queueManagerInstance = await QueueManager.getInstance(configStrategy);
47+
```
4448

45-
## Methods
46-
PLG Works Queue exposes following 3 methods:
47-
49+
## queueManagerInstance Object Methods
4850
- `queueManagerInstance.subscribeEvent.rabbit(topics, options, readCallback, subscribeCallback)`
51+
<br>Description: Subscribe to multiple topics over a queue.
52+
<br>Parameters:
4953
- <b>topics</b> [Array] (mandatory) - List of events to subscribe to.
50-
- <b>options</b> [object] (mandatory) -
54+
- <b>options</b> [object] (mandatory) Object with following keys:
5155
- <b>queue</b> [string] (optional) - Name of the queue on which you want to receive all your subscribed events. These queues and events, published in them, have TTL of 6 days. If a queue name is not passed, a queue with a unique name is created and is deleted when the subscriber gets disconnected.
5256
- <b>ackRequired</b> [integer] (optional) - The delivered message needs ack if passed 1 ( default 0 ). if 1 passed and ack not done, message will redeliver.
5357
- <b>broadcastSubscription</b> [integer] (optional) - Set to 1, when queue needs to be subscribed to broadcasting events.
5458
- <b>prefetch</b> [integer] (optional) - The number of messages released from queue in parallel. In case of ackRequired=1, queue will pause unless delivered messages are acknowledged.
5559
- <b>readCallback</b> [function] (mandatory) - Callback method will be invoked whenever there is a new notification.
5660
- <b>subscribeCallback</b> [function] (optional) - Callback method to return consumerTag.
5761

58-
<br>
59-
6062
- `queueManagerInstance.publishEvent.perform(params)`
61-
- <b>params</b> [object] (mandatory)
63+
<br>Description: Publish event to topics.
64+
<br>Parameters:
65+
- <b>params</b> [object] (mandatory) Object with following keys:
6266
- <b>topics</b> [Array] (optional) List of topic messages to publish.
6367
- <b>broadcast</b> [integer] (optional) When set to 1 message will be broadcasted to all channels. Default value is 0.
6468
- <b>publishAfter</b> [integer] (optional) Message to be sent after milliseconds.
6569
- <b>publisher</b> [string] (mandatory) Name of publisher
66-
- <b>message</b> [object] (mandatory)
67-
- <b>kind</b> [string] (madatory) Kind of the message.
70+
- <b>message</b> [object] (mandatory) Object with following keys:
71+
- <b>kind</b> [string] (mandatory) Kind of the message.
6872
- <b>payload</b> [object] (optional) Payload to identify message and extra info.
69-
70-
<br>
71-
7273

7374
## Examples:
7475

75-
#### 1. Subscribe to events published through RabbitMQ:
76+
### Subscribe to events published through RabbitMQ:
7677

7778
```js
7879
// Config Strategy for PLG Works Queue.
@@ -152,7 +153,7 @@ process.on('rmq_error', rmqError);
152153
subscribe();
153154
```
154155

155-
#### 2. Listen to multiple events with one subscriber.
156+
### Listen to multiple events with one subscriber.
156157

157158
```js
158159
// Config Strategy for PLG Works Queue.
@@ -181,7 +182,7 @@ const subscribeMultiple = async function() {
181182
subscribeMultiple();
182183
```
183184

184-
#### 3. Publish Notifications:
185+
### Publish Notifications:
185186

186187
- All events are by default published using EventEmitter and if configured, through RabbitMQ as well.
187188

@@ -220,7 +221,7 @@ const publish = async function() {
220221
publish();
221222
```
222223

223-
#### 4. Pause and Restart queue consumption:
224+
### Pause and Restart queue consumption:
224225

225226
- We also support pause and start queue consumption. According to your logical condition, you can fire below events from your process to cancel or restart consumption respectively.
226227

@@ -265,9 +266,8 @@ const subscribePauseRestartConsume = async function() {
265266
subscribePauseRestartConsume();
266267
```
267268

268-
269269
## Running test cases
270270
Run following command to execute test cases.
271271
```shell script
272272
./node_modules/.bin/mocha --recursive "./test/**/*.js"
273-
```
273+
```

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0-beta.1
1+
1.0.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@plgworks/queue",
3-
"version": "1.0.0-beta.1",
3+
"version": "1.0.0",
44
"description": "Queue helps publish critical events using EventEmitter and RabbitMQ.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)