Shreyas S

Joined

860 Experience
1 Lesson Completed
1 Question Solved

Activity

I further inspected redis via redis-cli monitor and found out that ActionCable.server.broadcast publishes messages to local redis even though the remote redis url is mentioned in cable.yml

That is kinda weird. But I got it to work by directly creating a redis instance and publishing it to the channel

$redis = Redis.new(host: "#{ENV.fetch("REDIS_HOST")}", port: "#{ENV.fetch("REDIS_PORT")}", password: "#{ENV.fetch("REDIS_PASS")}")
$redis.publish "channel", { data: data }

Understanding how Action Cable uses Redis under the hood helped a lot. Many thanks to Chris for making videos on Action Cable!

I'm working on a rails app which uses action cable to notify users on the frontend when an event gets triggered.

I'm using a remote redis instance to work with action cable. So this is my dev env setup in cable.yml

development:
  adapter: redis
  url: redis://:<%= ENV.fetch("REDIS_PASS") %>@<%= ENV.fetch("REDIS_HOST") %>:<%= ENV.fetch("REDIS_PORT") %>/1

I'm able to create a websocket connection successfully without any problems.

But when I broadcast from rails console like this
ActionCable.server.broadcast "channel", { data: data }
It returns 0, which means the message isn't getting broadcasted.

In my cable.yml, if I change my url to local redis url
redis://localhost:6379
I am able to broadcast from rails console successfully and it returns 1

I'm not sure why it works with locally but not with remote redis server. How do I find what the problem is and fix this?

Posted in Realtime Notifications with ActionCable Discussion

Can you please share the link if you found it?