@sera4/essentia 1.1.38 → 1.1.39
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 +14 -31
- package/queue/publisher.js +1 -1
package/package.json
CHANGED
package/package.tar.gz
CHANGED
|
Binary file
|
package/queue/index.js
CHANGED
|
@@ -309,29 +309,7 @@ class S4Queue {
|
|
|
309
309
|
* @param {Object} msg a JSON object as the message.
|
|
310
310
|
*/
|
|
311
311
|
async publishDirectMessage(exchange, key, msg) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (!key) {
|
|
315
|
-
throw(new Error(`Direct message require a key`));
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (!p) {
|
|
319
|
-
throw(new Error(`No PUB for ${exchange} found`));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (p.type !== 'direct') {
|
|
323
|
-
throw(new Error(`PUB ${exchange} is not direct`));
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
let content = msg;
|
|
327
|
-
if (content.constructor !== ({}).constructor) {
|
|
328
|
-
// if not in JSON format, let's make it so
|
|
329
|
-
content = {
|
|
330
|
-
msg: msg
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return await p.publish({key, content});
|
|
312
|
+
return this.publishMessage(exchange, key, msg)
|
|
335
313
|
}
|
|
336
314
|
|
|
337
315
|
/**
|
|
@@ -341,20 +319,25 @@ class S4Queue {
|
|
|
341
319
|
* @param {Object} msg a JSON object as the message.
|
|
342
320
|
*/
|
|
343
321
|
async publishTopicMessage(exchange, topic, msg) {
|
|
344
|
-
|
|
322
|
+
return this.publishMessage(exchange, topic, msg)
|
|
323
|
+
}
|
|
345
324
|
|
|
346
|
-
|
|
347
|
-
|
|
325
|
+
/**
|
|
326
|
+
* Publish a message to the exchange
|
|
327
|
+
* @param {String} exchange name of exchange
|
|
328
|
+
* @param {String} key name of the key or topic
|
|
329
|
+
* @param {Object} msg payload to be published
|
|
330
|
+
*/
|
|
331
|
+
async publishMessage(exchange, key, msg) {
|
|
332
|
+
if (!key) {
|
|
333
|
+
throw(new Error(`Key argument not defined`));
|
|
348
334
|
}
|
|
349
335
|
|
|
336
|
+
const p = this.pubs[exchange];
|
|
350
337
|
if (!p) {
|
|
351
338
|
throw(new Error(`No PUB for ${exchange} found`));
|
|
352
339
|
}
|
|
353
340
|
|
|
354
|
-
if (p.type !== 'topic') {
|
|
355
|
-
throw(new Error(`PUB ${exchange} is not topic`));
|
|
356
|
-
}
|
|
357
|
-
|
|
358
341
|
let content = msg;
|
|
359
342
|
if (content.constructor !== ({}).constructor) {
|
|
360
343
|
// if not in JSON format, let's make it so
|
|
@@ -363,7 +346,7 @@ class S4Queue {
|
|
|
363
346
|
}
|
|
364
347
|
}
|
|
365
348
|
|
|
366
|
-
return await p.publish({key
|
|
349
|
+
return await p.publish({key, content});
|
|
367
350
|
}
|
|
368
351
|
|
|
369
352
|
/**
|
package/queue/publisher.js
CHANGED
|
@@ -68,7 +68,7 @@ export class Publisher {
|
|
|
68
68
|
logger.debug("Data", parcel);
|
|
69
69
|
|
|
70
70
|
const content = Buffer.from(JSON.stringify(parcel));
|
|
71
|
-
const res = await this.channel.publish(this.exchange, msg.key, content, {persistent: true});
|
|
71
|
+
const res = await this.channel.publish(this.exchange.name, msg.key, content, {persistent: true});
|
|
72
72
|
|
|
73
73
|
if (!res) {
|
|
74
74
|
throw(new Error("Channel write buffer is full"));
|