@sera4/essentia 1.0.34 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/package.tar.gz +0 -0
- package/queue/index.js +39 -1
- package/queue/publisher.js +5 -1
package/package.json
CHANGED
package/package.tar.gz
CHANGED
|
Binary file
|
package/queue/index.js
CHANGED
|
@@ -171,6 +171,22 @@ class S4Queue {
|
|
|
171
171
|
this.pubs[name] = p;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Registers a new fanout publisher on the given exchange.
|
|
176
|
+
* If exchange doesn't exist, one will be created.
|
|
177
|
+
* @param {String} exchange the name of the exchange on AMQP service.
|
|
178
|
+
*/
|
|
179
|
+
async registerFanoutPublisher(exchange) {
|
|
180
|
+
const name = exchange;
|
|
181
|
+
if (Object.keys(this.pubs).includes(name)) {
|
|
182
|
+
throw new Error(`Publisher ${name} already registered`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const p = new Publisher(exchange, 'fanout', true, name);
|
|
186
|
+
await p.init(this.connection);
|
|
187
|
+
this.pubs[name] = p;
|
|
188
|
+
}
|
|
189
|
+
|
|
174
190
|
/**
|
|
175
191
|
* Registers a new direct subscriber on a given exchange and queue.
|
|
176
192
|
* If exchange and queue don't exists, they'll be created
|
|
@@ -273,6 +289,28 @@ class S4Queue {
|
|
|
273
289
|
return await p.publish({key: topic, content});
|
|
274
290
|
}
|
|
275
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Binds an exchange to a queue
|
|
294
|
+
* @param {String} exchange the name of the exchange.
|
|
295
|
+
* @param {String} queue the name of the queue.
|
|
296
|
+
* @param {pattern} (optional) pattern for routing key
|
|
297
|
+
*/
|
|
298
|
+
async bindQueueToExchange(exchange, queue, pattern) {
|
|
299
|
+
const p = this.pubs[exchange];
|
|
300
|
+
|
|
301
|
+
if (!p) {
|
|
302
|
+
throw(new Error(`No PUB for ${exchange} found`));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (!queue) {
|
|
306
|
+
throw(new Error(`Binding a queue requires a queue name`));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return await p.bindQueue(queue, pattern)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
276
314
|
/**
|
|
277
315
|
* Adds a listener for a specific key.
|
|
278
316
|
* If a subscriber that was regitered was found
|
|
@@ -291,4 +329,4 @@ class S4Queue {
|
|
|
291
329
|
}
|
|
292
330
|
}
|
|
293
331
|
|
|
294
|
-
module.exports = new S4Queue();
|
|
332
|
+
module.exports = new S4Queue();
|
package/queue/publisher.js
CHANGED