Description
Bug Report
.
Current behavior
It is not possible to use a RegEx for event and message patterns. This is possible when using KafkaJS library but is not possible in NestJS
Input Code
Having a controller emitting a message 'pre-notify-post'
@Post('notify-with-regex')
async sendNotificationForRegExMatching(): Promise<any> {
return this.client.emit('pre-notify-post', { notify: true });
}
Also having a controller with the event handler and expecting messages that match the regular expression of /.*notify.*/
:
@EventPattern(/.*notify.*/)
secondEventHandler(data: any) {
KafkaController.IS_NOTIFIED_WITH_REGEX = data.value.notify;
}
Currently, the event handler never gets called, because the handler is not matched using regular expressions.
Expected behavior
It is expected to listen to events and messages by using RegEx patterns. This is possible in KafkaJS library and it is useful when having a set of a topic that the consumer wants to listen to.
Alternatively, you can subscribe to multiple topics at once using a RegExp:
await consumer.connect()
await consumer.subscribe({ topic: /topic-(eu|us)-.*/i })
https://kafka.js.org/docs/consuming
Possible Solution
This could be fixed by getting the matching routes.
Environment
Nest version: 6.7