added :primary_config failover option

This commit is contained in:
2011-02-01 14:06:52 +00:00
parent 80369c9418
commit 575df3690e
3 changed files with 26 additions and 4 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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