@sera4/essentia 1.0.22 → 1.0.24

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sera4/essentia",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "A library of utilities for Teleporte Web Services",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/package.tar.gz CHANGED
Binary file
package/queue/index.js CHANGED
@@ -149,31 +149,29 @@ class S4Queue {
149
149
  * @param {Object} msg a JSON object as the message.
150
150
  */
151
151
  async publishDirectMessage(exchange, key, msg) {
152
- return new Promise((resolve, reject) => {
153
- const p = this.pubs[exchange];
152
+ const p = this.pubs[exchange];
154
153
 
155
- if (!key) {
156
- reject(new Error(`Direct message require a key`));
157
- }
154
+ if (!key) {
155
+ reject(new Error(`Direct message require a key`));
156
+ }
158
157
 
159
- if (!p) {
160
- reject(new Error(`No PUB for ${exchange} found`));
161
- }
158
+ if (!p) {
159
+ reject(new Error(`No PUB for ${exchange} found`));
160
+ }
162
161
 
163
- if (p.type !== 'direct') {
164
- reject(new Error(`PUB ${exchange} is not direct`));
165
- }
162
+ if (p.type !== 'direct') {
163
+ reject(new Error(`PUB ${exchange} is not direct`));
164
+ }
166
165
 
167
- let content = msg;
168
- if (content.constructor !== ({}).constructor) {
169
- // if not in JSON format, let's make it so
170
- content = {
171
- msg: msg
172
- }
166
+ let content = msg;
167
+ if (content.constructor !== ({}).constructor) {
168
+ // if not in JSON format, let's make it so
169
+ content = {
170
+ msg: msg
173
171
  }
172
+ }
174
173
 
175
- return p.publish({key, content});
176
- });
174
+ return await p.publish({key, content});
177
175
  }
178
176
 
179
177
  /**
@@ -59,28 +59,24 @@ class Publisher {
59
59
  * A tracking uuid for the message will be returned.
60
60
  */
61
61
  async publish(msg) {
62
- return new Promise((resolve, reject) => {
62
+ if (!this.channel) {
63
+ throw(new Error(`No channel for ${this.name} to publish`));
64
+ }
65
+
66
+ const parcel = {
67
+ tracking_id: uuidv4(),
68
+ data: msg.content
69
+ }
70
+ logger.debug("Publishing message", parcel);
63
71
 
64
- if (!this.channel) {
65
- reject(new Error(`No channel for ${this.name} to publish`));
66
- }
72
+ const content = Buffer.from(JSON.stringify(parcel));
73
+ const res = await this.channel.publish(this.exchange, msg.key, content, {persistent: true});
67
74
 
68
- logger.debug("Publishing message", msg);
69
- const content = {
70
- tracking_id: uuidv4(),
71
- data: Buffer.from(JSON.stringify(msg.content))
72
- }
75
+ if (!res) {
76
+ throw(new Error("Channel write buffer is full"));
77
+ }
73
78
 
74
- this.channel.publish(this.exchange, msg.key, content, {persistent: true}, (err, ok) => {
75
- if (err) {
76
- logger.error(`An error occured publishing message to ${this.name}`);
77
- reject(err);
78
- } else {
79
- logger.debug("Message delivered:", msg);
80
- resolve(content.tracking_id);
81
- }
82
- });
83
- });
79
+ return parcel.tracking_id;
84
80
  }
85
81
  }
86
82