You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PLG Works Queue helps 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 EventEmitter and RabbitMQ. All events get published using node EventEmitter and, if configured, events are also published through RabbitMQ, using topic-based exchange.
6
6
7
-
# Install
7
+
##Install
8
8
9
9
```bash
10
10
npm install @plgworks/queue --save
11
11
```
12
12
13
-
# Examples:
13
+
## 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.
21
+
- <b>enableRabbitmq</b> [integer] (optional) 0 if local usage.
22
+
- <b>switchHostAfterSec</b> [integer] (optional) Wait time before switching RMQ host.
23
+
- <b>connectionTimeoutSec</b> [integer] (optional) Wait time for connection to establish.
14
24
15
-
#### Subscribe to events published through RabbitMQ:
25
+
Example snippet to initialize PLG Works queue manager.
16
26
17
-
- Basic example on how to listen a specific event. Arguments passed are:
18
-
- <b>Events</b> [Array] (mandatory) - List of events to subscribe to.
- <b>topics</b> [Array] (mandatory) - List of events to subscribe to.
50
+
- <b>options</b> [object] (mandatory) -
20
51
- <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.
21
-
- <b>ackRequired</b> [number] - (optional) - The delivered message needs ack if passed 1 ( default 0 ). if 1 passed and ack not done, message will redeliver.
22
-
- <b>prefetch</b> [number] (optional) - The number of messages released from queue in parallel. In case of ackRequired=1, queue will pause unless delivered messages are acknowledged.
23
-
- <b>Callback</b> [function] (mandatory) - Callback method will be invoked whenever there is a new notification.
52
+
- <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.
53
+
- <b>broadcastSubscription</b> [integer] (optional) - Set to 1, when queue needs to be subscribed to broadcasting events.
54
+
- <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.
55
+
- <b>readCallback</b> [function] (mandatory) - Callback method will be invoked whenever there is a new notification.
56
+
- <b>subscribeCallback</b> [function] (optional) - Callback method to return consumerTag.
- All events are by default published using EventEmitter and if configured, through RabbitMQ as well.
163
220
@@ -174,34 +231,29 @@ configStrategy = {
174
231
"enableRabbitmq":1
175
232
}
176
233
};
234
+
177
235
// Import the Queue module.
178
236
constQueueManager=require('@plgworks/queue');
179
237
constpublish=asyncfunction() {
180
238
let queueManagerInstance =awaitQueueManager.getInstance(configStrategy);
181
239
queueManagerInstance.publishEvent.perform(
182
240
{
183
-
topics:["event.ProposedBrandedToken"],
184
-
broadcast:1, // When set to 1 message will be broadcasted to all channels. 'topics' parameter should not be sent.
241
+
topics:["event.PublishTestEvent"],
242
+
broadcast:1, // When set to 1 message will be broadcasted to all channels.
185
243
publishAfter:1000, // message to be sent after milliseconds.
186
244
publisher:'MyPublisher',
187
245
message: {
188
-
kind:"event_received",
189
-
payload: {
190
-
event_name:'ProposedBrandedToken',
191
-
params: {
192
-
// params of the event
193
-
},
194
-
contract_address:'contract address',
195
-
chain_id:'Chain id',
196
-
chain_kind:'kind of the chain'
246
+
kind:"event_received",
247
+
payload: {
248
+
// Custom payload for message
249
+
}
197
250
}
198
-
}
199
251
});
200
252
};
201
253
publish();
202
254
```
203
255
204
-
#### Pause and Restart queue consumption:
256
+
#### 5. Pause and Restart queue consumption:
205
257
206
258
- 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.
0 commit comments