Phuks-co / throat

Open Source link aggregator and discussion platform powering Phuks
https://phuks.co
MIT License
73 stars 32 forks source link

Connect socketio messaging to Redis publish/subscribe #422

Closed happy-river closed 2 years ago

happy-river commented 2 years ago

Allow an external process to receive notifications of events and to send notifications to users who have active websocket connections, using Redis.

Publish all messages sent via socketio.emit to Redis, using keys of the form {namespace}:{event}:{room} and encoding the payload with JSON. Subscribe to keys on Redis of the form /send:{event}:{room}, and when a message is received decode the payload from JSON and send it out in the /snt namespace using socketio.emit, as well as republishing it on Redis as /snt:{event}:{room}.

The emitting and republishing uses a greenlet task so is only done if the server is running under gevent. Since there may be more than one such server process, have another greenlet task maintain a key on Redis with a short expiration time, and use those keys to determine which process will do the work.