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:
parent
fb0bb36bdd
commit
e44203c485
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@erp/plugin-sdk",
|
"name": "@erp/plugin-sdk",
|
||||||
"version": "1.11.2",
|
"version": "1.11.3",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|
|
||||||
|
|
@ -331,9 +331,19 @@ export class CoreService {
|
||||||
source: this.serviceName,
|
source: this.serviceName,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
};
|
};
|
||||||
this.client.emit(pattern, event).subscribe({
|
try {
|
||||||
error: (err) => this.logger.error(`Failed to emit event ${pattern}:`, err),
|
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> {
|
async auditLog(action: string, resource: string, details?: any): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue