nestjs
nestjs copied to clipboard
routingKey is ignored
Hi guys,
I'm encountering an issue with the RabbitMQ module. I have two subscribers listening on the same queue but with different routing keys. However, messages are being processed in a round-robin fashion between the handlers, regardless of the routing key.
Here's the code:
@RabbitSubscribe({
exchange: 'asset.topic',
routingKey: 'asset.index.success',
queue: 'api.assetModule',
})
async onAssetIndexed(data: { caseId: number; assetId: number }) {
this.logger.log(`Asset ${data.caseId}/${data.assetId} indexed successfully`);
}
@RabbitSubscribe({
exchange: 'asset.topic',
routingKey: 'asset.index.error',
queue: 'api.assetModule',
})
async onAssetIndexError(data: { caseId: number; assetId: number; reason: string }) {
this.logger.error(`Failed to index asset ${data.caseId}/${data.assetId}: ${data.reason}`);
}
Even with 3 messages having the asset.index.success key, both handlers are receiving them alternately.
Am I missing something, or could this be a bug? Using version 5.4.0 of the library.
I would have expected the routingKey to also be used by the library to call the right handler, as opposed to it only being used to bind the queue to certain keys.
Any advice would be appreciated!