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.
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 usingsocketio.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.