Sharing same @EventPattern across 2 handlers is broken if 2nd handler uses an interceptor
See original GitHub issueBug Report
Current behavior
Given two controller route handlers that subscribe to the same @EventPattern
, both handlers are executed as expected. However, if an interceptor is used on the 2nd handler, the interceptor is executed but the handler itself is never executed
Input Code
Reproduce: https://github.com/RoxKilly/nestjs-redis-troubleshoot/tree/issue-7913
export class AppController implements OnModuleInit {
constructor(@Inject('REDIS_CLIENT') private redis: ClientRedis) {}
onModuleInit(): any {
this.redis.emit(eventPattern, 'NEW EVENT');
}
@EventPattern(eventPattern)
handler1(data) {
Logger.log(data, 'Handler 1');
}
/** This will not be triggered unless we disable the interceptor or remove the other handler */
@EventPattern(eventPattern)
@UseInterceptors(LoggingInterceptor)
handler2(data) {
Logger.log(data, 'Handler 2');
}
}
Without Interceptor
Notice that both handler1
and handler2
receive and log the NEW EVENT
With Interceptor on 2nd handler
Notice the interceptor for handler2
is triggered, but handler2
never executes (it doesn’t log the event)
Expected behavior
I expected both handlers to be triggered even if I use an interceptor on the 2nd handler.
Possible Solution
Removing the interceptor from the 2nd handler makes this go away but is not a practical workaround.
Environment
Nest version: 8.0.6
For Tooling issues:
- Node version: 16.4.0
- Platform: Windows
Others:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
NestJS ClientRedis emits but EventPattern handler not triggered
NestJS was not listening on the Redis channel because after creating the microservice, I never started it. In main.ts I had to change:...
Read more >Microservices | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines ...
Read more >Domain Events – Take 2 - Udi Dahan
One thing that we want to keep in the solution is that all the code to define events, their names, and the parameters...
Read more >Event Handler called twice with the same event - Google Groups
I'm facing some problems using TrackingProcessors. Seems that sometimes, some handlers are called twice. It happens expecially if the handler method is very ......
Read more >Discovery and Service Mapping Patterns release notes
Read patterns documentation in one place. The ServiceNow Store documentation for IT Operations Management patterns is now in the release family sections of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed in 8.0.9
@HackPoint never, so far. I mean,
... Event pattern: undefined
never showed to me. When there is no listener, message always shows name of pattern.