amqp-failover 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module AMQP
7
7
  attr_accessor :last_fail
8
8
 
9
9
  def initialize(hash = {}, last_fail_date = nil)
10
- self.replace(symbolize_keys(defaults.merge(hash)))
10
+ self.replace(defaults.merge(symbolize_keys(hash)))
11
11
  self.last_fail = last_fail_date if last_fail_date
12
12
  end
13
13
 
@@ -29,13 +29,13 @@ module AMQP
29
29
  # - :selection, not yet implimented.
30
30
  #
31
31
  def connect_with_failover(opts = nil)
32
- opts = parse_amqp_url_or_opts(opts)
32
+ opts = parse_amqp_url_or_opts_with_failover(opts)
33
33
  connect_without_failover(opts)
34
34
  end
35
35
  alias :connect_without_failover :connect
36
36
  alias :connect :connect_with_failover
37
37
 
38
- def parse_amqp_url_or_opts(opts = nil)
38
+ def parse_amqp_url_or_opts_with_failover(opts = nil)
39
39
  if opts.is_a?(String) && opts.index(',').nil?
40
40
  opts = init_failover(opts.split(','))
41
41
  elsif opts.is_a?(Array)
@@ -56,12 +56,19 @@ module AMQP
56
56
 
57
57
  end # << self
58
58
 
59
- def disconnected_with_failover
60
- return failover_switch if @failover
61
- disconnected_without_failover
59
+ def initialize_with_failover(opts = {})
60
+ @failover = opts.delete(:failover) if opts.has_key?(:failover)
61
+ initialize_without_failover(opts)
62
62
  end
63
- alias :disconnected_without_failover :disconnected
64
- alias :disconnected :disconnected_with_failover
63
+ alias :initialize_without_failover :initialize
64
+ alias :initialize :initialize_with_failover
65
+
66
+ def unbind_with_failover
67
+ @on_disconnect = method(:failover_switch) if @failover
68
+ unbind_without_failover
69
+ end
70
+ alias :unbind_without_failover :unbind
71
+ alias :unbind :unbind_with_failover
65
72
 
66
73
  end # Client
67
74
  end # AMQP
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AMQP
4
4
  class Failover
5
- VERSION = "0.0.2"
5
+ VERSION = "0.0.3"
6
6
  end
7
7
  end
@@ -10,12 +10,6 @@ module AMQP
10
10
  attr_accessor :settings
11
11
  attr_accessor :on_disconnect
12
12
 
13
- def self.extended(base)
14
- if (base.failover = base.settings.delete(:failover))
15
- base.on_disconnect = base.method(:disconnected)
16
- end
17
- end
18
-
19
13
  def failover_switch
20
14
  if (new_settings = @failover.from(@settings))
21
15
  log_message = "Could not connect to or lost connection to server #{@settings[:host]}:#{@settings[:port]}. " +
@@ -26,7 +20,7 @@ module AMQP
26
20
  if @failover.options[:fallback] && @failover.primary == @settings
27
21
  fallback(@failover.primary, @failover.fallback_interval)
28
22
  end
29
- @settings = new_settings
23
+ @settings = new_settings.merge({:failover => @failover})
30
24
  reconnect
31
25
  else
32
26
  raise Error, "Could not connect to server #{@settings[:host]}:#{@settings[:port]}"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp-failover
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Myhrberg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-02 00:00:00 +00:00
18
+ date: 2011-02-22 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency