diff --git a/lib/amqp/failover.rb b/lib/amqp/failover.rb index 8719a74..1c1130d 100644 --- a/lib/amqp/failover.rb +++ b/lib/amqp/failover.rb @@ -22,6 +22,7 @@ module AMQP def initialize(confs = nil, opts = {}) @configs = Failover::Configurations.new(confs) @options = default_options.merge(opts) + @configs.primary_ref = @options[:primary_config] end class << self @@ -33,9 +34,10 @@ module AMQP end def default_options - { :retry_timeout => 1, - :selection => :sequential, #TODO: Impliment next server selection algorithm - :fallback => false, #TODO: Enable by default once a sane implimentation is figured out + { :primary_config => 0, + :retry_timeout => 1, + :selection => :sequential, #TODO: Implement next server selection algorithm + :fallback => false, #TODO: Enable by default once a sane implementation is figured out :fallback_interval => 10 } end diff --git a/lib/amqp/failover/ext/amqp/client.rb b/lib/amqp/failover/ext/amqp/client.rb index e3a0092..804fb99 100644 --- a/lib/amqp/failover/ext/amqp/client.rb +++ b/lib/amqp/failover/ext/amqp/client.rb @@ -22,6 +22,8 @@ module AMQP # # Available failover options are: # - :retry_timeout, time to wait before retrying a specific AMQP config after failure. + # - :primary_config, specify which of the supplied configurations is it the primary one. The default + # value is 0, the first item in the config array. Use 1 for the second and so on. # - :fallback, check for the return of the primary server, and fallback to it if and when it returns. # - :fallback_interval, seconds between each check for original server if :fallback is true. # - :selection, not yet implimented. diff --git a/spec/integration/failover_spec.rb b/spec/integration/failover_spec.rb index 595eeec..4ccb8dd 100644 --- a/spec/integration/failover_spec.rb +++ b/spec/integration/failover_spec.rb @@ -6,7 +6,7 @@ require 'amqp/server' require 'server_helper' require 'logger_helper' -describe "Full Failover support of AMQP gem" do +describe "Failover support loaded into AMQP gem" do before(:each) do @flog = LoggerHelper.new @@ -120,4 +120,22 @@ describe "Full Failover support of AMQP gem" do end end + it "should abide to :primary_config option" do + port1 = 75672 + port2 = 65672 + EM.run { + serv = start_server(port1) + EM.add_timer(0.1) { + conn = AMQP.connect({:hosts => [{:port => port1}, {:port => port2}], :primary_config => 1}) + conn.failover.primary[:port].should == port2 + conn.settings[:port].should == port2 + conn.settings.should == conn.failover.primary + EM.add_timer(0.1) { + conn.should be_connected + EM.stop + } + } + } + end + end