@mulingai-npm/message-broker 1.1.4 → 1.1.7
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.
package/dist/rabbitmq-client.js
CHANGED
|
@@ -14,7 +14,7 @@ class RabbitMQClient {
|
|
|
14
14
|
}
|
|
15
15
|
this.connection = await (0, amqplib_1.connect)(this.url);
|
|
16
16
|
this.channel = await this.connection.createChannel();
|
|
17
|
-
console.log('RabbitMQ connected and channel created.');
|
|
17
|
+
console.log('🐇 RabbitMQ connected and channel created.');
|
|
18
18
|
// Cleanup on close
|
|
19
19
|
this.connection.on('close', () => {
|
|
20
20
|
console.warn('RabbitMQ connection closed.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mulingai-npm/message-broker",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"prepublishOnly": "npm run build"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@mulingai-npm/web-sockets": "^1.
|
|
20
|
+
"@mulingai-npm/web-sockets": "^1.19.0",
|
|
21
21
|
"amqplib": "^0.10.5"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { RabbitMQClient } from '../rabbitmq-client';
|
|
2
|
-
import { IMulingstreamListenerFeedData } from '@mulingai-npm/web-sockets';
|
|
3
|
-
export declare class MulingstreamListenerFeed {
|
|
4
|
-
private client;
|
|
5
|
-
constructor(client: RabbitMQClient);
|
|
6
|
-
initialize(): Promise<void>;
|
|
7
|
-
publish(data: IMulingstreamListenerFeedData): Promise<void>;
|
|
8
|
-
subscribe(queueName: string, onMessage: (data: IMulingstreamListenerFeedData) => Promise<void> | void): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MulingstreamListenerFeed = void 0;
|
|
4
|
-
const EXCHANGE_NAME = 'mulingstream-listener-feed';
|
|
5
|
-
const EXCHANGE_TYPE = 'fanout';
|
|
6
|
-
class MulingstreamListenerFeed {
|
|
7
|
-
constructor(client) {
|
|
8
|
-
this.client = client;
|
|
9
|
-
}
|
|
10
|
-
async initialize() {
|
|
11
|
-
const channel = this.client.getChannelOrThrow();
|
|
12
|
-
await channel.assertExchange(EXCHANGE_NAME, EXCHANGE_TYPE, {
|
|
13
|
-
durable: false
|
|
14
|
-
});
|
|
15
|
-
console.log(`MulingstreamListenerFeed exchange '${EXCHANGE_NAME}' asserted.`);
|
|
16
|
-
}
|
|
17
|
-
async publish(data) {
|
|
18
|
-
const channel = this.client.getChannelOrThrow();
|
|
19
|
-
const payload = Buffer.from(JSON.stringify(data));
|
|
20
|
-
channel.publish(EXCHANGE_NAME, '', payload); // With a fanout exchange, the routingKey is usually '' (ignored).
|
|
21
|
-
}
|
|
22
|
-
async subscribe(queueName, onMessage) {
|
|
23
|
-
const channel = this.client.getChannelOrThrow();
|
|
24
|
-
await channel.assertQueue(queueName, { durable: true });
|
|
25
|
-
await channel.bindQueue(queueName, EXCHANGE_NAME, '');
|
|
26
|
-
await channel.consume(queueName, async (msg) => {
|
|
27
|
-
if (!msg) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const data = JSON.parse(msg.content.toString());
|
|
32
|
-
await onMessage(data);
|
|
33
|
-
channel.ack(msg);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.error(`Error in MulingstreamListenerFeed subscription queue ${queueName}:`, error);
|
|
37
|
-
channel.nack(msg);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.MulingstreamListenerFeed = MulingstreamListenerFeed;
|