jrief / django-websocket-redis

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

Using DWR with multi-tenants #252

Open LiteWait opened 6 years ago

LiteWait commented 6 years ago

We run a multi-tenant solution using diango_tenants supporting 1000's of tenants on a cluster of web servers. It seems obvious there is no support for multi-tenant solutions in DWR. My question is does it seems feasible that DWR could be modified to support this? I've pulled down Channels and managed to get it working by picking the host from web socket connect to anchor the instance on a particular DB schema and squirreling the tenant info in the channel session. DWR just seems cleaner than Channels, but if I can't pull off multi-tenant it is a non-starter. Other option would be to replace Redis in DWR with RabbitMQ which I sure would be a brutal pill to swallow! Thanks.

jrief commented 6 years ago

If you run ws4redis you can dispatch the websockets by their session-id. In general, I always suggest to use websockets from the server to the client, and pure Ajax the other way round. Then the server can decide to whom a message will go, session or group.

It might be, that I did not understand your question correctly.

oortega commented 4 years ago

Hello @LiteWait could you run ws4redis with multi tenant?

Hello @jrief I am using django schemas and ws4redis, but it does not work subscribe user, it only works when it is broadcast and session.

Subscribe user I guess it does not work because each postgres schema has a list of users and I suppose that ws4redis does not know what schema the user is up to, do you know what I should modify so that the message is sent to the user of the schema that initiated the request?

I use this https://django-tenant-schemas.readthedocs.io/en/latest/

Here https://github.com/oortega/facturas_tenant I have the example of chat you have on ws4redis but only broadcast works, subscribe user does not work

I have noticed that it only works subscribe user in the public scheme, in celery the same error happened to me but in the task I do this


from django.db import connection
connection.set_schema(schema)

and I can already consult the correct tenant, do you know how I can tell ws4redis to consult the correct tenant?

thanks.