question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It is not possible to use RegEx for event matching on the @EventPattern() adn @MessagePattern()

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:25 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
Idan747commented, Oct 13, 2021

Hi, any update on this?

5reactions
Vetmcommented, May 10, 2021

Any updates on this? Without this feature kafka is pretty much useless for us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - What's a valid @MessagePattern for NestJS MQTT ...
I'm trying to setup a MQTT Microservice using NestJS according to the docs. I've started a working Mosquitto Broker using Docker and verified ......
Read more >
Amazon EventBridge event patterns - AWS Documentation
Event patterns have the same structure as the events they match. Rules use event patterns to select events and send them to targets....
Read more >
Microservices | NestJS - A progressive Node.js framework
The emit() method takes two arguments, pattern and payload . The pattern should match one defined in an @EventPattern() decorator. The payload is...
Read more >
API with NestJS #18. Exploring the idea of microservices
By implementing the microservice architecture, we break down our API into smaller, independent components. Having a separate codebase, and ...
Read more >
Cisco IOS Embedded Event Manager Command Reference
EEM will use a vty line when a vty line is not being used by EEM and there are ... from within a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found