Understanding client_id in the message bus

Hello :wave: ,

I’ve try to dive into the codebase recently, to figure out the client id in /message-bus/{client-id}/poll endpoint. Could someone please provide some guidance or direct me to the relevant code or documentation that explains what exactly this client ID represents and how it’s set?

Thanks in advance for your help!

1 Like

I could be wrong, but the clientId is likely to identify who the MessageBus should deliver X message to

Imagine it as a conversation where every X amount of time, the client asks the server “Hey, I have id XYZ, do you have a message for me?”

The client id seems to be automatically generated every time the script is loaded (I don’t know if in the case of Discourse this generated clientId somehow persists on the client)

1 Like

Are you trying to use or understand the message-bus?

If it’s the former, maybe describe what you’re trying to watch and what you’re doing that’s not working. What I do is grep through the plugins in GitHub - discourse/all-the-plugins for MessageBus.

3 Likes

To give some more context, we observer a high number of message-bus poll calls on our discourse hosting. Wanted to check whether there’s any correlation between client IDs and current users. If such a connection exists, it could help us identify patterns and define effective rate limiting rules to manage the traffic.

I mostly don’t understand it, but you can look at the browser dev tools and see that every open window is regularly polling the message bus. That’s how stuff happens without reloading the page, like seeing posts get edited, message counts updated, and so on. It’s expected that it will be a lot. Looks like it’s polling a random number, so you (or at least I) can’t tell (easily) what user it is.

Yes - a high number of message-bus poll calls represent a lot of concurrent users, where each unique client-id represents a browser session.

No - this is necessary traffic, it’s required for your forum to function. If you see a lot, it’s also a sign of success! :+1:

3 Likes