diff --git a/config/anycable.yml b/config/anycable.yml index 7fd6e98..f8d54a0 100644 --- a/config/anycable.yml +++ b/config/anycable.yml @@ -1,40 +1,30 @@ -# gRPC server settings, anycable grpc server will listen -# websocket server at given host:port, usually Anycable server runs locally to ws server -# MUST BE in sync with ws-server setting -rpc=0.0.0.0:50051 -# rpc_host: "localhost:50051" - -# redis url -# MUST BE in sync with ws-server setting -redis=redis://localhost:6379/5 -# REM: Redis PubSub system doesn't use the database part of URI -# redis_url: "redis://localhost:6379/5" - -# redis_sentinels: -# - { host: 'localhost', port: 26379 } -# - { host: 'redis-1-2', port: 26379 } -# - { host: 'redis-1-3', port: 26379 } - -# anycable use single pubsub queue, this is queue name -# MUST BE in sync with ws-server setting -redis_channel=__anycable__ -# redis_channel: "__anycable__", - -#---------- ENVIRONMENT VARIABLES ---------- -# since Anycable config based on anyway_config (https://github.com/palkan/anyway_config), all Anycable settings, -# can be set or overridden through corresponding Environment variable. -# Ex: rpc_host is overridden by ANYCABLE_RPC_HOST, redis_url by ANYCABLE_REDIS_URL e.t.c Look in anyway_config for more details - +# This file contains per-environment settings for AnyCable. +# +# Since AnyCable config is based on anyway_config (https://github.com/palkan/anyway_config), all AnyCable settings +# can be set or overridden through the corresponding environment variables. +# E.g., `rpc_host` is overridden by ANYCABLE_RPC_HOST, `debug` by ANYCABLE_DEBUG etc. +# +# Note that AnyCable recognizes REDIS_URL env variable for Redis pub/sub adapter. If you want to +# use another Redis instance for AnyCable, provide ANYCABLE_REDIS_URL variable. +# +# Read more about AnyCable configuration here: https://docs.anycable.io/#/ruby/configuration +# default: &default - rpc_host: <%= ENV.fetch("ANYCABLE_RPC_HOST", "localhost:50051") %> + # Turn on/off access logs ("Started..." and "Finished...") + access_logs_disabled: false + # This is the host and the port to run AnyCable RPC server on. + # You must configure your WebSocket server to connect to it, e.g.: + # $ anycable-go --rpc-host=":50051" + rpc_host: "127.0.0.1:50051" + # Whether to enable gRPC level logging or not log_grpc: false - log_file: nil - debug: false # Shortcut to enable GRPC logging and debug level - log_level: info + # Use the same channel name for WebSocket server, e.g.: + # $ anycable-go --redis-channel="__anycable__" redis_channel: "__anycable__" - redis_sentinels: [] development: <<: *default - redis_url: <%= ENV.fetch("REDIS_URL", "redis://localhost:6379/2") %> + redis_url: "redis://localhost:6379/1" production: <<: *default - redis_url: <%= ENV.fetch("REDIS_URL", "redis://localhost:6379/1") %> diff --git a/config/cable.yml b/config/cable.yml index ed9318b..8a279ad 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,4 +1,6 @@ -# List of available adapters: async, any_cable +# Make it possible to switch adapters by passing the CABLE_ADAPTER env variable. +# For example, you can use it fallback to the standard Action Cable in staging/review +# environments (by setting `CABLE_ADAPTER=redis`). development: adapter: <%= ENV.fetch("CABLE_ADAPTER", "any_cable") %> @@ -7,4 +9,3 @@ test: production: adapter: <%= ENV.fetch("CABLE_ADAPTER", "any_cable") %> - channel_prefix: evil_chat_production diff --git a/config/environments/development.rb b/config/environments/development.rb index fac6855..9407425 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -54,6 +54,6 @@ # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker - # Specify AnyCable WebSocket server URL to make JS client connect to it + # Specify AnyCable WebSocket server URL to use by JS client config.action_cable.url = ENV.fetch("CABLE_URL", "ws://localhost:3334/cable").presence end diff --git a/config/environments/production.rb b/config/environments/production.rb index 8c653ba..d0bdb2d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -37,7 +37,7 @@ # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' - # Specify AnyCable WebSocket server URL to make JS client connect to it + # Specify AnyCable WebSocket server URL to use by JS client config.action_cable.url = ENV["CABLE_URL"].presence # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] diff --git a/docker-compose.yml b/docker-compose.yml index 753fa54..ee98a08 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,7 +34,9 @@ services: EDITOR: vim RAILS_ENV: ${RAILS_ENV:-development} DATABASE_URL: postgres://postgres:postgres@postgres:5432 - REDIS_URL: redis://redis:6379/ + REDIS_URL: redis://redis:6379/0 + ANYCABLE_REDIS_URL: redis://redis:6379/0 + ANYCABLE_RPC_HOST: 0.0.0.0:50051 WEBPACKER_DEV_SERVER_HOST: webpacker DISABLE_SPRING: 1 depends_on: @@ -79,7 +81,7 @@ services: - '3334:3334' environment: PORT: 3334 - REDIS_URL: redis://redis:6379/0 + ANYCABLE_REDIS_URL: redis://redis:6379/0 ANYCABLE_RPC_HOST: anycable-rpc:50051 depends_on: - anycable-rpc