I'm currently developing a microservice that is responsible for receiving messages from RabbitMQ. However, I am encountering an error message as follows:
ERROR [Server] There is no matching event handler defined in the remote service. Event pattern: undefined
The code snippet below shows the main.ts file:
import { NestFactory } from '@nestjs/core';
import { Transport, MicroserviceOptions } from '@nestjs/microservices';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
AppModule,
{
transport: Transport.RMQ,
options: {
urls: ['amqp://localhost:5672'],
queue: 'my-queue',
queueOptions: { durable: false },
},
},
);
app.listen();
}
bootstrap();
Here is the content of the app.module.ts file:
import { Module } from '@nestjs/common';
import { RabbitMQConsumerService } from './rabbitmq-consumer.service';
@Module({
imports: [],
providers: [RabbitMQConsumerService],
})
export class AppModule {}
Lastly, let's take a look at the rabbitmq-consumer.service.ts file:
import { Injectable } from '@nestjs/common';
import {
Ctx,
MessagePattern,
Payload,
RmqContext,
} from '@nestjs/microservices';
@Injectable()
export class RabbitMQConsumerService {
@MessagePattern('my-queue')
async processMessage(@Payload() data: any, @Ctx() context: RmqContext) {
console.log('Received message:', data);
}
}
Despite expecting to successfully receive messages in the NestJS service when sending them, an error occurs with the following message:
ERROR [Server] There is no matching event handler defined in the remote service. Event pattern: undefined