mirror of
https://github.com/jimeh/amqp-failover.git
synced 2026-02-19 02:46:43 +00:00
added :primary_config failover option
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user