Hello friends, I've encountered a problem that I've been trying to fix for days, but no method works. PLS HELP ME
this is producer code:
@Injectable()
export class ReportService {
private readonly client: ClientProxy;
@InjectModel('Invoice') private invoiceModel: Model<Invoice>
constructor() {
this.client = ClientProxyFactory.create({
transport: Transport.RMQ,
options: {
urls: ['.......'],
queue: 'daily_sales_report',
queueOptions: { durable: false },
},
});
}
@Cron('*/10 * * * * *')
async generateDailyReport() {
try {
const report = {text_val:"hellllo"}
await firstValueFrom(this.client.emit('sale_report', report));
return report;
} catch (error) {
console.error('Error generating daily report:', error);
throw error;
}
}
}
consumer main.ts file :
async function bootstrap() {
try {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
AppModule,
{
transport: Transport.RMQ,
options: {
urls: ['...............'],
queue: 'daily_sales_report',
queueOptions: { durable: false },
},
},
);
await app.listen();
console.log('Microservice is listening...');
} catch (error) {
console.error('Error starting microservice:', error);
process.exit(1);
}
}
bootstrap();
and this service file :
@Injectable()
export class EmailService {
@EventPattern('sale_report')
async getNotifications(@Payload() report: any) {
console.log(report)
}
The error i get in the consumer console:
PS C:\nest js\sales-report-system\email-sender> npm run start
> email-sender@0.0.1 start
> nest start
[Nest] 3536 - 04/21/2025, 10:50:44 PM ERROR [Server] There is no matching event handler defined in the remote service. Event pattern: sale_report
PLEASE HELP ME 😭