gemcap-be-common 1.4.249 → 1.4.250

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.
@@ -19,7 +19,7 @@ export declare const EVENT_KEYS: {
19
19
  * ========= CRM DOMAIN EVENTS =========
20
20
  */
21
21
  readonly crm: {
22
- readonly PROSPECT_EMAILS_REQUESTED: "crm.prospect.emails.requested";
22
+ readonly PROSPECT_EMAILS_SEND_REQUESTED: "crm.prospect.emails.requested";
23
23
  };
24
24
  /**
25
25
  * ========= FINANCE DOMAIN EVENTS =========
@@ -22,7 +22,7 @@ exports.EVENT_KEYS = {
22
22
  * ========= CRM DOMAIN EVENTS =========
23
23
  */
24
24
  crm: {
25
- PROSPECT_EMAILS_REQUESTED: 'crm.prospect.emails.requested',
25
+ PROSPECT_EMAILS_SEND_REQUESTED: 'crm.prospect.emails.requested',
26
26
  },
27
27
  /**
28
28
  * ========= FINANCE DOMAIN EVENTS =========
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.249",
3
+ "version": "1.4.250",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,6 @@
1
+ export declare class RabbitService {
2
+ private connection;
3
+ private channel;
4
+ init(): Promise<void>;
5
+ publish(exchange: string, routingKey: string, payload: unknown): Promise<void>;
6
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.RabbitService = void 0;
27
+ const amqp = __importStar(require("amqplib"));
28
+ const { NODE_ENV } = process.env;
29
+ class RabbitService {
30
+ connection = null;
31
+ channel = null;
32
+ async init() {
33
+ const rabbitMQApi = NODE_ENV === 'development' ? 'localhost' : 'rabbitmq';
34
+ this.connection = await amqp.connect(`amqp://${rabbitMQApi}`, { heartbeat: 10 });
35
+ this.connection.on('error', (err) => {
36
+ console.error('RabbitMQ connection error', err);
37
+ });
38
+ this.connection.on('close', () => {
39
+ console.warn('RabbitMQ connection closed. Reconnecting...');
40
+ setTimeout(() => this.init(), 5000);
41
+ });
42
+ this.channel = await this.connection.createChannel();
43
+ console.log('RabbitMQ connected');
44
+ }
45
+ async publish(exchange, routingKey, payload) {
46
+ if (!this.channel) {
47
+ throw new Error('RabbitMQ channel is not initialized');
48
+ }
49
+ this.channel.publish(exchange, routingKey, Buffer.from(JSON.stringify(payload)), { persistent: true });
50
+ }
51
+ }
52
+ exports.RabbitService = RabbitService;
@@ -0,0 +1,40 @@
1
+ import * as amqp from 'amqplib';
2
+
3
+ const { NODE_ENV } = process.env;
4
+
5
+ export class RabbitService {
6
+ private connection: amqp.ChannelModel | null = null;
7
+ private channel: amqp.Channel | null = null;
8
+
9
+ async init() {
10
+ const rabbitMQApi = NODE_ENV === 'development' ? 'localhost' : 'rabbitmq';
11
+
12
+ this.connection = await amqp.connect(`amqp://${rabbitMQApi}`, { heartbeat: 10 });
13
+
14
+ this.connection.on('error', (err) => {
15
+ console.error('RabbitMQ connection error', err);
16
+ });
17
+
18
+ this.connection.on('close', () => {
19
+ console.warn('RabbitMQ connection closed. Reconnecting...');
20
+ setTimeout(() => this.init(), 5000);
21
+ });
22
+
23
+ this.channel = await this.connection.createChannel();
24
+
25
+ console.log('RabbitMQ connected');
26
+ }
27
+
28
+ async publish(exchange: string, routingKey: string, payload: unknown) {
29
+ if (!this.channel) {
30
+ throw new Error('RabbitMQ channel is not initialized');
31
+ }
32
+
33
+ this.channel.publish(
34
+ exchange,
35
+ routingKey,
36
+ Buffer.from(JSON.stringify(payload)),
37
+ { persistent: true },
38
+ );
39
+ }
40
+ }