sim-node-lib 0.5.1 → 0.5.3

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.
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
3
3
  import { PubSubApiEnum } from '../Enums/PubSubApiEnum';
4
4
  import { PubSubModel } from '../Models/PubSubModel';
5
5
  export declare class GooglePubSubSubscription {
6
- constructor(subscriptionName: string);
6
+ constructor(subscriptionName: string, maxMessages?: number);
7
7
  private _subscription;
8
8
  listenMessages(eventEmitter: EventEmitter): Promise<void>;
9
9
  listenMessagesV2(fn: (obj: PubSubModel) => Promise<boolean>, api: PubSubApiEnum, logger?: any): Promise<void>;
@@ -13,8 +13,14 @@ exports.GooglePubSubSubscription = void 0;
13
13
  const pubsub_1 = require("@google-cloud/pubsub");
14
14
  const PubSubModel_1 = require("../Models/PubSubModel");
15
15
  class GooglePubSubSubscription {
16
- constructor(subscriptionName) {
17
- this._subscription = new pubsub_1.PubSub().subscription(subscriptionName);
16
+ constructor(subscriptionName, maxMessages = 100) {
17
+ const options = {
18
+ flowControl: {
19
+ maxMessages: maxMessages,
20
+ allowExcessMessages: false,
21
+ },
22
+ };
23
+ this._subscription = new pubsub_1.PubSub().subscription(subscriptionName, options);
18
24
  }
19
25
  listenMessages(eventEmitter) {
20
26
  return __awaiter(this, void 0, void 0, function* () {
@@ -32,28 +38,36 @@ class GooglePubSubSubscription {
32
38
  listenMessagesV2(fn, api, logger) {
33
39
  return __awaiter(this, void 0, void 0, function* () {
34
40
  this._subscription.on('message', (message) => __awaiter(this, void 0, void 0, function* () {
35
- const data = JSON.parse(message.data.toString());
36
- const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table, data.api);
37
- if (api !== pubSubModel.api) {
38
- yield fn(pubSubModel).then(() => {
39
- message.ack();
40
- }).catch((err) => {
41
- if (err.routine === '_bt_check_unique') {
41
+ try {
42
+ const data = JSON.parse(message.data.toString());
43
+ const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table, data.api);
44
+ if (api !== pubSubModel.api) {
45
+ yield fn(pubSubModel)
46
+ .then(() => {
42
47
  message.ack();
43
- }
44
- else {
45
- if (logger) {
46
- logger.warn('___________________________________________________');
47
- logger.warn('Erro no PubSub (handle):' + JSON.stringify(data[0]));
48
- logger.warn('Routine:' + err.routine);
49
- logger.warn('Message:' + err.message);
50
- logger.warn('Error:' + err);
48
+ })
49
+ .catch((err) => {
50
+ if (err.routine === '_bt_check_unique') {
51
+ message.ack();
51
52
  }
52
- }
53
- });
53
+ else {
54
+ if (logger) {
55
+ logger.warn('___________________________________________________');
56
+ logger.warn('Erro no PubSub (handle):' + JSON.stringify(data[0]));
57
+ logger.warn('Routine:' + err.routine);
58
+ logger.warn('Message:' + err.message);
59
+ logger.warn('Error:' + err);
60
+ }
61
+ }
62
+ });
63
+ }
64
+ else {
65
+ message.ack();
66
+ }
54
67
  }
55
- else {
56
- message.ack();
68
+ catch (error) {
69
+ console.error('Erro crítico ao processar mensagem do PubSub:', error);
70
+ message.nack();
57
71
  }
58
72
  }));
59
73
  });
@@ -20,6 +20,7 @@ export declare enum PubSubTableEnum {
20
20
  cluster = "cluster",
21
21
  clusterCliente = "cluster_cliente",
22
22
  clienteVeiculo = "cliente_veiculo",
23
+ cpfImport = "cpf_import",
23
24
  concorrente = "concorrente",
24
25
  configuracao = "configuracao",
25
26
  depositoAntecipado = "deposito_antecipado",
@@ -24,6 +24,7 @@ var PubSubTableEnum;
24
24
  PubSubTableEnum["cluster"] = "cluster";
25
25
  PubSubTableEnum["clusterCliente"] = "cluster_cliente";
26
26
  PubSubTableEnum["clienteVeiculo"] = "cliente_veiculo";
27
+ PubSubTableEnum["cpfImport"] = "cpf_import";
27
28
  PubSubTableEnum["concorrente"] = "concorrente";
28
29
  PubSubTableEnum["configuracao"] = "configuracao";
29
30
  PubSubTableEnum["depositoAntecipado"] = "deposito_antecipado";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",