@seidor-cloud-produtos/orbit-backend-lib 1.101.32 → 1.101.34

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.
@@ -12,7 +12,9 @@ export default class AmqpQueue implements QueueConnection {
12
12
  private messagesInMemory;
13
13
  private controller;
14
14
  private channels;
15
- constructor(uri?: string);
15
+ protected socketOptions?: any;
16
+ constructor(uri?: string, socketOptions?: any);
17
+ private setSocketOptions;
16
18
  connect(vHost: string): Promise<AmqpQueue>;
17
19
  close(): Promise<void>;
18
20
  get(queueName: string, options?: amqp.Options.Get | undefined): Promise<AmqpQueueGetResult | null>;
@@ -10,12 +10,23 @@ class AmqpQueue {
10
10
  messagesInMemory = [];
11
11
  controller;
12
12
  channels = new Map();
13
- constructor(uri = process.env.BROKER_AMQP) {
13
+ socketOptions;
14
+ constructor(uri = process.env.BROKER_AMQP, socketOptions) {
14
15
  this.uri = uri;
16
+ this.setSocketOptions(socketOptions);
17
+ }
18
+ setSocketOptions(socketOptions) {
19
+ if (!socketOptions) {
20
+ this.socketOptions = {
21
+ frameMax: 131072,
22
+ };
23
+ }
24
+ this.socketOptions = socketOptions;
25
+ return this;
15
26
  }
16
27
  async connect(vHost) {
17
28
  const urlConnection = `${this.uri}/${vHost}`;
18
- this.connection = await amqplib_1.default.connect(urlConnection);
29
+ this.connection = await amqplib_1.default.connect(urlConnection, this.socketOptions);
19
30
  this.vHost = vHost;
20
31
  await this.treatReconnection(vHost);
21
32
  if (process.env.NODE_ENV !== 'test') {
@@ -17,7 +17,6 @@ class RabbitMQScaledJobRunner {
17
17
  this.options = options;
18
18
  }
19
19
  async handleError(error, getResult) {
20
- logger_1.default.error(`[RabbitMQScaledJobRunner] Erro: ${error.message}`);
21
20
  if (!getResult) {
22
21
  return;
23
22
  }
@@ -43,32 +42,46 @@ class RabbitMQScaledJobRunner {
43
42
  }
44
43
  async run() {
45
44
  let getResult = null;
45
+ let consumedMessages = 0;
46
+ const messagesToGet = this.options.numberOfMessagesToGet ?? 1;
46
47
  try {
47
48
  await this.amqpQueue.connect(this.vHost);
48
- getResult = await this.amqpQueue.get(this.queueName, {
49
- noAck: !this.options.manualAck,
50
- });
51
- if (!getResult) {
52
- logger_1.default
53
- .debug()
54
- ?.warning('[RabbitMQScaledJobRunner] Nenhuma mensagem disponível.');
55
- return;
56
- }
57
- const { channel, rawMessage } = getResult;
58
- const msg = this.options.parse(rawMessage);
59
- logger_1.default
60
- .debug()
61
- ?.info(`[RabbitMQScaledJobRunner] Mensagem recebida ${JSON.stringify(msg, null, 2)}`);
62
- await Promise.race([this.handler.handle(msg), this.rejectTimeout()]);
63
- if (this.options.manualAck) {
64
- await this.amqpQueue.ack(channel, rawMessage);
49
+ while (consumedMessages < messagesToGet) {
50
+ try {
51
+ getResult = await this.amqpQueue.get(this.queueName, {
52
+ noAck: !this.options.manualAck,
53
+ });
54
+ if (!getResult) {
55
+ logger_1.default.warning('[RabbitMQScaledJobRunner] Nenhuma mensagem disponível.');
56
+ return;
57
+ }
58
+ const { channel, rawMessage } = getResult;
59
+ const msg = this.options.parse(rawMessage);
60
+ logger_1.default
61
+ .debug()
62
+ ?.info(`[RabbitMQScaledJobRunner] Mensagem recebida ${JSON.stringify(msg, null, 2)}`);
63
+ await Promise.race([this.handler.handle(msg), this.rejectTimeout()]);
64
+ if (this.options.manualAck) {
65
+ await this.amqpQueue.ack(channel, rawMessage);
66
+ }
67
+ }
68
+ catch (error) {
69
+ logger_1.default.error(`[RabbitMQScaledJobRunner] Erro: ${error.message}`);
70
+ if (getResult && this.options.manualAck) {
71
+ await this.handleError(error, getResult);
72
+ }
73
+ }
74
+ finally {
75
+ if (getResult) {
76
+ getResult = null;
77
+ consumedMessages += 1;
78
+ logger_1.default.debug()?.info(`[RabbitMQScaledJobRunner] Mensagens consumidas: ${consumedMessages}`);
79
+ }
80
+ }
65
81
  }
66
82
  }
67
- catch (err) {
68
- logger_1.default.error(`[RabbitMQScaledJobRunner] Erro: ${err.message}`);
69
- if (getResult && this.options.manualAck) {
70
- await this.handleError(err, getResult);
71
- }
83
+ catch (error) {
84
+ logger_1.default.error(`[RabbitMQScaledJobRunner] Erro: ${JSON.stringify(error)}`);
72
85
  }
73
86
  finally {
74
87
  try {
@@ -4,4 +4,5 @@ export type RabbitMQScaledJobOptions = {
4
4
  manualAck: boolean;
5
5
  errorStrategy: ErrorStrategy;
6
6
  timeoutMs: number;
7
+ numberOfMessagesToGet?: number;
7
8
  };
@@ -16,8 +16,11 @@ class AuthValidator {
16
16
  isAuthorized() {
17
17
  const notReceiptAuthorizations = this.requestData.authorizations === undefined ||
18
18
  this.requestData.authorizations === null;
19
+ if (notReceiptAuthorizations) {
20
+ return true;
21
+ }
19
22
  const hasAuthorizations = auth_matcher_1.default.isMatch(this.query, this.requestData.authorizations);
20
- return notReceiptAuthorizations || hasAuthorizations;
23
+ return hasAuthorizations;
21
24
  }
22
25
  async setup() {
23
26
  this.requestData = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seidor-cloud-produtos/orbit-backend-lib",
3
- "version": "1.101.32",
3
+ "version": "1.101.34",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",