# How can i subscribe to topics using websockets?

**URL:** https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935
**Category:** General
**Created:** [8 October 2020 12:26 UTC](https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935 "2020-10-08T12:26:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![codecracker2020](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codecracker2020/32/37449_2.png) [@codecracker2020](https://discourse.nodered.org/u/codecracker2020)
#### Post date: [8 October 2020 12:27 UTC](https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935/1 "2020-10-08T12:27:00Z")

</div>

How can i subscribe to topics using websockets?

I am able to setup the connection but dont know how to subscribe to the topic. Please help

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [8 October 2020 12:29 UTC](https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935/2 "2020-10-08T12:29:54Z")

</div>

Hi @codecracker2020, welcome to the forum. I think your question is missing a key bit of information - what are you connecting to exactly?

When you say 'subscribe to topics', I'm guessing you mean you are connecting to an MQTT broker over websockets?

If that is the case, what nodes are you using to do that - the MQTT nodes or the WebSocket nodes?

---

<div class="post-metadata">

### Author: ![codecracker2020](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codecracker2020/32/37449_2.png) [@codecracker2020](https://discourse.nodered.org/u/codecracker2020)
#### Post date: [8 October 2020 12:34 UTC](https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935/3 "2020-10-08T12:34:08Z")

</div>

Thanks for the prompt response.. I am trying to establish a websocket connection with below url:  
[https://domainname:5051/my-service/websocket](https://domainname:5051/my-service/websocket)

After establishing websocket connection, i need to subscribe and start hearing to responses based on below topics. The number below indicate machine number.

/topic/units/112/activityrecords  
/topic/units/255/activityrecords  
/topic/units/811/activityrecords  
/topic/units/758/activityrecords

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [8 October 2020 12:45 UTC](https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935/4 "2020-10-08T12:45:35Z")

</div>

Hi @codecracker2020

but again you have not said if you mean with MQTT or not. Nor have you said what nodes you are using.

---

<div class="post-metadata">

### Author: ![codecracker2020](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codecracker2020/32/37449_2.png) [@codecracker2020](https://discourse.nodered.org/u/codecracker2020)
#### Post date: [8 October 2020 13:14 UTC](https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935/5 "2020-10-08T13:14:55Z")

</div>

I am using Websocket In and Websocket Out nodes. not MQTT.. I am using wss protocol.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [8 October 2020 13:19 UTC](https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935/6 "2020-10-08T13:19:33Z")

</div>

The websocket protocol has no concept of topics or subscriptions... so you will need to use some application-level protocol over the connection. This is why I thought you were referring to MQTT.

---

<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: [7 December 2020 13:19 UTC](https://discourse.nodered.org/t/how-can-i-subscribe-to-topics-using-websockets/33935/7 "2020-12-07T13:19:37Z")

</div>

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