Django通道后台工作人员使用InMemoryChannel Layer未拾取消息

Django通道后台工作人员使用InMemoryChannel Layer未拾取消息,django,django-channels,Django,Django Channels,我正在尝试实现一个后台工作程序,它最终将读取一个日志文件并通过websocket将其发送回客户端。当前该消息未传递给工作进程 我正在使用InMemoryChannelLayer,这是使用默认层还是必须使用Redis #consumer channel_layer = get_channel_layer() class LogFileConsumer(AsyncConsumer): async def read_file(self, message): print(me

我正在尝试实现一个后台工作程序,它最终将读取一个日志文件并通过websocket将其发送回客户端。当前该消息未传递给工作进程

我正在使用InMemoryChannelLayer,这是使用默认层还是必须使用Redis

#consumer
channel_layer = get_channel_layer()

class LogFileConsumer(AsyncConsumer):

    async def read_file(self, message):
        print(message)
        await asyncio.sleep(2)
        
class LogConsumer(AsyncWebsocketConsumer):
# group_send code, not shown, is routed back fine to the client browser
    async def connect(self):
        await self.accept()
        await channel_layer.send('read-file',{
            'type': 'read.file',
            'id':'start',
        })
然后,我运行worker,如下所示:

$ python manage.py runworker read-file
Running worker for channels ['read-file']
我希望看到控制台上打印回一条消息,但什么也没有返回

其余的代码,通过websocket从浏览器接收消息,然后使用group_send将消息发送回客户端,都可以正常工作。我肯定某个地方有个愚蠢的错误,就是看不出来


感谢

内存层仅用于测试etc(例如在通道repo上运行单元测试)

您应该始终使用Redis(或其他,如RabbitMQ)层

$ python manage.py runworker read-file
Running worker for channels ['read-file']