Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionCable Not Receiving Data

I created the following using ActionCable but not able to receive any data that is being broadcasted.

Comments Channel:

class CommentsChannel < ApplicationCable::Channel
  def subscribed
    comment = Comment.find(params[:id])
    stream_for comment
  end
end

JavaScript:

var cable = Cable.createConsumer('ws://localhost:3000/cable');

var subscription = cable.subscriptions.create({
  channel: "CommentsChannel",
  id: 1
},{
  received: function(data) {
    console.log("Received data")
  }
});

It connects fine and I can see the following in the logs:

CommentsChannel is streaming from comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x

I then broadcast to that stream:

ActionCable.server.broadcast "comments:Z2lkOi8vdHJhZGUtc2hvdy9FdmVudC8x", { test: '123' }

The issue is that the received function is never called. Am I doing something wrong?

Note: I'm using the actioncable npm package to connect from a BackboneJS application.

like image 301
Artem Kalinchuk Avatar asked Mar 28 '16 16:03

Artem Kalinchuk


1 Answers

Changing the cable adapter from async to redis in config/cable.yml fixed it for me.

Update

As Erem pointed out below, the server and console are isolated processes so you need to use a centralized queue manager.

like image 98
Artem Kalinchuk Avatar answered Nov 19 '22 00:11

Artem Kalinchuk