Repository navigation
fix(microservices): ignore an mqtt server's own replies under wildcards - #18418
Merged
Merged
Conversation
4 of 12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
ServerMqttpublishes its replies on<topic>/replywith the same client that subscribes to the handlers' filters. A filter that ends in#(for example@MessagePattern('orders/#')) also matchesorders/1/reply, so the broker hands the server its own reply.handleMessagetakes it for a foreign message and runs the handler a second time, with the reply object as its input. Side effects of the handler run twice for one request. An exact topic and a+filter do not match the reply topic, so they are not affected.This is the MQTT twin of #18125, which fixed the same thing for the Redis server.
Issue Number: N/A
What is the new behavior?
handleMessageskips a message when all of these hold, asisOwnReplydoes inServerRedis:/reply,idand nopattern(a reply, not a request or an event),/replyand matches the topic.MQTT wildcards work on topic levels, so the last check uses the existing
matchMqttPatternandremoveHandlerKeySharedPrefix(shared subscriptions). A handler onorders/+/replyor an exactorders/1/replystill gets the replies. Requests published to a reply topic still arrive, because they carry apattern. No option is added and no default changes.Tests in
server-mqtt.spec.ts(4 of the new ones fail onmaster, the others pin the guard):orders/1/replyis not dispatched to a message handler, an event handler or a shared subscription onorders/#;users/#when another handler targets reply topics;orders/+/reply,orders/1/reply,+/+/replyand a sharedorders/+/reply;idare still dispatched;orders/+and the exact topic are not reached by the reply.I removed each condition of the guard one at a time and each time a test went red.
Does this PR introduce a breaking change?
Other information
A message that is not from Nest, has an
idand nopattern, and is published to a topic ending in/replyis now skipped unless a handler targets reply topics. Before, a wildcard event handler received it. This is the same rule as in the Redis server.One limit, as before this change: the server looks up one handler per topic. If a
#handler is registered before a handler on a reply filter, the lookup still returns the#one for the reply. This PR does not change that.