fix: emit() publishes to exchange instead of sendToQueue

NestJS v10 RMQ client uses sendToQueue which sends to a specific
queue (core_queue), bypassing the exchange. Messages were never
delivered to other plugins' queues bound to the exchange.

Changed emit() to use amqplib to publish directly to system_events
exchange with {pattern, data} format that NestJS RMQ server expects.
This commit is contained in:
Kyryll O. 2026-06-19 16:17:47 +03:00
parent fb0bb36bdd
commit e44203c485
2 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@erp/plugin-sdk",
"version": "1.11.2",
"version": "1.11.3",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {

View File

@ -331,9 +331,19 @@ export class CoreService {
source: this.serviceName,
timestamp: Date.now(),
};
this.client.emit(pattern, event).subscribe({
error: (err) => this.logger.error(`Failed to emit event ${pattern}:`, err),
});
try {
const conn = await amqp.connect(this.getRMQUrl());
const ch = await conn.createChannel();
await ch.assertExchange('system_events', 'topic', { durable: true });
ch.publish('system_events', pattern, Buffer.from(JSON.stringify({
pattern,
data: event,
})));
await ch.close();
await conn.close();
} catch (err: any) {
this.logger.error(`Failed to emit event ${pattern}: ${err.message}`);
}
}
async auditLog(action: string, resource: string, details?: any): Promise<void> {