Closed mjarmoc closed 4 years ago
It will be triggered in case:
You publish app with @RMQRoute('myTopic')
but after some time decide to refactor your code and changed route to @RMQRoute('myNewTopic')
. If any of other microservices will use old route this error will be triggered.
Are you sure :)? If you send('myTopic', payload)
I think the myNewTopic
microservice will not do anything, and all others microservices will response as previously. @RMQRoute
registers topics in the exchange that are used to bind to queues, so I can't imagine a scenario where the route does not exist in the controller, because if there is no route, then the message will not be delivered to queue, thus not consumed, thus not checked.
Correct me if I am wrong :)
When you first connecting with myTopic
, lib will do the following:
So after service stops, topic will stay bound to queue inside rabbitmq until you unbind it manually or drop RMQ configs.
When you start with myNewTopic
:
So after that we will have two bindings:
myTopic -> myQueue
myNewTopic -> myQueue
And 1 consumer that only knows how to deal with myNewTopic
. But when you send myTopic
it will get to the consumer because of bondings. And this code will be triggered)
https://github.com/AlariCode/nestjs-rmq/blob/fcee2326e46c00cf5904e72083660e798414981a/lib/rmq.service.ts#L157-L162
I believe this one will never get called. If there is no route, then it won't be registered as a routing key in the exchange. If so, then the message will never reach the queue, thus won't reach the rmq-controller.