@go-mailer/vertebra 3.2.51 → 3.3.0

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.
@@ -1,3 +1,4 @@
1
+ const crypto = require('crypto');
1
2
  const rabbit = require("amqplib");
2
3
  const EventEmitter = require("events");
3
4
 
@@ -83,10 +84,13 @@ class Broker {
83
84
 
84
85
  async publish(queue_name, message = {}) {
85
86
  try {
87
+ const payload = typeof message === 'string' ? JSON.parse(message) : message;
88
+ payload.uuid = crypto.randomUUID();
89
+
86
90
  this.channel.assertQueue(queue_name, {
87
91
  durable: true,
88
92
  });
89
- this.channel.sendToQueue(queue_name, Buffer.from(message), {
93
+ this.channel.sendToQueue(queue_name, Buffer.from(JSON.stringify(payload)), {
90
94
  persistent: true,
91
95
  });
92
96
  } catch (e) {
@@ -98,10 +102,11 @@ class Broker {
98
102
  this.connector = connector;
99
103
  }
100
104
 
101
- async subscribe(queue_name, handler = console.log) {
105
+ async subscribe(queue_name, handler = console.log, prefetch = 1) {
102
106
  try {
103
107
  if (!this.channel) return;
104
108
  this.channel.assertQueue(queue_name, {});
109
+ this.channel.prefetch(prefetch);
105
110
  this.channel.consume(queue_name, handler);
106
111
  } catch (e) {
107
112
  console.log(`RabbitMQ subscribe(): ${e.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-mailer/vertebra",
3
- "version": "3.2.51",
3
+ "version": "3.3.0",
4
4
  "description": "Go-Mailer vertebra",
5
5
  "main": "index.js",
6
6
  "scripts": {