Class Index [+]

Quicksearch

AMQ::Client::Settings

@see AMQ::Client::Settings.configure

Constants

AMQP_PORTS

@private

AMQPS

@private

Public Class Methods

client_properties() click to toggle source
    # File lib/amq/client/settings.rb, line 48
48:       def self.client_properties
49:         @client_properties ||= {
50:           :platform    => ::RUBY_DESCRIPTION,
51:           :product     => "AMQ Client",
52:           :information => "http://github.com/ruby-amqp/amq-client",
53:           :version     => AMQ::Client::VERSION
54:         }
55:       end
configure(settings = nil) click to toggle source

Merges given configuration parameters with defaults and returns the result.

@param [Hash] Configuration parameters to use.

@option settings [String] :host (“127.0.0.1“) Hostname AMQ broker runs on. @option settings [String] :port (5672) Port AMQ broker listens on. @option settings [String] :vhost (“/”) Virtual host to use. @option settings [String] :user (“guest”) Username to use for authentication. @option settings [String] :pass (“guest”) Password to use for authentication. @option settings [String] :ssl (false) Should be use TLS (SSL) for connection? @option settings [String] :timeout (nil) Connection timeout. @option settings [String] :logging (false) Turns logging on or off. @option settings [String] :broker (nil) Broker name (use if you intend to use broker-specific features). @option settings [Fixnum] :frame_max (131072) Maximum frame size to use. If broker cannot support frames this large, broker’s maximum value will be used instead.

@return [Hash] Merged configuration parameters.

    # File lib/amq/client/settings.rb, line 75
75:       def self.configure(settings = nil)
76:         case settings
77:         when Hash then
78:           if username = settings.delete(:username)
79:             settings[:user] ||= username
80:           end
81: 
82:           if password = settings.delete(:password)
83:             settings[:pass] ||= password
84:           end
85: 
86: 
87:           self.default.merge(settings)
88:         when String then
89:           settings = self.parse_amqp_url(settings)
90:           self.default.merge(settings)
91:         when NilClass then
92:           self.default
93:         end
94:       end
default() click to toggle source

Default connection settings used by AMQ clients

@see AMQ::Client::Settings.configure

    # File lib/amq/client/settings.rb, line 19
19:       def self.default
20:         @default ||= {
21:           # server
22:           :host  => "127.0.0.1",
23:           :port  => AMQ::Protocol::DEFAULT_PORT,
24: 
25:           # login
26:           :user  => "guest",
27:           :pass  => "guest",
28:           :vhost => "/",
29: 
30:           # connection timeout
31:           :timeout => nil,
32: 
33:           # logging
34:           :logging => false,
35: 
36:           # ssl
37:           :ssl => false,
38: 
39:           # broker
40:           # if you want to load broker-specific extensions
41:           :broker => nil,
42: 
43:           :frame_max => 131072
44:         }
45:       end
parse_amqp_url(connection_string) click to toggle source

Parses AMQP connection URI and returns its components as a hash.

h2. 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.

@example How vhost is parsed

  AMQ::Client::Settings.parse_amqp_url("amqp://dev.rabbitmq.com")            # => vhost is nil, so default (/) will be used
  AMQ::Client::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/")           # => vhost is an empty string
  AMQ::Client::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/%2Fvault")   # => vhost is /vault
  AMQ::Client::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/production") # => vhost is production
  AMQ::Client::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/a.b.c")      # => vhost is a.b.c
  AMQ::Client::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/foo/bar")    # => ArgumentError

@param [String] connection_string AMQP connection URI, à la JDBC connection string. For example: amqp://bus.megacorp.internal:5877. @return [Hash] Connection parameters (:username, :password, :vhost, :host, :port, :ssl)

@raise [ArgumentError] When connection URI schema is not amqp or amqps, or the path contains multiple segments

@see bit.ly/ks8MXK Connecting to The Broker documentation guide @api public

     # File lib/amq/client/settings.rb, line 135
135:       def self.parse_amqp_url(connection_string)
136:         uri = URI.parse(connection_string)
137:         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 %{amqp amqps}.include?(uri.scheme)
138: 
139:         opts = {}
140: 
141:         opts[:scheme] = uri.scheme
142:         opts[:user]   = URI.unescape(uri.user) if uri.user
143:         opts[:pass]   = URI.unescape(uri.password) if uri.password
144:         opts[:host]   = uri.host if uri.host
145:         opts[:port]   = uri.port || AMQ::Client::Settings::AMQP_PORTS[uri.scheme]
146:         opts[:ssl]    = uri.scheme == AMQ::Client::Settings::AMQPS
147:         if uri.path =~ %{^/(.*)}
148:           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('/')
149:           opts[:vhost] = URI.unescape($1)
150:         end
151: 
152:         opts
153:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.