fix: sendNotification publishes directly to exchange instead of NestJS RMQ client sendToQueue
This commit is contained in:
parent
67f58d6f74
commit
8209f4ac82
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@erp/plugin-sdk",
|
||||
"version": "1.11.0",
|
||||
"version": "1.11.1",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"bin": {
|
||||
|
|
|
|||
|
|
@ -406,14 +406,30 @@ export class CoreService {
|
|||
}
|
||||
|
||||
async sendNotification(payload: { userId: number | null; title: string; message: string; icon?: string; image?: string; details?: any }): Promise<void> {
|
||||
await this.emit('system.notification.send', {
|
||||
try {
|
||||
const conn = await amqp.connect(this.getRMQUrl());
|
||||
const ch = await conn.createChannel();
|
||||
await ch.assertExchange('system_events', 'topic', { durable: true });
|
||||
const eventData = {
|
||||
eventId: uuidv4(),
|
||||
pattern: 'system.notification.send',
|
||||
payload: {
|
||||
userId: payload.userId,
|
||||
title: payload.title,
|
||||
message: payload.message,
|
||||
icon: payload.icon,
|
||||
image: payload.image,
|
||||
details: payload.details,
|
||||
});
|
||||
},
|
||||
source: this.serviceName,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
ch.publish('system_events', 'system.notification.send', Buffer.from(JSON.stringify(eventData)));
|
||||
await ch.close();
|
||||
await conn.close();
|
||||
} catch (err: any) {
|
||||
this.logger.error(`[sendNotification] Failed: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
getDbName(): string {
|
||||
|
|
|
|||
Loading…
Reference in New Issue