nest
nest copied to clipboard
RabbitMQ Bug Microservices
Is there an existing issue for this?
- [X] I have searched the existing issues
Current behavior
all this request was sent without restart server or rabbitmq server
- first request consumer don't receive message: stackoveflow
- second request come to consumer - ok
- future request provide error: There is no matching message handler defined in the remote service - stackoverflow
Minimum reproduction code
not have
Steps to reproduce
Producer
main.ts producer
const app = await NestFactory.create<NestExpressApplication>(MainModule);
app.connectMicroservice<MicroserviceOptions>({
transport: Transport.RMQ,
options: {
urls: ['amqp://' + process.env.RABBIT_HOST + ':5672'],
queue: 'my_queue',
queueOptions: {
durable: false,
},
consumerTag: 'Service1',
},
});
await app.startAllMicroservices();
...
await app.listen(3000);
MainModule
ClientsModule.register([
{
name: 'MY_SERVICE',
transport: Transport.RMQ,
options: {
urls: ['amqp://' + process.env.RABBIT_HOST + ':5672'],
queue: 'tenant_queue',
queueOptions: {
durable: false,
},
},
},
]),
MainService
constructor(
...
@Inject('MY_SERVICE') private readonly client: ClientProxy,
) {}
@Post()
endpoint(...) {
...
switchMap((result) =>
forkJoin({
result: of(result),
db: this.client.send('my-event', result),
}),
),
}),
);
Consumer
main.ts
const app = await NestFactory.createMicroservice(MainModule, {
transport: Transport.RMQ,
options: {
urls: ['amqp://' + process.env.RABBIT_HOST + ':5672'],
queue: 'my_queue',
queueOptions: {
durable: false,
},
consumerTag: 'consumerService',
},
});
await app.listen();
consumerController:
@Controller()
export class ConsumerController {
constructor(
....,
private readonly connection: PrismaClientManager,
) {}
@MessagePattern('my-event')
async notify(
@Payload() { ... }: { ... : ... },
@Ctx() context: RmqContext,
) {
return ...;
}
}
Expected behavior
consumer answer to all events sent from rabbitmq provider
Package
- [ ] I don't know. Or some 3rd-party package
- [ ]
@nestjs/common - [ ]
@nestjs/core - [X]
@nestjs/microservices - [ ]
@nestjs/platform-express - [ ]
@nestjs/platform-fastify - [ ]
@nestjs/platform-socket.io - [ ]
@nestjs/platform-ws - [ ]
@nestjs/testing - [ ]
@nestjs/websockets - [ ] Other (see below)
Other package
No response
NestJS version
10.0.0
Packages versions
_ _ _ ___ _____ _____ _ _____
| \ | | | | |_ |/ ___|/ __ \| | |_ _|
| \| | ___ ___ | |_ | |\ `--. | / \/| | | |
| . ` | / _ \/ __|| __| | | `--. \| | | | | |
| |\ || __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/ \____/\_____/\___/
[System Information]
OS Version : Windows 10.0.22631
NodeJS Version : v18.20.2
NPM Version : 10.5.0
[Nest CLI]
Nest CLI Version : 10.3.2
[Nest Platform Information]
platform-express version : 10.3.3
microservices version : 10.3.3
schematics version : 10.1.1
passport version : 10.0.3
swagger version : 7.3.0
testing version : 10.3.3
common version : 10.3.3
config version : 3.2.0
core version : 10.3.3
jwt version : 10.2.0
cli version : 10.3.2
### Node.js version
18.20.2
### In which operating systems have you tested?
- [ ] macOS
- [X] Windows
- [ ] Linux
### Other
_No response_
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).