@imqueue/core 2.0.17 → 2.0.19

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": "@imqueue/core",
3
- "version": "2.0.17",
3
+ "version": "2.0.19",
4
4
  "description": "Simple JSON-based messaging queue for inter service communication",
5
5
  "keywords": [
6
6
  "message-queue",
package/src/RedisQueue.js CHANGED
@@ -57,8 +57,6 @@ exports.DEFAULT_IMQ_OPTIONS = {
57
57
  safeDeliveryTtl: 5000,
58
58
  useGzip: false,
59
59
  watcherCheckDelay: 5000,
60
- verbose: false,
61
- verboseExtended: false,
62
60
  };
63
61
  exports.IMQ_SHUTDOWN_TIMEOUT = +(process.env.IMQ_SHUTDOWN_TIMEOUT || 1000);
64
62
  /**
@@ -174,16 +172,9 @@ class RedisQueue extends events_1.EventEmitter {
174
172
  this.redisKey = `${this.options.host}:${this.options.port}`;
175
173
  this.verbose(`Initializing queue on ${this.options.host}:${this.options.port} with prefix ${this.options.prefix} and safeDelivery = ${this.options.safeDelivery}, and safeDeliveryTtl = ${this.options.safeDeliveryTtl}, and watcherCheckDelay = ${this.options.watcherCheckDelay}, and useGzip = ${this.options.useGzip}`);
176
174
  }
177
- verbose(message, sensitiveMessage, sensitiveOnly) {
178
- if (sensitiveOnly && !this.options.verboseExtended) {
179
- return;
180
- }
175
+ verbose(message) {
181
176
  if (this.options.verbose) {
182
- const text = `[IMQ-CORE][${this.name}]: ${message}`;
183
- const fullText = this.options.verboseExtended
184
- ? `${text}${sensitiveMessage}`
185
- : text;
186
- this.logger.info(fullText);
177
+ this.logger.info(`[IMQ-CORE][${this.name}]: ${message}`);
187
178
  }
188
179
  }
189
180
  /**
@@ -214,7 +205,7 @@ class RedisQueue extends events_1.EventEmitter {
214
205
  if (ch === fcn && typeof handler === 'function') {
215
206
  handler(JSON.parse(message));
216
207
  }
217
- this.verbose(`Received message from ${ch} channel`, `, data: ${JSON.stringify(message)}`);
208
+ this.verbose(`Received message from ${ch} channel, data: ${JSON.stringify(message)}`);
218
209
  });
219
210
  this.verbose(`Subscribed to ${channel} channel`);
220
211
  }
@@ -227,12 +218,12 @@ class RedisQueue extends events_1.EventEmitter {
227
218
  if (this.subscription) {
228
219
  this.verbose('Initialize unsubscribing...');
229
220
  if (this.subscriptionName) {
230
- await this.subscription.unsubscribe(`${this.options.prefix}:${this.subscriptionName}`);
221
+ this.subscription.unsubscribe(`${this.options.prefix}:${this.subscriptionName}`);
231
222
  this.verbose(`Unsubscribed from ${this.subscriptionName} channel`);
232
223
  }
233
224
  this.subscription.removeAllListeners();
234
225
  this.subscription.disconnect(false);
235
- await this.subscription.quit();
226
+ this.subscription.quit();
236
227
  }
237
228
  this.subscriptionName = undefined;
238
229
  this.subscription = undefined;
@@ -255,7 +246,8 @@ class RedisQueue extends events_1.EventEmitter {
255
246
  const jsonData = JSON.stringify(data);
256
247
  const name = toName || this.name;
257
248
  await this.writer.publish(`${this.options.prefix}:${name}`, jsonData);
258
- this.verbose(`Published message to ${name} channel`, `, data: ${jsonData}`);
249
+ this.verbose(`Published message to ${name} channel, data: ${jsonData}
250
+ `);
259
251
  }
260
252
  /**
261
253
  * Initializes and starts current queue routines
@@ -336,7 +328,6 @@ class RedisQueue extends events_1.EventEmitter {
336
328
  const data = { id, message, from: this.name };
337
329
  const key = `${this.options.prefix}:${toQueue}`;
338
330
  const packet = this.pack(data);
339
- this.verbose('Message send', `: ${packet}`, true);
340
331
  const cb = (error, op) => {
341
332
  // istanbul ignore next
342
333
  if (error) {
@@ -347,10 +338,10 @@ class RedisQueue extends events_1.EventEmitter {
347
338
  }
348
339
  };
349
340
  if (delay) {
350
- await this.writer.zadd(`${key}:delayed`, Date.now() + delay, packet, (e) => {
341
+ this.writer.zadd(`${key}:delayed`, Date.now() + delay, packet, (err) => {
351
342
  // istanbul ignore next
352
- if (e) {
353
- cb(e, 'ZADD');
343
+ if (err) {
344
+ cb(err, 'ZADD');
354
345
  return;
355
346
  }
356
347
  this.writer.set(`${key}:${id}:ttl`, '', 'PX', delay, 'NX', (err) => {
@@ -363,7 +354,7 @@ class RedisQueue extends events_1.EventEmitter {
363
354
  });
364
355
  }
365
356
  else {
366
- await this.writer.lpush(key, packet, (err) => {
357
+ this.writer.lpush(key, packet, (err) => {
367
358
  // istanbul ignore next
368
359
  if (err) {
369
360
  cb(err, 'LPUSH');
@@ -383,7 +374,7 @@ class RedisQueue extends events_1.EventEmitter {
383
374
  if (this.reader) {
384
375
  this.verbose('Destroying reader...');
385
376
  this.reader.removeAllListeners();
386
- await this.reader.quit();
377
+ this.reader.quit();
387
378
  this.reader.disconnect(false);
388
379
  delete this.reader;
389
380
  }
@@ -590,7 +581,7 @@ class RedisQueue extends events_1.EventEmitter {
590
581
  enableOfflineQueue: true,
591
582
  autoResendUnfulfilledCommands: true,
592
583
  });
593
- context[channel] = (0, _1.makeRedisSafe)(redis);
584
+ context[channel] = (0, _1.makeRedisSafe)(redis, options.verbose ? options.logger : undefined);
594
585
  context[channel].__imq = true;
595
586
  for (const event of [
596
587
  'wait',
@@ -724,7 +715,6 @@ class RedisQueue extends events_1.EventEmitter {
724
715
  const { id, message, from } = this.unpack(data);
725
716
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
726
717
  this.emit('message', message, id, from);
727
- this.verbose('Message received', `: ${data}`, true);
728
718
  }
729
719
  catch (err) {
730
720
  // istanbul ignore next
@@ -826,7 +816,7 @@ class RedisQueue extends events_1.EventEmitter {
826
816
  */
827
817
  async onWatchMessage(...args) {
828
818
  try {
829
- const key = ((args.pop() || '') + '').split(':');
819
+ const key = (args.pop() || '').split(':');
830
820
  if (key.pop() !== 'ttl') {
831
821
  return;
832
822
  }
package/src/redis.d.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  * <support@imqueue.com> to get commercial licensing options.
23
23
  */
24
24
  import Redis from 'ioredis';
25
+ import { ILogger } from './IMessageQueue';
25
26
  /**
26
27
  * Extends default Redis type to allow dynamic properties access on it
27
28
  *
@@ -31,6 +32,6 @@ export interface IRedisClient extends Redis {
31
32
  __ready__?: boolean;
32
33
  __imq?: boolean;
33
34
  }
34
- export declare function makeRedisSafe(redis: IRedisClient): IRedisClient;
35
+ export declare function makeRedisSafe(redis: IRedisClient, logger?: ILogger): IRedisClient;
35
36
  export { Redis };
36
37
  export default Redis;
package/src/redis.js CHANGED
@@ -29,7 +29,7 @@ exports.makeRedisSafe = makeRedisSafe;
29
29
  const ioredis_1 = require("ioredis");
30
30
  exports.Redis = ioredis_1.default;
31
31
  // istanbul ignore next
32
- function makeRedisSafe(redis) {
32
+ function makeRedisSafe(redis, logger) {
33
33
  return new Proxy(redis, {
34
34
  get(target, property, receiver) {
35
35
  const original = Reflect.get(target, property, receiver);
@@ -37,11 +37,13 @@ function makeRedisSafe(redis) {
37
37
  return async (...args) => {
38
38
  try {
39
39
  if (target.status !== 'ready') {
40
+ logger === null || logger === void 0 ? void 0 : logger.warn('Redis client is not ready yet, while ', `executing command: "${String(property)}"`);
40
41
  return null;
41
42
  }
42
43
  return await original.apply(target, args);
43
44
  }
44
45
  catch (err) {
46
+ logger === null || logger === void 0 ? void 0 : logger.error(err);
45
47
  return null;
46
48
  }
47
49
  };