Dynamic MQTT-in causes other nodes to re-receive retained messages

I have a dynamic MQTT-in node that occasionally subscribes and then later unsubscribes. While I expected this node to receive all relevant retained messages on subscribe, it didn't initially occur to me that all other MQTT-in nodes would also re-receive their relevant retained messages.

I guess I'm just thinking out loud, because there's probably no solution where I can have the dynamic MQTT-in receive the retained messages, but not any of the other MQTT-in nodes. Does anybody have any ideas?

I actually want the node doing the dynamic sub/unsub to receive the retained messages - that's it's purpose. I sometimes screw up and accidentally let retain 'leak' from an MQTT-in to an MQTT-out (or via copy/paste of a MQTT-out node), and sometimes it causes problems. Since I always put "/retained" in the topic of any message I want to retain, this flow warns me every two hours if there's retained messages that don't have it. The purpose of the sub/unsub is largely to keep warning me until I fix it.

At this stage the only solution appears to be to not make it dynamic and build a list of warnings that is emptied on deploy/restart and keeps reminding me every 2 hours. When I delete the retained message I would then have to manually clear the list and cause the retained messages to be resent. Or maybe I just automatically delete it, reload retained messages, and send myself a warning.

If you are (dynamically) subscribing to a topic that another MQTT In node is statically subscribed to, this could occur.

Is that what you are doing?

If you are dynamically subscribing to a different topic (one that is not statically subscribed to) and ALL other MQTT in nodes are triggered with retained messages, then this is not right.

Can you provide further details? E.g.

  • Node version
  • Node-RED version
  • MQTT broker type & version (e.g mosquito v2.x)
    • where MQTT broker is installed (same computer? Other computer in same network? External/cloud broker?)
  • a screenshot of the MQTT config settings

Lastly, a minimal flow that demonstrates this would be very helpful.

Yes this node dynamically subscribes to "mb/#", and I prefix all my messages with "mb/" so while it is only sending retained messages that match that, it's pretty broad and causes all other nodes subscribing to a subset (eg. "mb/my/test") to get their retained messages as well. Not a show stopper, just unexpected until I thought about it.

Ok, that is not unexpected.

if you answer the request for further details, I suspect i have a (very simple) solution. Like 1 simple change, deploy, fixed.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.