如何在Tornado IO Loop中运行Celery worker?

时间:2016-02-05 07:21:59

标签: io celery tornado

我有一个Tornado Websocket服务器,它维护与多个websockets(移动设备)的开放连接。现在有一个包含所有消息的队列,需要将其发送到所有连接的websockets。所以我正在尝试编写这个程序,它消耗来自队列的消息并将它们发送到所有打开的连接。到目前为止,这是我的代码:

open_websocket_connections = []

class GetDataSocketHandler(tornado.websocket.WebSocketHandler):

    def check_origin(self, origin):
        return True

    def open(self):
        open_websocket_connections.appped(self)
        logging.info('connection opened')

    def on_close(self):
        open_websocket_connections.remove(self)
        logging.info('connection closed')


def on_message(message, *args, **kwargs):
    for connection in open_websocket_connections:
        connection.write_message(message)

# missing celery code part
def consume_messages(queue, *args, **kwargs):
    # connect to `queue`
    # call `on_message`

# missing ioloop code
# run the `consume_messages` in an ioloop

那么如何填写缺失的部分?

0 个答案:

没有答案