lib/splash/transports/rabbitmq.rb in prometheus-splash-0.4.4 vs lib/splash/transports/rabbitmq.rb in prometheus-splash-0.4.5
- old
+ new
@@ -9,21 +9,20 @@
def_delegators :@queue, :subscribe
def initialize(options = {})
@config = get_config.transports
- @url = "amqp://"
+
host = @config[:rabbitmq][:host]
port = @config[:rabbitmq][:port]
- vhost = @config[:rabbitmq][:vhost]
- if @config[:rabbitmq][:user] and @config[:rabbitmq][:passwd] then
- creds = "#{@config[:rabbitmq][:user]}:#{@config[:rabbitmq][:passwd]}@"
- @url << creds
- end
- @url << "#{host}:#{port}#{vhost}"
+ vhost = (@config[:rabbitmq][:vhost])? @config[:rabbitmq][:vhost] : '/'
+ passwd = (@config[:rabbitmq][:passwd])? @config[:rabbitmq][:passwd] : 'guest'
+ user = (@config[:rabbitmq][:user])? @config[:rabbitmq][:user] : 'guest'
+ conf = { :host => host, :vhost => vhost, :user => user, :password => passwd, :port => port.to_i}
+
begin
- @connection = Bunny.new @url
+ @connection = Bunny.new conf
@connection.start
@channel = @connection.create_channel
@queue = @channel.queue options[:queue]
rescue Bunny::Exception
return { :case => :service_dependence_missing, :more => "RabbitMQ Transport not available." }
@@ -39,24 +38,22 @@
include Splash::Transports
include Splash::Loggers
def initialize
@config = get_config.transports
- @url = "amqp://"
host = @config[:rabbitmq][:host]
port = @config[:rabbitmq][:port]
- vhost = @config[:rabbitmq][:vhost]
- if @config[:rabbitmq][:user] and @config[:rabbitmq][:passwd] then
- creds = "#{@config[:rabbitmq][:user]}:#{@config[:rabbitmq][:passwd]}@"
- @url << creds
- end
- @url << "#{host}:#{port}#{vhost}"
+ vhost = (@config[:rabbitmq][:vhost])? @config[:rabbitmq][:vhost] : '/'
+ passwd = (@config[:rabbitmq][:passwd])? @config[:rabbitmq][:passwd] : 'guest'
+ user = (@config[:rabbitmq][:user])? @config[:rabbitmq][:user] : 'guest'
+ conf = { :host => host, :vhost => vhost, :user => user, :password => passwd, :port => port.to_i}
+
begin
- @connection = Bunny.new @url
+ @connection = Bunny.new conf
@connection.start
@channel = @connection.create_channel
rescue Bunny::Exception
- return { :case => :service_dependence_missing, :more => "RabbitMQ Transport not available." }
+ splash_exit case: :service_dependence_missing, more: "RabbitMQ Transport not available."
end
end
def purge(options)