FEATURE: Allow running message_bus in a different redis instance (#7616)

Adds `DISCOURSE_MESSAGE_BUS_REDIS_ENABLED` env var, that when set
to true, will allow Discourse to connect to a different redis
instance for MessageBus needs.

When enabled you can configure the same env vars user for redis,
but prefixed by `MESSAGE_BUS`, eg:

`DISCOURSE_MESSAGE_BUS_REDIS_HOST`
This commit is contained in:
Rafael dos Santos Silva 2019-05-28 02:52:43 -03:00 committed by Sam
parent 9a232e1a0a
commit 315a38e0e3
3 changed files with 49 additions and 1 deletions

View File

@ -136,6 +136,7 @@ class GlobalSetting
# For testing purposes # For testing purposes
def self.reset_redis_config! def self.reset_redis_config!
@config = nil @config = nil
@message_bus_config = nil
end end
def self.redis_config def self.redis_config
@ -160,6 +161,29 @@ class GlobalSetting
end end
end end
def self.message_bus_redis_config
return redis_config unless message_bus_redis_enabled
@message_bus_config ||=
begin
c = {}
c[:host] = message_bus_redis_host if message_bus_redis_host
c[:port] = message_bus_redis_port if message_bus_redis_port
if message_bus_redis_slave_host && message_bus_redis_slave_port
c[:slave_host] = message_bus_redis_slave_host
c[:slave_port] = message_bus_redis_slave_port
c[:connector] = DiscourseRedis::Connector
end
c[:password] = message_bus_redis_password if message_bus_redis_password.present?
c[:db] = message_bus_redis_db if message_bus_redis_db != 0
c[:db] = 1 if Rails.env == "test"
c[:id] = nil if message_bus_redis_skip_client_commands
c.freeze
end
end
def self.add_default(name, default) def self.add_default(name, default)
unless self.respond_to? name unless self.respond_to? name
define_singleton_method(name) do define_singleton_method(name) do

View File

@ -120,6 +120,30 @@ redis_password =
# skip configuring client id for cloud providers who support no client commands # skip configuring client id for cloud providers who support no client commands
redis_skip_client_commands = false redis_skip_client_commands = false
# message bus redis server switch
message_bus_redis_enabled = false
# message bus redis server address
message_bus_redis_host = localhost
# message bus redis server port
message_bus_redis_port = 6379
# message bus redis slave server address
message_bus_redis_slave_host =
# message bus redis slave server port
message_bus_redis_slave_port = 6379
# message bus redis database
message_bus_redis_db = 0
# message bus redis password
message_bus_redis_password =
# skip configuring client id for cloud providers who support no client commands
message_bus_redis_skip_client_commands = false
# enable Cross-origin Resource Sharing (CORS) directly at the application level # enable Cross-origin Resource Sharing (CORS) directly at the application level
enable_cors = false enable_cors = false
cors_origin = '' cors_origin = ''

View File

@ -95,7 +95,7 @@ MessageBus.on_disconnect do |site_id|
end end
# Point at our redis # Point at our redis
MessageBus.redis_config = GlobalSetting.redis_config MessageBus.redis_config = GlobalSetting.message_bus_redis_config
MessageBus.reliable_pub_sub.max_backlog_size = GlobalSetting.message_bus_max_backlog_size MessageBus.reliable_pub_sub.max_backlog_size = GlobalSetting.message_bus_max_backlog_size
MessageBus.long_polling_enabled = SiteSetting.enable_long_polling MessageBus.long_polling_enabled = SiteSetting.enable_long_polling