@seidor-cloud-produtos/orbit-backend-lib 1.101.49 → 1.101.50

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.
@@ -4,6 +4,12 @@ import QueueConnection from '../../../application/queue/queue-connection';
4
4
  import DomainEvent from '../../../domain/events/domain-event';
5
5
  import QueueController from '../queue-controller';
6
6
  import { AmqpQueueGetResult } from './types';
7
+ interface SocketOptions {
8
+ retry?: {
9
+ maxCount: number;
10
+ intervalMs: number;
11
+ };
12
+ }
7
13
  export default class AmqpQueue implements QueueConnection {
8
14
  private uri;
9
15
  private static instance;
@@ -12,10 +18,10 @@ export default class AmqpQueue implements QueueConnection {
12
18
  private messagesInMemory;
13
19
  private controller;
14
20
  private channels;
15
- protected socketOptions?: any;
16
- constructor(uri?: string, socketOptions?: any);
21
+ protected socketOptions?: SocketOptions;
22
+ constructor(uri?: string, socketOptions?: SocketOptions);
17
23
  private setSocketOptions;
18
- connect(vHost: string): Promise<AmqpQueue>;
24
+ connect(vHost: string, retryCount?: number): Promise<AmqpQueue>;
19
25
  close(): Promise<void>;
20
26
  get(queueName: string, options?: amqp.Options.Get | undefined): Promise<AmqpQueueGetResult | null>;
21
27
  ack(channel: amqp.Channel, msg: any): Promise<void>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const amqplib_1 = tslib_1.__importDefault(require("amqplib"));
5
+ const timeout_1 = require("../../../shared/timeout");
5
6
  class AmqpQueue {
6
7
  uri;
7
8
  static instance;
@@ -19,16 +20,26 @@ class AmqpQueue {
19
20
  this.socketOptions = socketOptions;
20
21
  return this;
21
22
  }
22
- async connect(vHost) {
23
- const urlConnection = `${this.uri}/${vHost}`;
24
- this.connection = await amqplib_1.default.connect(urlConnection, this.socketOptions);
25
- this.vHost = vHost;
26
- await this.treatReconnection(vHost);
27
- if (process.env.NODE_ENV !== 'test') {
28
- console.log(`⚙️ PROCESS ${this.vHost} PID: `, process.pid);
29
- console.log(`🐝 Queue connected on vHost: ${this.vHost}`);
23
+ async connect(vHost, retryCount = 0) {
24
+ try {
25
+ const urlConnection = `${this.uri}/${vHost}`;
26
+ this.connection = await amqplib_1.default.connect(urlConnection, this.socketOptions);
27
+ this.vHost = vHost;
28
+ await this.treatReconnection(vHost);
29
+ if (process.env.NODE_ENV !== 'test') {
30
+ console.log(`⚙️ PROCESS ${this.vHost} PID: `, process.pid);
31
+ console.log(`🐝 Queue connected on vHost: ${this.vHost}`);
32
+ }
33
+ return this;
34
+ }
35
+ catch (e) {
36
+ if (!this.socketOptions?.retry?.maxCount ||
37
+ retryCount >= this.socketOptions?.retry?.maxCount) {
38
+ throw e;
39
+ }
40
+ await (0, timeout_1.sleep)(this.socketOptions.retry.intervalMs);
41
+ return await this.connect(vHost, retryCount++);
30
42
  }
31
- return this;
32
43
  }
33
44
  async close() {
34
45
  await this.connection.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seidor-cloud-produtos/orbit-backend-lib",
3
- "version": "1.101.49",
3
+ "version": "1.101.50",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",