-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an alternative channel layer implementation that uses Redis Pub/Sub #247
Conversation
There is one logic bug, but I'll propose that we do not fix it. This implementation does not support a Consumer doing this: self.channel_layer.group_add("whatever_group", someone_elses_channel_name) Rather, you need to stick with the normal pattern of only adding yourself to groups: self.channel_layer.group_add("whatever_group", self.channel_name) Stated another way: One consumer cannot subscribe a different consumer (denoted by Again, I would propose that we let this be a documented limitation of this implementation. Fixing it is possible by publishing special messages destined for |
The other thing to note: Not all configuration parameters are supported (yet). expiry I don't think this is needed. A consumer's own message queue will be cleaned up when that consumer disconnects, which essentially "expires" those messages for us (removes them from memory, that is). group_expiry Similarly, a group naturally "expires" when no one is subscribed to it. capacity This might make sense to implement. It wouldn't be hard, just add a check of the message queue length inside channel_capacity Same... symmetric_encryption_keys This would be easy enough to add, just pass these keys along to the two places where |
@acu192 but there is a workaround for this. When you need to add an channel to a group, you send it a special message internally. await self.channel_layer.group_send('user_private_channel', 'user_channel_name', {
'type': 'join_group',
'group_name': 'group_name_here'
}
) Similarly, for leaving groups, we could have an event handler called If you have any more questions or I haven't explained this clearly. please let me know. |
This is already the case (via
I'm interested in thinking about this more, although I'm not seeing this as a solution yet. For example, a common use-case in my app (and I assume other apps) is to add a channel to a group then immediately do a One idea, trying to solve it, would be for the caller of @aryan340 Out of curiosity, do you need this functionality in your app? I.e. adding channels to groups from the "outside"? |
I just added a runtime check to I propose we merge this PR with this known limitation. It is a low-risk merge (it does not change any existing code) and we can continue improving it over time. @aryan340 Perhaps after this PR is merged, you can send in a new PR with the workaround you proposed? Maintainers, what do you think? |
Yes, I would be needing that. My use case is, users are a part of boxes. Whenever they join a box, I listen to that via a listener and add the user to the associated group. So this needs to be done outside the consumer.
Sorry I meant that each consumer must have it's own private group. |
You can configure redis pub sub clients to listen for subscribe or unsubscribe messages. Everytime a client subscribes a message is sent. This way we can know if the consumer is finished subscribing. (edit) adding onto my previous statement, |
@acu192 I am okay if this PR doesnt provide external group add support out of the box. |
No, I'm not insisting; it would be totally up to you if you wanted to try to extend this implementation with your idea. But first we need the maintainers' buy-in to this PR. |
Hey @acu192 -- thanks for this. Looks good. Let me have a play. I think we should probably go with it as an option for folks. Nice. |
@carltongibson Thanks for considering this PR! I'm excited to get it integrated and help maintain it over time. If you want a simple project to play around with this, I copied this implementation into this repo: You can easily change which channel layer is used on this line of code. Currently it is set to use this new implementation, as you'll see. Maybe that gives you an easy way to play around with it. |
@carltongibson Also, after this is merged, I'll create issues in this repo to document the features that are still needed in this implementation to bring it in-line with the original implementation. I think it's best if we address those additional features in future PRs, to take this incrementally. |
nicely done. I have just a few nitpicks about the code, feel free to disregard them if you dont consider them important. Would it be possible to have a basic test added too, please? |
@yedpodtrzitko Your suggestions were fixed in the two commits above. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @acu192 — thanks for this. It looks nice.
Sorry for the delay. It's been hectic.
Some initial comments:
- I'm going to pull in Added Redis sentinel support. #250. Can you look out for that and rebase?
alt.py
is probably better aspubsub.py
no?- For tests, do you think we can
parametrize
thetest_core
tests? (i.e. we just want to check the channel layer API works, so running base tests on both channel layers seems desirable.)
Current plan is to go over the open PRs and then pull together a release. Thanks!
Co-authored-by: Chase Bennett <[email protected]>
@carltongibson The first two tasks are done:
For the tests, I'll look into that next... |
Okay, looking at the tests there are a few internal (non-API) differences that make this hard to use the same exact test code, for example the use of Another issue is that this pub/sub impl requires that you call Another issue is that Redis Pub/Sub does not have a unique keyspace per databases, thus the trick that
There may be other issues, but I stopped at this point. How about I write a new test suite ( |
OK, that sounds perfect. (The thought to parametrise was just about saving a bit of work, but yes, it’s not at the right level for that.) Please, yes, perhaps create fresh PR, as there’s a lot of noise here now — I think you merged, rather than rebased at the end there — and a fresh one-or-two-commit PR will be easier to review. Thanks! (This is quite exciting 😄) |
Here is a link to the new (cleaned-up) PR for this feature: #251 |
@yedpodtrzitko - Thanks again for your review and feedback of this initial PR. In case you haven't been following the progress of the |
Fixes Issue #245