Incorrect subscriber handle called
See original GitHub issueThis seems like a bug or a wrong usage on my side, please let me know if you experienced something similar.
We have a topic exchange with different microservices sending events to an audit log service.
In the audit log service we have an @Injectable()
subscriber class with several @RabbitSucribe()
handlers, designed to handle different types of events based on routingKey
.
The routing key is of form “service.action.object” and the handlers’ routing key templates are correspondingly, *.created.*
, *.updated.*
, *.deleted.*
, etc. They do very similar things, so I didn’t notice at start, but seems even though all data in the message is correctly sent (especially the routing key), the handlers are not consistently called based on the defined template.
For example, an admin.deleted.User
message might end up being handled by the created or updated handler…
We tried to get to the bottom of this, but can’t find anything wrong with our setup or code. Also noticed that if I break up the 1 subscriber class, into several @Injectable()
classes, each with only 1 @RabbitSucribe()
handler - the issue goes away.
Is it wrong to use multiple @RabbitSucribe()
inside one class? Or is there another issue down the line?
EDIT: In fact the separated subscribers with 1 handler also doesn’t work (only looked working at start). So what exactly might be the issue?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
@Sikora00 Please review the RabbitMQ patterns documentation around message routing and exchanges. Both of these two links are very valuable in understanding how things work under the hood when it comes to these concepts. Don’t worry about the code samples since
@golevelup/nestjs-rabbitmq
abstracts away most of that for you. What is important is that you take a look at the diagrams and concepts being presented so that you understand the relationship between routing, queues and consumers.Understanding these concepts will make it much easier for you to leverage RabbitMQ across any programming language or library
https://www.rabbitmq.com/tutorials/tutorial-four-javascript.html https://www.rabbitmq.com/tutorials/tutorial-five-javascript.html
I’m closing this for now because it works as intended based on the underlying RabbitMQ implementation. If there are additional issues related to this feel free to open or create a new issue