@@ -215,23 +215,23 @@ Using a Message Queue
215
215
216
216
The Socket.IO server owns the socket connections to all the clients, so it is
217
217
the only process that can emit events to them. Unfortunately this becomes a
218
- limitation for many applications, as a common need is to emit events to
219
- clients from a different process, like a
220
- `Celery <http://www.celeryproject.org/ >`_ worker, or any other auxiliary
221
- process or script that works in conjunction with the server.
218
+ limitation for many applications that use more than one process. A common need
219
+ is to emit events to clients from a process other than the server, for example
220
+ a `Celery <http://www.celeryproject.org/ >`_ worker.
222
221
223
- To enable these other processes to emit events, the server can be configured
224
- to listen for externally issued events on a message queue such as
222
+ To enable these auxiliary processes to emit events, the server can be
223
+ configured to listen for externally issued events on a message queue such as
225
224
`Redis <http://redis.io/ >`_ or `RabbitMQ <https://www.rabbitmq.com/ >`_.
226
225
Processes that need to emit events to client then post these events to the
227
226
queue.
228
227
229
228
Another situation in which the use of a message queue is necessary is with
230
229
high traffic applications that work with large number of clients. To support
231
230
these clients, it may be necessary to horizontally scale the Socket.IO
232
- server by splitting the client list among multiple server processes. For this
233
- type of installation, the server processes communicate with each other through
234
- ta message queue.
231
+ server by splitting the client list among multiple server processes. In this
232
+ type of installation, each server processes owns the connections to a subset
233
+ of the clients. To make broadcasting work in this environment, the servers
234
+ communicate with each other through the message queue.
235
235
236
236
The message queue service needs to be installed and configured separately. By
237
237
default, the server uses `Kombu <http://kombu.readthedocs.org/en/latest/ >`_
@@ -240,29 +240,38 @@ can be used. Kombu can be installed with pip::
240
240
241
241
pip install kombu
242
242
243
+ To use RabbitMQ or other AMQP protocol compatible queues, that is the only
244
+ required dependency. But for other message queues, Kombu may require
245
+ additional packages. For example, to use a Redis queue, Kombu needs the Python
246
+ package for Redis installed as well::
247
+
248
+ pip install redis
249
+
243
250
To configure a Socket.IO server to connect to a message queue, the
244
251
``client_manager `` argument must be passed in the server creation. The
245
252
following example instructs the server to connect to a Redis service running
246
253
on the same host and on the default port::
247
254
248
- redis = socketio.KombuManager('redis://localhost:6379/ ')
255
+ redis = socketio.KombuManager('redis://')
249
256
sio = socketio.Server(client_manager=redis)
250
257
251
- For a RabbitMQ queue also running on the local server, the configuration is
252
- as follows::
258
+ For a RabbitMQ queue also running on the local server with default
259
+ credentials, the configuration is as follows::
253
260
254
- amqp = socketio.KombuManager('amqp://guest:guest@localhost:5672// ')
261
+ amqp = socketio.KombuManager('amqp://')
255
262
sio = socketio.Server(client_manager=amqp)
256
263
257
264
The arguments passed to the ``KombuManager `` constructor are passed directly
258
265
to Kombu's `Connection object
259
- <http://kombu.readthedocs.org/en/latest/userguide/connections.html> `_.
266
+ <http://kombu.readthedocs.org/en/latest/userguide/connections.html> `_, so
267
+ the Kombu documentation should be consulted for information on how to
268
+ connect to the message queue appropriately.
260
269
261
270
If multiple Sokcet.IO servers are connected to a message queue, they
262
- automatically communicate with each other and manage a combine client list,
271
+ automatically communicate with each other and manage a combined client list,
263
272
without any need for additional configuration. To have a process other than
264
273
the server connect to the queue to emit a message, the same ``KombuManager ``
265
- class can be used. For example::
274
+ class can be used as standalone object . For example::
266
275
267
276
# connect to the redis queue
268
277
redis = socketio.KombuManager('redis://localhost:6379/')
0 commit comments