# How to pass a message through the MQTT IN node configured in dynamic subscription mode

**URL:** <https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064>\
**Category:** General\
**Tags:** mqtt\
**Created:** [5 August 2022 10:29 UTC](https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064 "2022-08-05T10:29:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 August 2022 11:09 UTC](https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064/2 "2022-08-05T11:09:19Z")

</div>

Works fine - just not how you think.

Here is a fully working demo...

> [@Dynamic MQTT node's "actions-\>connect" guidance needed](https://discourse.nodered.org/t/dynamic-mqtt-nodes-actions-connect-guidance-needed/58878/2):
>
> The dynamic connection does not overwrite fields. It simply connects to the broker specified in the msg you send. You just add a broker (with any settings you like) and set it to NOT auto connect [image] then you send the appropriate msg to set up and connect. Here is a working demo... [mqtt-dyn] [{"id":"a7f43be0a40d080b","type":"mqtt out","z":"8afdb9e0485c9da7","name":"mqtt out","topic":"","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","…

Here is another using your values...  
 ![chrome_6Z6vYYtxra](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/a/aabad48cd134b29fc488681eb316ab19ec840bdd.gif)

```auto
[{"id":"90c6b92a167ccfd0","type":"function","z":"ec9cf53f5ff54f3b","name":"connect action","func":"msg.broker = {\"broker\":\"broker.hivemq.com\",\"port\":1883};\nmsg.action = \"connect\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":60,"wires":[["66b1ad13cb265281"]]},{"id":"66b1ad13cb265281","type":"mqtt in","z":"ec9cf53f5ff54f3b","name":"","topic":"","qos":"2","datatype":"auto-detect","broker":"87ae16f44f4c9289","nl":false,"rap":true,"rh":0,"inputs":1,"x":1370,"y":80,"wires":[["11fbaa32576de64f"]]},{"id":"3ae59f4eb19407ae","type":"inject","z":"ec9cf53f5ff54f3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":960,"y":60,"wires":[["90c6b92a167ccfd0"]]},{"id":"11fbaa32576de64f","type":"debug","z":"ec9cf53f5ff54f3b","name":"debug 54","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1400,"y":140,"wires":[]},{"id":"7d4e46fa8e71c57a","type":"mqtt out","z":"ec9cf53f5ff54f3b","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"87ae16f44f4c9289","x":1190,"y":260,"wires":[]},{"id":"72b84df48b0acf5a","type":"inject","z":"ec9cf53f5ff54f3b","name":"{\"key\":\"32wf43eg\"}","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"joshworld","payload":"{\"key\":\"32wf43eg\"}","payloadType":"json","x":1010,"y":260,"wires":[["7d4e46fa8e71c57a"]]},{"id":"dd2ae0d3db44925e","type":"function","z":"ec9cf53f5ff54f3b","name":"subscribe action","func":"msg.action = \"subscribe\";\nmsg.topic = \"joshworld\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":140,"wires":[["66b1ad13cb265281"]]},{"id":"41db7b3deaae2651","type":"inject","z":"ec9cf53f5ff54f3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":960,"y":140,"wires":[["dd2ae0d3db44925e"]]},{"id":"4329193ee5bd637b","type":"inject","z":"ec9cf53f5ff54f3b","name":"{\"key\":\"32wf43eg\"}","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"joshworld","payload":"{\"key\":\"abcdef\"}","payloadType":"json","x":1010,"y":300,"wires":[["7d4e46fa8e71c57a"]]},{"id":"dea0d19eb4e1a97a","type":"inject","z":"ec9cf53f5ff54f3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":960,"y":180,"wires":[["2a1712b5f6c429c5"]]},{"id":"2a1712b5f6c429c5","type":"function","z":"ec9cf53f5ff54f3b","name":"unsubscribe action","func":"msg.action = \"unsubscribe\";\nmsg.topic = \"joshworld\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1150,"y":180,"wires":[["66b1ad13cb265281"]]},{"id":"18c55b5aa26ca697","type":"function","z":"ec9cf53f5ff54f3b","name":"disconnect action","func":"msg.action = \"disconnect\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1150,"y":100,"wires":[["66b1ad13cb265281"]]},{"id":"3f476107531ea14f","type":"inject","z":"ec9cf53f5ff54f3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":960,"y":100,"wires":[["18c55b5aa26ca697"]]},{"id":"87ae16f44f4c9289","type":"mqtt-broker","name":"dynamic","broker":"0.0.0.0","port":"1883","clientid":"","autoConnect":false,"usetls":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

---

_[View the full topic](https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064)._
