lib/amq/client/settings.rb in amq-client-1.0.4 vs lib/amq/client/settings.rb in amq-client-1.1.0.pre1

- old
+ new

@@ -1,9 +1,9 @@ # encoding: utf-8 require "amq/protocol/client" # TODO: "amq/protocol/constants" -require "amq/uri" +require "uri" module AMQ module Client # @see AMQ::Client::Settings.configure module Settings @@ -134,10 +134,26 @@ # @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_amqp_url(connection_string) - AMQ::URI.parse(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 || AMQ::Client::Settings::AMQP_PORTS[uri.scheme] + opts[:ssl] = uri.scheme == AMQ::Client::Settings::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 end end end end