I'm creating a microservice, where I need to receive messages from rabbit. I am facing the following error
ERROR [Server] There is no matching event handler defined in the remote service. Event pattern: undefined
main.ts
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();
app.module.ts
import { Module } from '@nestjs/common';
import { RabbitMQConsumerService } from './rabbitmq-consumer.service';
@Module({
imports: [],
providers: [RabbitMQConsumerService],
})
export class AppModule {}
rabbitmq-consumer.service.ts
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('Mensagem recebida:', data);
}
}
when I send the message I expected to receive it in the nestjs service, but I get the error
ERROR [Server] There is no matching event handler defined in the remote service. Event pattern: undefined