# Long Polling Message Bus Notifications from React Application

**URL:** https://meta.discourse.org/t/long-polling-message-bus-notifications-from-react-application/142722
**Category:** Development
**Created:** [February 26, 2020, 9:41pm UTC](https://meta.discourse.org/t/long-polling-message-bus-notifications-from-react-application/142722 "2020-02-26T21:41:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![StanLindsey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stanlindsey/32/170995_2.png) [@StanLindsey](https://meta.discourse.org/u/StanLindsey)
#### Post date: [February 26, 2020, 9:41pm UTC](https://meta.discourse.org/t/long-polling-message-bus-notifications-from-react-application/142722/1 "2020-02-26T21:41:23Z")

</div>

Hi all,

I’m currently building a React frontend to a headless Discourse server.

I am in the process of implementing the notifications count, similar to the one over the users avatar on here. I’d like this to be updated in near real-time using long polling over Discourse’s message\_bus.

I have seen the message-bus.js file but it is very verbose and out of date for a modern application. I don’t really want to be bringing in jQuery and a global object when we _should_ be doing it as part of the react application.

I have also seen in [/initializers/subscribe-user-notifications.js.es6](http://subscribe-user-notifications.js.es6) that we subscribe to `/notification/userid` but I cannot find documentation for the channels available to subscribe to or what the responses are.

I’m looking for help as to the best-practice way to implement subscribing to message bus in a modern javascript application.

Thanks! 👍

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 27, 2020, 10:29am UTC](https://meta.discourse.org/t/long-polling-message-bus-notifications-from-react-application/142722/2 "2020-02-27T10:29:56Z")

</div>

> [@StanLindsey](#):
>
> subscribing to message bus in a modern javascript application

Discourse **is** a modern javascript application 😛

The best way is to use the message-bus library. ~~Currently it does depend on JQuery, but if you would like to submit a pull request to remove that dependency, I’m sure it would be considered.~~

> [@StanLindsey](#):
>
> cannot find documentation for the channels available to subscribe to or what the responses are.

Messagebus is only intended to be used within Discourse, it’s not really a ‘public’ API. The best source of information will be the javascript files in the codebase, which you already found 👍

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 27, 2020, 10:54am UTC](https://meta.discourse.org/t/long-polling-message-bus-notifications-from-react-application/142722/3 "2020-02-27T10:54:25Z")

</div>

> [@david](#):
>
> Currently it does depend on jQuery, but if you would like to submit a pull request to remove that dependency, I’m sure it would be considered.

Minor correction 🙂

> MessageBus will first attempt to use jQuery and then fallback to a plain XMLHttpRequest version that’s contained in the `message-bus-ajax.js` file. `message-bus-ajax.js` must be loaded after `message-bus.js` for it to be used. You may override this option with a function that implements an ajax request by some other means

> **[GitHub - discourse/message\_bus: A reliable and robust messaging bus for Ruby and...](https://github.com/discourse/message_bus)**
>
> A reliable and robust messaging bus for Ruby and Rack

---

<div class="post-metadata">

### Author: ![StanLindsey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stanlindsey/32/170995_2.png) [@StanLindsey](https://meta.discourse.org/u/StanLindsey)
#### Post date: [February 27, 2020, 11:07am UTC](https://meta.discourse.org/t/long-polling-message-bus-notifications-from-react-application/142722/4 "2020-02-27T11:07:10Z")

</div>

Thanks @david, @sam, I didn’t mean to suggest that Discourse isn’t a modern application - it obviously is. I think I found message-bus.js first and I was confused whether that was truly the best-practice. It works right so its not a problem.

Thanks!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 27, 2020, 11:09am UTC](https://meta.discourse.org/t/long-polling-message-bus-notifications-from-react-application/142722/5 "2020-02-27T11:09:38Z")

</div>

Discourse core uses the exact same file, it is the right file ™
