@mulingai-npm/message-broker 2.4.0 → 2.6.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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RabbitMQClient } from '../rabbitmq-client';
|
|
2
|
+
import { IListenerActivityEvent } from '@mulingai-npm/web-sockets';
|
|
3
|
+
export declare class MulingstreamListenerActivity {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: RabbitMQClient);
|
|
6
|
+
initialize(): Promise<void>;
|
|
7
|
+
publish(data: IListenerActivityEvent): Promise<void>;
|
|
8
|
+
subscribe(queueName: string, onMessage: (data: IListenerActivityEvent) => Promise<void> | void): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MulingstreamListenerActivity = void 0;
|
|
4
|
+
const EXCHANGE_NAME = 'mulingstream-listener-activity';
|
|
5
|
+
const EXCHANGE_TYPE = 'fanout';
|
|
6
|
+
class MulingstreamListenerActivity {
|
|
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(`MulingstreamListenerActivity 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);
|
|
21
|
+
console.log(`[ListenerActivity] Published ${data.type} for room ${data.roomId}, total: ${data.stats.totalListeners}`);
|
|
22
|
+
}
|
|
23
|
+
async subscribe(queueName, onMessage) {
|
|
24
|
+
const channel = this.client.getChannelOrThrow();
|
|
25
|
+
await channel.assertQueue(queueName, { durable: true });
|
|
26
|
+
await channel.bindQueue(queueName, EXCHANGE_NAME, '');
|
|
27
|
+
await channel.consume(queueName, async (msg) => {
|
|
28
|
+
if (!msg) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const data = JSON.parse(msg.content.toString());
|
|
33
|
+
await onMessage(data);
|
|
34
|
+
channel.ack(msg);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error(`Error in MulingstreamListenerActivity subscription queue ${queueName}:`, error);
|
|
38
|
+
channel.nack(msg);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.MulingstreamListenerActivity = MulingstreamListenerActivity;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mulingai-npm/message-broker",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
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.37.0",
|
|
21
21
|
"amqplib": "^0.10.5"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|