lib/amqp/client.rb in amqp-0.8.0.rc13 vs lib/amqp/client.rb in amqp-0.8.0.rc14

- old
+ new

@@ -1,8 +1,8 @@ # encoding: utf-8 -require "uri" +require 'amq/client/settings' require "amqp/session" module AMQP # @private module Client @@ -31,15 +31,20 @@ connection_string_or_options else Hash.new end - if block - AMQP.client.connect(opts.merge(options), &block) - else - AMQP.client.connect(opts.merge(options)) + connection = if block + AMQP.client.connect(opts.merge(options), &block) + else + AMQP.client.connect(opts.merge(options)) + end + + connection.on_open do + require "amqp/extensions/rabbitmq" if connection.broker.rabbitmq? end + connection end # Parses AMQP connection URI and returns its components as a hash. # # h2. vhost naming schemes @@ -78,26 +83,10 @@ # @raise [ArgumentError] When connection URI schema is not amqp or amqps, or the path contains multiple segments # # @see http://bit.ly/ks8MXK Connecting to The Broker documentation guide # @api public def self.parse_connection_uri(connection_string) - uri = URI.parse(connection_string) - raise ArgumentError.new("Connection URI must use amqp or amqps schema (example: amqp://bus.megacorp.internal:5766), learn more at http://bit.ly/ks8MXK") unless %w{amqp amqps}.include?(uri.scheme) - - opts = {} - - opts[:scheme] = uri.scheme - opts[:user] = URI.unescape(uri.user) if uri.user - opts[:pass] = URI.unescape(uri.password) if uri.password - opts[:host] = uri.host if uri.host - opts[:port] = uri.port || AMQP_PORTS[uri.scheme] - opts[:ssl] = uri.scheme == AMQPS - if uri.path =~ %r{^/(.*)} - raise ArgumentError.new("#{uri} has multiple-segment path; please percent-encode any slashes in the vhost name (e.g. /production => %2Fproduction). Learn more at http://bit.ly/amqp-gem-and-connection-uris") if $1.index('/') - opts[:vhost] = URI.unescape($1) - end - - opts + AMQ::Client::Settings.parse_amqp_url(connection_string) end end # Client