jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
896 stars 222 forks source link

Allowing More Than One Subscriber Class? #169

Open pkkid opened 8 years ago

pkkid commented 8 years ago

I want to use django-websocket-redis for more than one type of app. I touched on this the other day, but didn't really collect my thoughts enough and thus removed the issue.

I think in the simplest form, I want to have different subscribers for different facilities. Much like Django's urls.py in how a regex points to a view. For example, we could define WS4REDIS_SUBSCRIBERS like below, where the key is a regex matched with the request's facility string. Then the WsgiServer would map the request to the correct Subscriber class (perhaps returning a 404 if there are no matches).

WS4REDIS_SUBSCRIBERS = {
    'someapp': 'mysite.subscribers.SomeAppSubscriber',
    'chat-(.*?)': 'mysite.subscribers.ChatSubscriber',
    ...
}

# The current behavior (allowing anything) could be achieved with the following..
WS4REDIS_SUBSCRIBERS = {
    '.*': 'ws4redis.subscriber.RedisSubscriber',
}
pkkid commented 8 years ago

Here is a working prototype showing how this could work which falls back to the current behavior. If this were accepted, a few more things need to be thought out first: