# Subscribe to the same topic multiple times and find problems

**URL:** <https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160>\
**Category:** General\
**Tags:** mqtt\
**Created:** [6 November 2022 12:03 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160 "2022-11-06T12:03:23Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joe1](https://discourse.nodered.org/u/joe1)\
**Post date:** [6 November 2022 12:03 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/1 "2022-11-06T12:03:24Z")

</div>

In practice, you should not subscribe to the same topic repeatedly, but try to subscribe to the same topic repeatedly in the test. If you find a problem, I am a beginner. Maybe it is not a problem. Looking forward to the answers.  
The broker and topic needs to be changed to yours

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/056388dfcecdc91470f2d60b3176c0a899401ffb.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 November 2022 12:26 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/2 "2022-11-06T12:26:07Z")

</div>

Please explain what problem you are seeing, and export a small flow demonstrating the problem. Then we can import it and see if we can replicate it.

---

<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:** [6 November 2022 13:10 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/3 "2022-11-06T13:10:34Z")

</div>

Please share this exact flow.

Also, please explain what you are attempting to achieve please.

---

<div class="post-metadata">

**Author:** ![joe1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joe1](https://discourse.nodered.org/u/joe1)\
**Post date:** [6 November 2022 13:54 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/4 "2022-11-06T13:54:10Z")

</div>

The number is the execution order (click the execution order)  
After step 3, the data can be received normally, but the received data is lost when subscribing again (4-step, 5-step). If the data is repeated again (6-step, 7-step), the received data is empty

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

```auto
[{"id":"eafbf2bd0cb1a911","type":"inject","z":"bef43d30cc72242e","name":"sub single string v1/devices/me/attributes/response/+","props":[{"p":"action","v":"subscribe","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"v1/devices/me/attributes/response/+","x":250,"y":1200,"wires":[["1bc939d3424e96b0"]]},{"id":"e8dff4a1a2332288","type":"comment","z":"bef43d30cc72242e","name":"Subscribe topics","info":"","x":120,"y":1160,"wires":[]},{"id":"60c93ad54211496a","type":"comment","z":"bef43d30cc72242e","name":"connect / disconnect / other","info":"","x":160,"y":960,"wires":[]},{"id":"4286c855f442a60a","type":"inject","z":"bef43d30cc72242e","name":"unsub all","props":[{"p":"action","v":"unsubscribe","vt":"str"},{"p":"topic","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":1280,"wires":[["1bc939d3424e96b0"]]},{"id":"1bc939d3424e96b0","type":"mqtt in","z":"bef43d30cc72242e","name":"Dynamic 1","topic":"","qos":"2","datatype":"auto","broker":"d98ab0d0f2c84665","nl":false,"rap":true,"rh":0,"inputs":1,"x":560,"y":1200,"wires":[["ba7d968d025e1434"]]},{"id":"e568f02f852ae49b","type":"inject","z":"bef43d30cc72242e","name":"get subscriptions","props":[{"p":"action","v":"getSubscriptions","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":1100,"wires":[["1bc939d3424e96b0"]]},{"id":"e52d5308b7f9bcf9","type":"complete","z":"bef43d30cc72242e","name":"","scope":["1bc939d3424e96b0"],"uncaught":false,"x":570,"y":1260,"wires":[["0f439578c36a5008"]]},{"id":"0f439578c36a5008","type":"debug","z":"bef43d30cc72242e","name":"Complete messages from dyn 1","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":810,"y":1260,"wires":[]},{"id":"414cc9a11b496a4f","type":"debug","z":"bef43d30cc72242e","name":"action response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":780,"y":1140,"wires":[]},{"id":"ba7d968d025e1434","type":"switch","z":"bef43d30cc72242e","name":"has msg.action","property":"action","propertyType":"msg","rules":[{"t":"eq","v":"getSubscriptions","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":1140,"wires":[["414cc9a11b496a4f"],["409d563946353ca3"]]},{"id":"409d563946353ca3","type":"debug","z":"bef43d30cc72242e","name":"MQTT messages dyn 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":1200,"wires":[]},{"id":"6781fe8f9ee034d1","type":"inject","z":"bef43d30cc72242e","name":"connect with json","props":[{"p":"broker","v":"{\"broker\":\"thingsboard.cloud\",\"port\":1883,\"force\":true,\"username\":\"BSAPbKZ1a6bx8MkKbDWh\",\"protocolVersion\":5}","vt":"json"},{"p":"action","v":"connect","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":1060,"wires":[["1bc939d3424e96b0"]]},{"id":"3dcadd366cc27acd","type":"inject","z":"bef43d30cc72242e","name":"v1/devices/me/attributes/request/1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"v1/devices/me/attributes/request/1","payload":"{}","payloadType":"json","x":240,"y":1500,"wires":[["a18a861103436e0c"]]},{"id":"a18a861103436e0c","type":"mqtt out","z":"bef43d30cc72242e","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"d98ab0d0f2c84665","x":510,"y":1460,"wires":[]},{"id":"903741c1c11402fb","type":"comment","z":"bef43d30cc72242e","name":"publish to regular mqtt out","info":"","x":150,"y":1460,"wires":[]},{"id":"4f8034d0227e584a","type":"inject","z":"bef43d30cc72242e","name":"disconnect","props":[{"p":"action","v":"disconnect","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":160,"y":1420,"wires":[["a18a861103436e0c"]]},{"id":"719be51b1cd86bc9","type":"complete","z":"bef43d30cc72242e","name":"","scope":["a18a861103436e0c"],"uncaught":false,"x":710,"y":1420,"wires":[["abc50b92610133e7"]]},{"id":"a76d844dc80ac6a0","type":"debug","z":"bef43d30cc72242e","name":"Complete messages mqtt-out","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"msg","x":780,"y":1500,"wires":[]},{"id":"ae2413b34f94726e","type":"comment","z":"bef43d30cc72242e","name":"Testing connect / disconnect actions with an mqtt-out","info":"","x":230,"y":1380,"wires":[]},{"id":"abc50b92610133e7","type":"switch","z":"bef43d30cc72242e","name":"has msg.action","property":"action","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":720,"y":1460,"wires":[["a76d844dc80ac6a0"]]},{"id":"d45b360505a4c0d2","type":"inject","z":"bef43d30cc72242e","name":"disconnect","props":[{"p":"action","v":"disconnect","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":1020,"wires":[["1bc939d3424e96b0"]]},{"id":"e83d1023f7bc72e3","type":"comment","z":"bef43d30cc72242e","name":"Unsubscribe topics","info":"","x":130,"y":1240,"wires":[]},{"id":"d98ab0d0f2c84665","type":"mqtt-broker","name":"broker_to_test_mqtt_control","broker":"localhost","port":"1883","clientid":"","autoConnect":false,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

```

---

<div class="post-metadata">

**Author:** ![joe1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joe1](https://discourse.nodered.org/u/joe1)\
**Post date:** [6 November 2022 14:04 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/5 "2022-11-06T14:04:35Z")

</div>

Several more brokers are provided for testing by multiple people, which may not be connected to the broker  
{  
"broker": "thingsboard.cloud",  
"port": 1883,  
"force": true,  
"username": "2pbCdh3BI8SbsKD2iWzb",  
"protocolVersion": 5  
}

username guZYLGYDty9n51y0tYvx

---

<div class="post-metadata">

**Author:** ![joe1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joe1](https://discourse.nodered.org/u/joe1)\
**Post date:** [6 November 2022 14:16 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/6 "2022-11-06T14:16:12Z")

</div>

![GIF 2022-11-6 22-14-12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83a3b7d1520c7a444363f805f5287b9e9194357f.gif)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 November 2022 14:48 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/7 "2022-11-06T14:48:25Z")

</div>

Are they using the same client id, try leaving it blank in the broker

---

<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:** [6 November 2022 16:20 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/8 "2022-11-06T16:20:36Z")

</div>

Hi. I will check this but could you verify your what is ACTUALLY coming from broker by using an independent client?

As you seem to be using MQTT v5 then I suggest [MQTT X](https://mqttx.app/) as it supports v5.

Use a separate client to subscribe to topics `v1/devices/me/attributes/request/1` and `v1/devices/me/attributes/response/1` & compare that to the debug value you see in Node-RED.

---

<div class="post-metadata">

**Author:** ![joe1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joe1](https://discourse.nodered.org/u/joe1)\
**Post date:** [7 November 2022 02:43 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/9 "2022-11-07T02:43:26Z")

</div>

I confirm that thingboard is normal,I try unsub all, and then sub, and there will be no data or partial data.

---

<div class="post-metadata">

**Author:** ![joe1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joe1](https://discourse.nodered.org/u/joe1)\
**Post date:** [7 November 2022 02:46 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/10 "2022-11-07T02:46:53Z")

</div>

In theory, the same client ID, no matter how many times you subscribe to the same topic, should also be the same topic, and the results should be normal. I'm a novice, maybe the description is wrong.You can try to change the sub to your business address

---

<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:** [7 November 2022 06:55 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/11 "2022-11-07T06:55:03Z")

</div>

> [@joe1](#):
>
> I confirm that thingboard is normal,I

How did you confirm this?  
Can you show screenshots?

Are you using feature of MQTT v5? If not could you retest using v3.1? (`protocolVersion = 4`)

I also tried the flow & sequence of operation with a mosquito broker - it works perfectly.

---

<div class="post-metadata">

**Author:** ![joe1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joe1](https://discourse.nodered.org/u/joe1)\
**Post date:** [7 November 2022 08:29 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/12 "2022-11-07T08:29:03Z")

</div>

Your guess is correct. thingsboard's protocol is v3. Because of my carelessness, I connected v3 with v5. Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 November 2022 08:29 UTC](https://discourse.nodered.org/t/subscribe-to-the-same-topic-multiple-times-and-find-problems/70160/13 "2022-11-21T08:29:51Z")

</div>

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