@autofleet/rabbit 2.1.10 → 2.1.12-beta1

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/.env ADDED
File without changes
package/dist/index.d.ts CHANGED
@@ -55,7 +55,7 @@ declare class RabbitMq implements IAfRabbitMq {
55
55
  assertQueue(queue: string, options?: Options.AssertQueue): Promise<void>;
56
56
  consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
57
57
  consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
58
- publish(exchange: string, content: any, customHeaders?: any): Promise<unknown>;
58
+ publish(exchange: string, content: any, customHeaders?: any): Promise<void>;
59
59
  sendToQueue(queue: string, content: any, options?: any, customHeaders?: any): Promise<boolean>;
60
60
  isConnected(): Promise<boolean>;
61
61
  }
package/dist/index.js CHANGED
@@ -1,23 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -31,9 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
13
  };
33
14
  Object.defineProperty(exports, "__esModule", { value: true });
34
- /* eslint-disable @typescript-eslint/ban-ts-comment,@typescript-eslint/ban-types,@typescript-eslint/no-unused-vars,consistent-return,no-async-promise-executor,no-param-reassign,no-empty */
35
- // eslint-disable-next-line max-classes-per-file
36
- const bluebird = __importStar(require("bluebird"));
37
15
  const moment_1 = __importDefault(require("moment"));
38
16
  const amqp_connection_manager_1 = require("amqp-connection-manager");
39
17
  const events_1 = require("events");
@@ -122,13 +100,13 @@ class RabbitMq {
122
100
  getConnection() {
123
101
  return __awaiter(this, void 0, void 0, function* () {
124
102
  return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
103
+ if (this.connection !== null) {
104
+ return resolve(this.connection);
105
+ }
125
106
  if (this.creatingConnection) {
126
107
  this.em.once(connectionCreatedConst, resolve);
127
108
  return;
128
109
  }
129
- if (this.connection !== null) {
130
- return resolve(this.connection);
131
- }
132
110
  this.creatingConnection = true;
133
111
  const username = process.env.RABBITMQ_USERNAME || 'guest';
134
112
  const password = process.env.RABBITMQ_PASSWORD || 'guest';
@@ -233,7 +211,7 @@ class RabbitMq {
233
211
  yield callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
234
212
  }
235
213
  catch (e) {
236
- yield this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
214
+ yield this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl })(msg);
237
215
  }
238
216
  })),
239
217
  ]);
@@ -273,15 +251,7 @@ class RabbitMq {
273
251
  RabbitMq.validateName('exchange', exchange);
274
252
  const channel = yield this.assertChannel();
275
253
  yield this.assertExchange(exchange);
276
- return new bluebird.Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
277
- try {
278
- yield channel.publish(exchange, '', Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
279
- return resolve();
280
- }
281
- catch (e) {
282
- reject(e);
283
- }
284
- })).timeout(this.PUBLISH_TIMEOUT, `${this.PUBLISH_ERROR_MSG}${exchange}`);
254
+ yield channel.publish(exchange, '', Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
285
255
  });
286
256
  }
287
257
  sendToQueue(queue, content, options, customHeaders) {
package/dump.rdb ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "2.1.10",
3
+ "version": "2.1.12-beta1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -158,13 +158,13 @@ class RabbitMq implements IAfRabbitMq {
158
158
 
159
159
  async getConnection() {
160
160
  return new Promise<AmqpConnectionManager>(async (resolve) => {
161
+ if (this.connection !== null) {
162
+ return resolve(this.connection);
163
+ }
161
164
  if (this.creatingConnection) {
162
165
  this.em.once(connectionCreatedConst, resolve);
163
166
  return;
164
167
  }
165
- if (this.connection !== null) {
166
- return resolve(this.connection);
167
- }
168
168
  this.creatingConnection = true;
169
169
  const username: string = process.env.RABBITMQ_USERNAME || 'guest';
170
170
  const password: string = process.env.RABBITMQ_PASSWORD || 'guest';
@@ -266,7 +266,7 @@ class RabbitMq implements IAfRabbitMq {
266
266
  this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
267
267
  );
268
268
  } catch (e) {
269
- await this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
269
+ await this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl })(msg);
270
270
  }
271
271
  },
272
272
  ),
@@ -309,16 +309,9 @@ class RabbitMq implements IAfRabbitMq {
309
309
  RabbitMq.validateName('exchange', exchange);
310
310
  const channel: ChannelWrapper = await this.assertChannel();
311
311
  await this.assertExchange(exchange);
312
- return new bluebird.Promise(async (resolve, reject) => {
313
- try {
314
- await channel.publish(exchange, '',
315
- Buffer.from(JSON.stringify(content)),
316
- RabbitMq.getPublishOptions(customHeaders));
317
- return resolve();
318
- } catch (e) {
319
- reject(e);
320
- }
321
- }).timeout(this.PUBLISH_TIMEOUT, `${this.PUBLISH_ERROR_MSG}${exchange}`);
312
+ await channel.publish(exchange, '',
313
+ Buffer.from(JSON.stringify(content)),
314
+ RabbitMq.getPublishOptions(customHeaders));
322
315
  }
323
316
 
324
317
  async sendToQueue(queue: string, content: any, options?: any, customHeaders?: any) {