AnyCable allows you to use any WebSocket server (written in any language) as a replacement for built-in Rails ActionCable server.
With AnyCable you can use channels, client-side JS, broadcasting - (almost) all that you can do with ActionCable.
You can even use ActionCable in development and not be afraid of compatibility issues.
For usage outside Rails see AnyCable repository.
- Ruby ~> 2.3;
- Rails ~> 5.0;
How It Works?
Compatible WebSocket servers
Add Anycable to your application's Gemfile:
gem 'anycable-rails' # or if you want to use built-in Action Cable server # for test and development (which is possible and recommended) gem 'anycable-rails', group: :production
NOTE: if you want to require
anycable-rails manually (i.e. with
require: false in your
make sure that it's loaded prior to
Rails.application.initialize! call (see
And then run:
rails generate anycable
to create executable.
config/anycable.ymlif you want to override defaults (see below):
production: # gRPC server host rpc_host: "localhost:50051" # Redis URL (for broadcasting) redis_url: "redis://localhost:6379/2" # Redis channel name redis_channel: "anycable"
Anycable uses anyway_config, thus it is also possible to set configuration variables through
secrets.yml or environment vars.
Run Anycable RPC server:
and also run AnyCable-compatible WebSocket server, e.g. anycable-go:
Don't forget to set cable url in your environment:
# For development it's likely the localhost # config/environments/development.rb config.action_cable.url = "ws://localhost:3334/cable" # For production it's likely to have a sub-domain and secure connection # config/environments/production.rb config.action_cable.url = "wss://ws.example.com/cable"
Anycable.logger by default, thus Anycable debug mode (
ANYCABLE_DEBUG=1) is not available, you should configure Rails logger instead, e.g.:
# in Rails configuration if Anycable.config.debug config.logger = Logger.new(STDOUT) config.log_level = :debug end
You can also turn on access logging (
Started <request data> /
Finished <request data>):
# in anycable.yml production: access_logs_disabled: false
This is the compatibility list for the AnyCable gem, not for AnyCable servers (which may not support some of the features yet).
|Connection Request (cookies, params)||+|
|Subscribe to channels||+|
|Unsubscribe from channels||+|
|Subscription Instance Variables||-|
|Performing Channel Actions||+|
|Custom stream callbacks||-|
|Disconnect remote clients||-|
Bug reports and pull requests are welcome on GitHub at https://github.com/anycable/anycable-rails.
The gem is available as open source under the terms of the MIT License.