5 Commits
v0.0.2 ... dev

Author SHA1 Message Date
5c1f55dd66 Merge branch 'hotfix/v0.0.3' into dev 2011-02-22 12:05:47 +00:00
18c89b1e0f fixed an issue with loading configs 2011-02-22 12:05:26 +00:00
bc69e8970e Version bump to 0.0.3 2011-02-22 12:04:44 +00:00
561a554b3f fixed an issue causing the Failover object to be
lost after the first failover occurs
2011-02-03 15:07:02 +00:00
c9f389ce84 Merge branch 'release/v0.0.2' into dev 2011-02-02 09:39:47 +00:00
4 changed files with 17 additions and 16 deletions

View File

@@ -7,7 +7,7 @@ module AMQP
attr_accessor :last_fail attr_accessor :last_fail
def initialize(hash = {}, last_fail_date = nil) def initialize(hash = {}, last_fail_date = nil)
self.replace(symbolize_keys(defaults.merge(hash))) self.replace(defaults.merge(symbolize_keys(hash)))
self.last_fail = last_fail_date if last_fail_date self.last_fail = last_fail_date if last_fail_date
end end

View File

@@ -29,13 +29,13 @@ module AMQP
# - :selection, not yet implimented. # - :selection, not yet implimented.
# #
def connect_with_failover(opts = nil) def connect_with_failover(opts = nil)
opts = parse_amqp_url_or_opts(opts) opts = parse_amqp_url_or_opts_with_failover(opts)
connect_without_failover(opts) connect_without_failover(opts)
end end
alias :connect_without_failover :connect alias :connect_without_failover :connect
alias :connect :connect_with_failover alias :connect :connect_with_failover
def parse_amqp_url_or_opts(opts = nil) def parse_amqp_url_or_opts_with_failover(opts = nil)
if opts.is_a?(String) && opts.index(',').nil? if opts.is_a?(String) && opts.index(',').nil?
opts = init_failover(opts.split(',')) opts = init_failover(opts.split(','))
elsif opts.is_a?(Array) elsif opts.is_a?(Array)
@@ -56,12 +56,19 @@ module AMQP
end # << self end # << self
def disconnected_with_failover def initialize_with_failover(opts = {})
return failover_switch if @failover @failover = opts.delete(:failover) if opts.has_key?(:failover)
disconnected_without_failover initialize_without_failover(opts)
end end
alias :disconnected_without_failover :disconnected alias :initialize_without_failover :initialize
alias :disconnected :disconnected_with_failover alias :initialize :initialize_with_failover
def unbind_with_failover
@on_disconnect = method(:failover_switch) if @failover
unbind_without_failover
end
alias :unbind_without_failover :unbind
alias :unbind :unbind_with_failover
end # Client end # Client
end # AMQP end # AMQP

View File

@@ -2,6 +2,6 @@
module AMQP module AMQP
class Failover class Failover
VERSION = "0.0.2" VERSION = "0.0.3"
end end
end end

View File

@@ -10,12 +10,6 @@ module AMQP
attr_accessor :settings attr_accessor :settings
attr_accessor :on_disconnect attr_accessor :on_disconnect
def self.extended(base)
if (base.failover = base.settings.delete(:failover))
base.on_disconnect = base.method(:disconnected)
end
end
def failover_switch def failover_switch
if (new_settings = @failover.from(@settings)) if (new_settings = @failover.from(@settings))
log_message = "Could not connect to or lost connection to server #{@settings[:host]}:#{@settings[:port]}. " + log_message = "Could not connect to or lost connection to server #{@settings[:host]}:#{@settings[:port]}. " +
@@ -26,7 +20,7 @@ module AMQP
if @failover.options[:fallback] && @failover.primary == @settings if @failover.options[:fallback] && @failover.primary == @settings
fallback(@failover.primary, @failover.fallback_interval) fallback(@failover.primary, @failover.fallback_interval)
end end
@settings = new_settings @settings = new_settings.merge({:failover => @failover})
reconnect reconnect
else else
raise Error, "Could not connect to server #{@settings[:host]}:#{@settings[:port]}" raise Error, "Could not connect to server #{@settings[:host]}:#{@settings[:port]}"