@sera4/essentia 1.1.36 → 1.1.37
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 +38 -10
- package/queue/publisher.js +5 -4
- package/queue/subscriber.js +5 -5
package/package.json
CHANGED
package/package.tar.gz
CHANGED
|
Binary file
|
package/queue/index.js
CHANGED
|
@@ -148,14 +148,15 @@ class S4Queue {
|
|
|
148
148
|
* Registers a new direct publisher on the given exchange.
|
|
149
149
|
* If exchange doesn't exist, one will be created.
|
|
150
150
|
* @param {String} exchange the name of the exchange on AMQP service.
|
|
151
|
+
* @param {Object} options connection options
|
|
151
152
|
*/
|
|
152
|
-
async registerDirectPublisher(exchange) {
|
|
153
|
+
async registerDirectPublisher(exchange, options) {
|
|
153
154
|
const name = exchange;
|
|
154
155
|
if (Object.keys(this.pubs).includes(name)) {
|
|
155
156
|
throw new Error(`Publisher ${name} already registered`);
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
const p = new Publisher(exchange, 'direct',
|
|
159
|
+
const p = new Publisher(exchange, 'direct', name, options);
|
|
159
160
|
await p.init(this.connection);
|
|
160
161
|
this.pubs[name] = p;
|
|
161
162
|
}
|
|
@@ -164,14 +165,15 @@ class S4Queue {
|
|
|
164
165
|
* Registers a new topic publisher on the given exchange.
|
|
165
166
|
* If exchange doesn't exist, one will be created.
|
|
166
167
|
* @param {String} exchange the name of the exchange on AMQP service.
|
|
168
|
+
* @param {Object} options connection options
|
|
167
169
|
*/
|
|
168
|
-
async registerTopicPublisher(exchange) {
|
|
170
|
+
async registerTopicPublisher(exchange, options) {
|
|
169
171
|
const name = exchange;
|
|
170
172
|
if (Object.keys(this.pubs).includes(name)) {
|
|
171
173
|
throw new Error(`Publisher ${name} already registered`);
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
const p = new Publisher(exchange, 'topic',
|
|
176
|
+
const p = new Publisher(exchange, 'topic', name, options);
|
|
175
177
|
await p.init(this.connection);
|
|
176
178
|
this.pubs[name] = p;
|
|
177
179
|
}
|
|
@@ -180,18 +182,29 @@ class S4Queue {
|
|
|
180
182
|
* Registers a new fanout publisher on the given exchange.
|
|
181
183
|
* If exchange doesn't exist, one will be created.
|
|
182
184
|
* @param {String} exchange the name of the exchange on AMQP service.
|
|
185
|
+
* @param {Object} options connection options
|
|
183
186
|
*/
|
|
184
|
-
async registerFanoutPublisher(exchange) {
|
|
187
|
+
async registerFanoutPublisher(exchange, options) {
|
|
185
188
|
const name = exchange;
|
|
186
189
|
if (Object.keys(this.pubs).includes(name)) {
|
|
187
190
|
throw new Error(`Publisher ${name} already registered`);
|
|
188
191
|
}
|
|
189
192
|
|
|
190
|
-
const p = new Publisher(exchange, 'fanout',
|
|
193
|
+
const p = new Publisher(exchange, 'fanout', name, options);
|
|
191
194
|
await p.init(this.connection);
|
|
192
195
|
this.pubs[name] = p;
|
|
193
196
|
}
|
|
194
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Checks whether or not a publisher with given parameters
|
|
200
|
+
* has been registered already
|
|
201
|
+
* @param {String} exchange the name of the exchange.
|
|
202
|
+
* @returns true if registered already, false otherwise
|
|
203
|
+
*/
|
|
204
|
+
hasPublisher(exchange) {
|
|
205
|
+
return Object.keys(this.pubs).includes(exchange);
|
|
206
|
+
}
|
|
207
|
+
|
|
195
208
|
/**
|
|
196
209
|
* Removes a previously registered publisher
|
|
197
210
|
* @param {String} exchange
|
|
@@ -214,14 +227,15 @@ class S4Queue {
|
|
|
214
227
|
* @param {String} exchange the name of the exchange.
|
|
215
228
|
* @param {String} queue the name of the queue.
|
|
216
229
|
* @param {String} key the name of the routing key.
|
|
230
|
+
* @param {Object} options connection options
|
|
217
231
|
*/
|
|
218
|
-
async registerDirectSubscriber(exchange, queue, key) {
|
|
232
|
+
async registerDirectSubscriber(exchange, queue, key, options) {
|
|
219
233
|
const name = `${exchange}-${queue}-${key}`;
|
|
220
234
|
if (Object.keys(this.subs).includes(name)) {
|
|
221
235
|
throw new Error(`Subscriber ${name} already registered`);
|
|
222
236
|
}
|
|
223
237
|
|
|
224
|
-
const s = new Subscriber(exchange, queue, 'direct',
|
|
238
|
+
const s = new Subscriber(exchange, queue, 'direct', key, name, options);
|
|
225
239
|
await s.init(this.connection);
|
|
226
240
|
this.subs[name] = s;
|
|
227
241
|
}
|
|
@@ -233,18 +247,32 @@ class S4Queue {
|
|
|
233
247
|
* @param {String} exchange the name of the exchange.
|
|
234
248
|
* @param {String} queue the name of the queue.
|
|
235
249
|
* @param {String} key the name of the routing key.
|
|
250
|
+
* @param {Object} options connection options
|
|
236
251
|
*/
|
|
237
|
-
async registerTopicSubscriber(exchange, queue, key) {
|
|
252
|
+
async registerTopicSubscriber(exchange, queue, key, options) {
|
|
238
253
|
const name = `${exchange}-${queue}-${key}`;
|
|
239
254
|
if (Object.keys(this.subs).includes(name)) {
|
|
240
255
|
throw new Error(`Subscriber ${name} already registered`);
|
|
241
256
|
}
|
|
242
257
|
|
|
243
|
-
const s = new Subscriber(exchange, queue, 'topic',
|
|
258
|
+
const s = new Subscriber(exchange, queue, 'topic', key, name, options);
|
|
244
259
|
await s.init(this.connection);
|
|
245
260
|
this.subs[name] = s;
|
|
246
261
|
}
|
|
247
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Checks whether or not a subscriber with given parameters
|
|
265
|
+
* has been registered already
|
|
266
|
+
* @param {String} exchange the name of the exchange.
|
|
267
|
+
* @param {String} queue the name of the queue.
|
|
268
|
+
* @param {String} key the name of the routing key.
|
|
269
|
+
* @returns true if registered already, false otherwise
|
|
270
|
+
*/
|
|
271
|
+
hasSubscriber(exchange, queue, key) {
|
|
272
|
+
const name = `${exchange}-${queue}-${key}`;
|
|
273
|
+
return Object.keys(this.subs).includes(name);
|
|
274
|
+
}
|
|
275
|
+
|
|
248
276
|
/**
|
|
249
277
|
* Removes a previously registered subscriber
|
|
250
278
|
* @param {String} exchange
|
package/queue/publisher.js
CHANGED
|
@@ -8,13 +8,14 @@ export class Publisher {
|
|
|
8
8
|
/**
|
|
9
9
|
* @param {String} exchange AMQP exchange name.
|
|
10
10
|
* @param {String} type direct|fanout| etc (supported types by RabbitMQ).
|
|
11
|
-
* @param {boolean} durable true if the messages should persist service restarts.
|
|
12
11
|
* @param {String} name a name to identify this publisher in the logs.
|
|
12
|
+
* @param {Object} options connection options
|
|
13
|
+
|
|
13
14
|
*/
|
|
14
|
-
constructor(exchange, type,
|
|
15
|
+
constructor(exchange, type, name, options = {}) {
|
|
15
16
|
this.exchange = exchange;
|
|
16
17
|
this.type = type;
|
|
17
|
-
this.
|
|
18
|
+
this.options = {durable: true, ...options};
|
|
18
19
|
this.name = name;
|
|
19
20
|
this.channel = null;
|
|
20
21
|
}
|
|
@@ -38,7 +39,7 @@ export class Publisher {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
logger.debug(`Initialized PUB channel for ${this.name}`);
|
|
41
|
-
await this.channel.assertExchange(this.exchange, this.type,
|
|
42
|
+
await this.channel.assertExchange(this.exchange, this.type, this.options);
|
|
42
43
|
|
|
43
44
|
this.channel.on("error", (err) => {
|
|
44
45
|
logger.debug(`Connection error for ${this.name}`, err);
|
package/queue/subscriber.js
CHANGED
|
@@ -10,15 +10,15 @@ export class Subscriber {
|
|
|
10
10
|
* @param {String} exchange name of the AMQP exchange.
|
|
11
11
|
* @param {String} queue name of the AMQP service.
|
|
12
12
|
* @param {String} type direct|fanout or other supported connection types.
|
|
13
|
-
* @param {boolean} durable durable connection or not.
|
|
14
13
|
* @param {String} key routing key. This will be used to bind the queue to the exchange.
|
|
15
14
|
* @param {String} name a usefull name to be printed in the logs.
|
|
15
|
+
* @param {Object} options connection options
|
|
16
16
|
*/
|
|
17
|
-
constructor(exchange, queue, type,
|
|
17
|
+
constructor(exchange, queue, type, key, name, options = {}) {
|
|
18
18
|
this.exchange = exchange;
|
|
19
19
|
this.queue = queue;
|
|
20
20
|
this.type = type;
|
|
21
|
-
this.
|
|
21
|
+
this.options = {durable: true, ...options};
|
|
22
22
|
this.key = key;
|
|
23
23
|
this.name = name;
|
|
24
24
|
this.channel = null;
|
|
@@ -55,8 +55,8 @@ export class Subscriber {
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
logger.debug(`Initialized SUB channel for ${this.name}`);
|
|
58
|
-
await this.channel.assertExchange(this.exchange, this.type,
|
|
59
|
-
await this.channel.assertQueue(this.queue,
|
|
58
|
+
await this.channel.assertExchange(this.exchange, this.type, this.options);
|
|
59
|
+
await this.channel.assertQueue(this.queue, this.options);
|
|
60
60
|
|
|
61
61
|
logger.debug(`Binding queue ${this.queue} on ${this.exchange} exchange for ${this.key} key`);
|
|
62
62
|
await this.channel.bindQueue(this.queue, this.exchange, this.key);
|