ActionCable频道未在Rails中广播消息时被调用

问题描述

首先,ActionCable功能非常新。我在这里一直在关注该教程:https://www.driftingruby.com/episodes/push-notifications-with-actioncable

创建了一个名为web_notifications_channel和web_notifications_channel.rb的频道:

class WebNotificationsChannel < ApplicationCable::Channel
  def subscribed
    stream_from "web_notifications_channel"
  end

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end
end

web_notifications_channel.js:

import consumer from "./consumer"

consumer.subscriptions.create("WebNotificationsChannel",{
  connected() {
    // Called when the subscription is ready for use on the server
  },disconnected() {
    // Called when the subscription has been terminated by the server
  },received(data) {
    // Called when there's incoming data on the websocket for this channel
    console.log(`wtf`)
    
  }
});

控制台中没有任何显示

已将适配器设置更改为cable.yml中的redis,以便从控制台请求:

development:
  adapter: redis

test:
  adapter: test

production:
  adapter: redis
  url: <%= ENV.fetch("REdis_URL") { "redis://localhost:6379/1" } %>
  channel_prefix: community_rails_production

运行控制台命令:

ActionCable.server.broadcast 'web_notifications_channel','You have visited the welcome page.'

我得到的答复是:

broadcasting to web_notifications_channel: "You have visited the welcome page."
 => 0 

但是我的received方法从未被调用!我在这里疯了,因为无法理解发生了什么!我检查了一些类似的问题,但没有一个我有帮助。

PS:我已经添加了redis gem,并从控制台开始了redis

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...