Module: AMQP::FailoverClient
- Includes:
- BasicClient
- Defined in:
- lib/amqp/failover_client.rb
Instance Attribute Summary collapse
-
#failover ⇒ Object
Returns the value of attribute failover.
- #fallback_callback ⇒ Object
-
#fallback_monitor ⇒ Object
readonly
Returns the value of attribute fallback_monitor.
-
#on_disconnect ⇒ Object
Returns the value of attribute on_disconnect.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #clean_exit(msg = nil) ⇒ Object
- #configs ⇒ Object
- #failover_switch ⇒ Object
- #fallback(conf = {}, retry_interval = nil) ⇒ Object
- #logger ⇒ Object
Instance Attribute Details
#failover ⇒ Object
Returns the value of attribute failover.
7 8 9 |
# File 'lib/amqp/failover_client.rb', line 7 def failover @failover end |
#fallback_callback ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/amqp/failover_client.rb', line 51 def fallback_callback #TODO: Figure out a way to artificially trigger EM to disconnect on fallback without channels being closed. @fallback_callback ||= proc { |conf, retry_interval| clean_exit("Primary server (#{conf[:host]}:#{conf[:port]}) is back. " + "Performing clean exit to be relaunched with primary config.") } end |
#fallback_monitor ⇒ Object (readonly)
Returns the value of attribute fallback_monitor.
8 9 10 |
# File 'lib/amqp/failover_client.rb', line 8 def fallback_monitor @fallback_monitor end |
#on_disconnect ⇒ Object
Returns the value of attribute on_disconnect.
11 12 13 |
# File 'lib/amqp/failover_client.rb', line 11 def on_disconnect @on_disconnect end |
#settings ⇒ Object
Returns the value of attribute settings.
10 11 12 |
# File 'lib/amqp/failover_client.rb', line 10 def settings @settings end |
Instance Method Details
#clean_exit(msg = nil) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/amqp/failover_client.rb', line 38 def clean_exit(msg = nil) msg ||= "clean exit" logger.info(msg) logger.error(msg) Process.exit end |
#configs ⇒ Object
34 35 36 |
# File 'lib/amqp/failover_client.rb', line 34 def configs @failover.configs if @failover end |
#failover_switch ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/amqp/failover_client.rb', line 13 def failover_switch if (new_settings = @failover.from(@settings)) = "Could not connect to or lost connection to server #{@settings[:host]}:#{@settings[:port]}. " + "Attempting connection to: #{new_settings[:host]}:#{new_settings[:port]}" logger.error() logger.info() if @failover.[:fallback] && @failover.primary == @settings fallback(@failover.primary, @failover.fallback_interval) end @settings = new_settings.merge({:failover => @failover}) reconnect else raise Error, "Could not connect to server #{@settings[:host]}:#{@settings[:port]}" end end |
#fallback(conf = {}, retry_interval = nil) ⇒ Object
45 46 47 48 49 |
# File 'lib/amqp/failover_client.rb', line 45 def fallback(conf = {}, retry_interval = nil) @fallback_monitor = Failover::ServerDiscovery.monitor(conf, retry_interval) do fallback_callback.call(conf, retry_interval) end end |