Django渠道自定义路由不起作用

时间:2018-06-03 18:44:11

标签: django django-channels

我试图添加自定义路由和消费者,但在发送请求时它什么都不做。似乎它无法看到消费者。

Routing.py

channel_routing = [
    route("websocket.connect", ws_add,
          path=r"^/some-data/(?P<table_id>[a-zA-Z0-9_]+)/$"),
    route("websocket.receive", ws_message,
          path=r"^/some-data/(?P<table_id>[a-zA-Z0-9_]+)/$"),
    route("websocket.disconnect", ws_disconnect,
          path=r"^/some-data/(?P<table_id>[a-zA-Z0-9_]+)/$"),
    #THIS ONE DOESN'T WORK
    route("queue", msg_consumer, path=r"^/test/$"),
]

consumers.py

def msg_consumer(message):
    print('testing')
    # And i'm adding it to Group
    Group("queue-%s" % room).send({
        "text": message.content['message'],
    })

我的js

socket = new WebSocket("ws://" + window.location.host + '/test/');
socket.onopen = function() {
socket.send(JSON.stringify({
      text: "test"
}));
}
// Call onopen directly if socket is already open
if (socket.readyState == WebSocket.OPEN) socket.onopen();

第一批消费者工作正常,但最后消费者没有。

0 个答案:

没有答案