# How to set ResponseTopic in mqtt request message

**URL:** <https://discourse.nodered.org/t/how-to-set-responsetopic-in-mqtt-request-message/47471>\
**Category:** General\
**Created:** [22 June 2021 10:18 UTC](https://discourse.nodered.org/t/how-to-set-responsetopic-in-mqtt-request-message/47471 "2021-06-22T10:18:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [22 June 2021 10:52 UTC](https://discourse.nodered.org/t/how-to-set-responsetopic-in-mqtt-request-message/47471/3 "2021-06-22T10:52:40Z")

</div>

Here is a more dynamic example where the responseTopic is set progromatically (in the inject node) and passed into the MQTT node.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cde596a215574149bb61a5330c05fbb5060e462a.png)

```auto
[{"id":"28f0a45c19686fd5","type":"inject","z":"4b3f21a3.ba434","name":"demo/response2","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"correlationData","v":"[99,111,114,114,101,108,45,100,97,116,97]","vt":"bin"},{"p":"aa","v":"123","vt":"num"},{"p":"userProperties","v":"{\"number1\":1,\"subobj\":{\"sub1\":123}}","vt":"json"},{"p":"responseTopic","v":"demo/response2","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":2380,"y":820,"wires":[["19787fc720cb68ab"]]},{"id":"19787fc720cb68ab","type":"mqtt out","z":"4b3f21a3.ba434","name":"","topic":"demo/request","qos":"","retain":"","respTopic":"","contentType":"text/plain","userProps":"","correl":"","expiry":"","broker":"dc811dae.05f5","x":2580,"y":820,"wires":[]},{"id":"7bc91b8e43fc5073","type":"mqtt in","z":"4b3f21a3.ba434","name":"","topic":"demo/request","qos":"2","datatype":"auto","broker":"dc811dae.05f5","nl":false,"rap":false,"x":2350,"y":980,"wires":[["68b68b0196181c93"]]},{"id":"97d93f0a378e8811","type":"mqtt out","z":"4b3f21a3.ba434","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"dc811dae.05f5","x":2910,"y":980,"wires":[]},{"id":"1e4ccf4168a1a8dd","type":"mqtt in","z":"4b3f21a3.ba434","name":"","topic":"demo/response1","qos":"2","datatype":"auto","broker":"dc811dae.05f5","nl":false,"rap":false,"x":2760,"y":760,"wires":[["21cf9bced1749aec"]]},{"id":"21cf9bced1749aec","type":"debug","z":"4b3f21a3.ba434","name":"req res pattern","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2940,"y":760,"wires":[]},{"id":"68b68b0196181c93","type":"change","z":"4b3f21a3.ba434","name":"delete topic & add random payload","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"$floor( ($random() * 10) + 1)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":2640,"y":980,"wires":[["97d93f0a378e8811"]]},{"id":"b3fec62de35fb3c9","type":"comment","z":"4b3f21a3.ba434","name":" ***************Response topic demo************************","info":"","x":2490,"y":680,"wires":[]},{"id":"4b105356a7e74661","type":"comment","z":"4b3f21a3.ba434","name":"send payload to \"demo/request\" expect reply on the responseTopic set in the inject node","info":"","x":2580,"y":720,"wires":[]},{"id":"4093181e7772c1ad","type":"comment","z":"4b3f21a3.ba434","name":"fake external application recieving command and responding to reply topic","info":"","x":2540,"y":940,"wires":[]},{"id":"44fe4ed1ec155c5f","type":"inject","z":"4b3f21a3.ba434","name":"demo/response3","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"correlationData","v":"correl sent in msg as a string","vt":"str"},{"p":"aa","v":"123","vt":"num"},{"p":"userProperties","v":"{\"number\":1}","vt":"json"},{"p":"responseTopic","v":"demo/response3","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":2380,"y":860,"wires":[["19787fc720cb68ab"]]},{"id":"8b570801642403a4","type":"inject","z":"4b3f21a3.ba434","name":"demo/response1","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"correlationData","v":"correl sent in msg as a string","vt":"str"},{"p":"aa","v":"123","vt":"num"},{"p":"userProperties","v":"{\"number2\":2, \"number1\":1}","vt":"json"},{"p":"responseTopic","v":"demo/response1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":2380,"y":780,"wires":[["19787fc720cb68ab"]]},{"id":"4fb4c56e810f05d2","type":"mqtt in","z":"4b3f21a3.ba434","name":"","topic":"demo/response2","qos":"2","datatype":"auto","broker":"dc811dae.05f5","nl":false,"rap":false,"x":2760,"y":820,"wires":[["fc3420b94da5a25d"]]},{"id":"fc3420b94da5a25d","type":"debug","z":"4b3f21a3.ba434","name":"req res pattern","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2940,"y":820,"wires":[]},{"id":"7b2c384ce917327f","type":"mqtt in","z":"4b3f21a3.ba434","name":"","topic":"demo/response3","qos":"2","datatype":"auto","broker":"dc811dae.05f5","nl":false,"rap":false,"x":2760,"y":880,"wires":[["7cf85a9adfa8092a"]]},{"id":"7cf85a9adfa8092a","type":"debug","z":"4b3f21a3.ba434","name":"req res pattern","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2940,"y":880,"wires":[]},{"id":"dc811dae.05f5","type":"mqtt-broker","name":"","broker":"broker.emqx.io","port":"1883","clientid":"","usetls":false,"compatmode":false,"protocolVersion":"5","keepalive":"50","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

```

The settable inputs are listed in the built in help...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e6e374b97eb854ac49c21db76e282529becbb9d.png)

---

_[View the full topic](https://discourse.nodered.org/t/how-to-set-responsetopic-in-mqtt-request-message/47471)._
