Module: AMQ::Client::Settings
- Defined in:
- lib/qrack/amq-client-url.rb
Overview
Class Method Summary collapse
- .client_properties ⇒ Object
-
.configure(settings = nil) ⇒ Hash
Merges given configuration parameters with defaults and returns the result.
-
.default ⇒ Object
Default connection settings used by AMQ clients.
-
.parse_amqp_url(connection_string) ⇒ Hash
Parses AMQP connection URI and returns its components as a hash.
Class Method Details
.client_properties ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/qrack/amq-client-url.rb', line 57 def self.client_properties @client_properties ||= { :platform => ::RUBY_DESCRIPTION, :product => "AMQ Client", :information => "http://github.com/ruby-amqp/amq-client", :version => AMQ::Client::VERSION } end |
.configure(settings = nil) ⇒ Hash
Merges given configuration parameters with defaults and returns the result.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/qrack/amq-client-url.rb', line 84 def self.configure(settings = nil) case settings when Hash then if username = settings.delete(:username) settings[:user] ||= username end if password = settings.delete(:password) settings[:pass] ||= password end self.default.merge(settings) when String then settings = self.parse_amqp_url(settings) self.default.merge(settings) when NilClass then self.default end end |
.default ⇒ Object
Default connection settings used by AMQ clients
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/qrack/amq-client-url.rb', line 28 def self.default @default ||= { # server :host => "127.0.0.1", :port => AMQ::Protocol::DEFAULT_PORT, # login :user => "guest", :pass => "guest", :vhost => "/", # connection timeout :timeout => nil, # logging :logging => false, # ssl :ssl => false, # broker # if you want to load broker-specific extensions :broker => nil, :frame_max => 131072 } end |
.parse_amqp_url(connection_string) ⇒ Hash
Parses AMQP connection URI and returns its components as a hash.
vhost naming schemes
It is convenient to be able to specify the AMQP connection parameters as a URI string, and various “amqp” URI schemes exist. Unfortunately, there is no standard for these URIs, so while the schemes share the basic idea, they differ in some details. This implementation aims to encourage URIs that work as widely as possible.
The URI scheme should be “amqp”, or “amqps” if SSL is required.
The host, port, username and password are represented in the authority component of the URI in the same way as in http URIs.
The vhost is obtained from the first segment of the path, with the leading slash removed. The path should contain only a single segment (i.e, the only slash in it should be the leading one). If the vhost is to include slashes or other reserved URI characters, these should be percent-escaped.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/qrack/amq-client-url.rb', line 144 def self.parse_amqp_url(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 |