laravel-centrifugo icon indicating copy to clipboard operation
laravel-centrifugo copied to clipboard

Site-wide centrifugo namespace for all channels

Open tfk-kaare opened this issue 3 years ago • 3 comments

When having several sites run on the same centrifugo server, the channel names and channel config may be in conflict. Centrifugo has support for channel namespaces, which is a perfect place to group site-wide channels in.

This PR is an attempt at keeping the internal Laravel channel names 'clean' (without namespaces), and when sending them to centrifugo, prefix them with the configured namespace for this site. It's still possible to drop site-wide namespaces and add namespaces to channels manually, but the two may not mix.

This will also remove the pain with adding custom namespace on channel names for model broadcasting, and other laravel 'magic' channel name generation.

Please review, consider, and test. It's not well tested. I have this working on two sites with two different namespaces and their custom centrifugo config, one using only public channels, the other only private.

P.S. The commits and commit log is gibberish, so please do a squash merge, if applicable.

tfk-kaare avatar Dec 08 '21 12:12 tfk-kaare

Hello. I consulted with the founder of Centrifugo. Namespaces are needed to delimit different features within the project, but not tie the entire site to one Namespace. Therefore, it would be wiser to put this logic in the project itself, and not in this package.

I will look at your implementation in detail, maybe there will be good ideas

denis660 avatar Dec 09 '21 17:12 denis660

That is true, but as mentioned, it's still possible to run 'custom' namespace within a single project by not using the site-wide ns.

It might be worth describing this in more detail and warn the user about inability to use in-site centrifugo namespaces, if global namespace is utilized.

tfk-kaare avatar Dec 09 '21 17:12 tfk-kaare

I've been thinking about this feature, and I see the conundrum. Centrifugo's namespace-feature should be available for the entire site, and trying to shoe-horn multi-site support in Centrifugo using namespaces is kind of a hack. It's a pity centrifugo doesn't support this out of the box; multi-site support, that is.

Another approach for multi-site support could be adding a site prefix (e.g CENTRIFUGO_SITE_PREFIX) to the channel name part, and leaving the namespace alone. This would allow all sites to use all namespaces, and have the same internal name without collision. So two sites, alice and bob with their respecive names as centrifugo channel prefix would then translate the shared, private channel named $buffered:example into: $buffered:alice-example and $buffered:bob-example. Problem now is that it becomes more for the developers to grasp, and figure out.

Let me know what you think. Area any of these two approaches edible?

  1. Current implementation using centrifugo channel namespaces as site prefix. You loose site internal centrifugo namespaces if utilizing site-wide NS.
  2. Add a site prefix to the bare channel name with the benefit of having all namespaces available, at the cost of more complex channel names.

Either way. Back to the original problem: Having several, similar sites, run on the same centrifugo server will occasionally cause channel collision, causing unforeseen problems. Implementing different site channel names per site results in a lot of scattered channel name modifications, when the real place to solve this would be at either centrifugo or centrifugo-wrapper (this project) level.

I'm leaving this PR hanging for now until a decision is taken.

tfk-kaare avatar Dec 13 '21 08:12 tfk-kaare

Hello. Unfortunately, I cannot accept your PR. This goes against the core concept of centrifugo

denis660 avatar Mar 30 '23 18:03 denis660