@mulingai-npm/message-broker 2.11.2 → 2.11.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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RabbitMQClient } from '../rabbitmq-client';
|
|
2
|
+
import { IMulingstreamRoomLanguagesUpdate } from '@mulingai-npm/web-sockets';
|
|
3
|
+
export declare class MulingstreamRoomLanguages {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: RabbitMQClient);
|
|
6
|
+
initialize(): Promise<void>;
|
|
7
|
+
publish(data: IMulingstreamRoomLanguagesUpdate): Promise<void>;
|
|
8
|
+
subscribe(queueName: string, onMessage: (data: IMulingstreamRoomLanguagesUpdate) => Promise<void> | void): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MulingstreamRoomLanguages = void 0;
|
|
4
|
+
const EXCHANGE_NAME = 'mulingstream-room-languages';
|
|
5
|
+
const EXCHANGE_TYPE = 'fanout';
|
|
6
|
+
class MulingstreamRoomLanguages {
|
|
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(`MulingstreamRoomLanguages 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
|
+
}
|
|
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 MulingstreamRoomLanguages subscription queue ${queueName}:`, error);
|
|
37
|
+
channel.nack(msg);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.MulingstreamRoomLanguages = MulingstreamRoomLanguages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mulingai-npm/message-broker",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.3",
|
|
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.49.
|
|
20
|
+
"@mulingai-npm/web-sockets": "^1.49.4",
|
|
21
21
|
"amqplib": "^0.10.5"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|