centrifugal / centrifugo

Scalable real-time messaging server in a language-agnostic way. Self-hosted alternative to Pubnub, Pusher, Ably. Set up once and forever.
https://centrifugal.dev
Apache License 2.0
8.44k stars 598 forks source link

Is it possible to publish to multiple channels using a pattern? #855

Closed miguelb-gk closed 4 months ago

miguelb-gk commented 4 months ago

We are migrating from socketIO to Centrifugo, and so far, it's going great. However, we have a use case where we want to send a message to all connected users (i.e., a system message). Currently, each user has their own private channel (e.g., user:123) for user messages and an organization channel (e.g., org:123) for their organization messages.

I looked at the "channels" API endpoint, but it has a warning not to use it because there is no paging. We have about 50k channels open at a time, with the potential for this to grow over 100k. I don't see any way of publishing to "user:*"; it requires a specific channel. In socketIO, we use their "emit" method to send a message to all connected clients. How can we solve this in Centrifugo?

There are a couple of options I can think of to solve this:

Ideally we could broadcast to a pattern or to all connected clients, but not sure if that is a feature you have considered. What would be the recommended approach for us to solve this?

Thanks

FZambia commented 4 months ago

Hello, @miguelb-gk

It's not possible to broadcast to pattern, the solution with Centrifugo is one of yours actually:

Create another "system" channel and have all the users also connect to this system channel.

This is the correct approach in Centrifugo case.

Regarding pattern broadcast – it sounds as an interesting feature, but I never thought about it before and I think it should be justified by the use case where approach with a separate channel is not sufficient. Since to process system messages you need to write code on the client-side which handles the messages and updates UI anyway, adding a separate channel seems a proper and simple way to me. This can be client-side or server-side subscription.

miguelb-gk commented 4 months ago

Thanks! We will implement the "system" channel approach.