当前位置: 首页 > 知识库问答 >
问题:

Django通道:应用程序内部异常:消息类型app_consumer没有处理程序。通知信息

益楷
2023-03-14

我正在尝试使用WebSocket向用户发送关于特定事件的通知。我有以下触发websocket方法的接收器模型:

@receiver(pre_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, update_fields=None, **kwargs):
    if update_fields:
        if 'pan_number_verified' in update_fields and instance.pan_number_verified is True:
            notification = Notification.objects.create(message='Your PAN Number has been verified...Head on to '
                                                               'creating a campaign right away.', user=instance)
            channel_layer = get_channel_layer()
            async_to_sync(channel_layer.group_send)("notification_%s" % instance.id, {
                "type": "app_consumer.notification_message",
                "message": str(notification.id)
            })

以下是我的应用程序消费者:

class AppConsumer(WebsocketConsumer):
    def connect(self):
        self.room_name = self.scope['url_route']['kwargs']['user_id']
        self.room_group_name = 'notification_%s' % self.room_name
        async_to_sync(self.channel_layer.group_add)(
            self.room_group_name,
            self.channel_name
        )
        self.accept()

    def disconnect(self, close_code):
        async_to_sync(self.channel_layer.group_discard)(
            self.room_group_name,
            self.channel_name
        )

    def receive(self, text_data):
        text_data_json = json.loads(text_data)
        message = text_data_json['message']

        async_to_sync(self.channel_layer.group_send)(
            self.room_group_name,
            {
                'type': 'app_consumer.notification_message',
                'message': message
            }
        )

    def notification_message(self, event):
        message = event['message']

        self.send(text_data=json.dumps({
            'message': message
        }))

但我得到以下错误消息:

应用程序内部异常:消息类型app\u consumer没有处理程序。通知信息

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/channels/consumer.py”,第59行,调用[receive,self.channel_receive],self。派遣

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/channels/utils.py”,第51行,在等待调度等待调度(结果)

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/asgiref/sync.py”,第244行,在call return wait asyncio中。等待(未来,超时=无)

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/tasks.py”,第414行,等待返回等待fut

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py”,第57行,运行结果=self。fn(*self.args,**self.kwargs)

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/channels/db.py”,第14行,在thread_handler return super()中。线程处理程序(循环,*args,**kwargs)

文件/库/框架/Python.framework/Versions/3.7/lib/python3.7/site-packages/asgiref/sync.py,第277行,thread_handler返回函数(*args,**kwargs)

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/channels/consumer.py”,第107行,在dispatch raise ValueError(“没有消息类型%s”%message[“type”]的处理程序)中

没有消息类型app\u使用者的处理程序。通知信息

共有1个答案

松秦斩
2023-03-14

您在这里发布的是您的通知\u消息处理程序方法的名称。

通道期望它被命名为app_consumer_notification_message

频道取代了 \

(消息类型中的前缀不用于路由,仅用于路由组名称)

 类似资料:
  • 我现在有这个问题,我需要在应用程序在后台时处理消息推送的信息,我的意思是,甚至不点击通知。这意味着这个应用程序:(UIApplication*)应用程序didReceiveRemote teNotify:(NSDicpedia*)userInfo fetchCompletionHandler:(val(^)(UIBackground FetchResult))完成必须在后台调用Handler!这是

  • 版本 维特。x核心:3.5.0 vert. x redis客户端:3.5.0 上下文 2018-06-02 17:40:55.981错误4933---[ntlop-thread-2]io.vertx.redis.impl.重新连接:没有处理程序等待消息:14751915 2018-06-02 17:41:10.937错误4933---[ntloop-thread-2]io。维特斯。雷迪斯。impl

  • 在Android上,toast通知的工作方式与UWP不同。它只是在应用程序的顶部显示一个黑色的弹出消息。在UWP中,从用户角度来看,toast通知与push通知是无法区分的。在UWP中有没有一种标准化的方式,简单地在app内部显示一个几秒后就会消失的快速通知,并且不干扰用户的体验?我的意思是,如果用户没有收到推送通知?

  • 我已经完成了关于如何使用Django(3.1.7版)中的频道和redis制作即时聊天应用程序的youtube教程(github代码链接)。我确实改变了教程中的一些内容,因为他使用的是不同的Django版本。我在使用他的代码时遇到的错误在另一篇stackoverflow文章中有解释。 我已将邮件保存到数据库,并已成功加载页面加载上的10条最新邮件。但是,当我单击“发送”按钮时,我没有看到消息显示在消

  • 我正在使用netty构建一个应用程序。在应用程序中,我需要处理传入和传出的消息。要求是应用程序将发送的任何消息都应由特定的处理程序处理,进入应用程序的任何消息都应由另一个特定的处理程序处理。但是,我希望在两个处理程序之间交换消息,以便能够跟踪发送的消息响应,因为请求消息也将发送到应用程序。 请任何想法hwo实施这样的要求。这个问题听起来可能不相关,但这就是我得到的,我还不是一个网络极客。我读到的关

  • 我正在使用FCM进行通知。FCM在从Firebase数据库创建数据时被触发。我收到了第一条信息。在此之后,不会接收到其他连续的消息。我在本地环境下运行这个。问题是由于以下消息“未配置计费帐户。外部网络无法访问,配额受到严重限制。配置计费帐户以消除这些限制”或任何其他问题造成的。我是否需要进入接收消息的计费计划。在测试环境中工作,这是不转移到计费计划的原因。如果问题与计费计划无关,可以有人指出代码的