amqp 1.1.0.pre1 → 1.1.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,157 @@
1
+ # encoding: utf-8
2
+
3
+ require "amq/protocol/client"
4
+ require "uri"
5
+
6
+ module AMQP
7
+ # @see AMQP::Settings.configure
8
+ module Settings
9
+ # @private
10
+ AMQP_PORTS = {"amqp" => 5672, "amqps" => 5671}.freeze
11
+
12
+ # @private
13
+ AMQPS = "amqps".freeze
14
+
15
+ # Default connection settings used by AMQ clients
16
+ #
17
+ # @see AMQP::Settings.configure
18
+ def self.default
19
+ @default ||= {
20
+ # server
21
+ :host => "127.0.0.1",
22
+ :port => AMQ::Protocol::DEFAULT_PORT,
23
+
24
+ # login
25
+ :user => "guest",
26
+ :pass => "guest",
27
+ :auth_mechanism => "PLAIN",
28
+ :vhost => "/",
29
+
30
+ # connection timeout
31
+ :timeout => nil,
32
+
33
+ # logging
34
+ :logging => false,
35
+
36
+ # ssl
37
+ :ssl => false,
38
+
39
+ :frame_max => 131072,
40
+ :heartbeat => 0
41
+ }
42
+ end
43
+
44
+ CLIENT_PROPERTIES = {
45
+ :platform => ::RUBY_DESCRIPTION,
46
+ :product => "amqp gem",
47
+ :information => "http://github.com/ruby-amqp/amqp",
48
+ :version => AMQP::VERSION
49
+ }
50
+
51
+ def self.client_properties
52
+ @client_properties ||= CLIENT_PROPERTIES
53
+ end
54
+
55
+
56
+ # Merges given configuration parameters with defaults and returns
57
+ # the result.
58
+ #
59
+ # @param [Hash] Configuration parameters to use.
60
+ #
61
+ # @option settings [String] :host ("127.0.0.1") Hostname AMQ broker runs on.
62
+ # @option settings [String] :port (5672) Port AMQ broker listens on.
63
+ # @option settings [String] :vhost ("/") Virtual host to use.
64
+ # @option settings [String] :user ("guest") Username to use for authentication.
65
+ # @option settings [String] :pass ("guest") Password to use for authentication.
66
+ # @option settings [String] :ssl (false) Should be use TLS (SSL) for connection?
67
+ # @option settings [String] :timeout (nil) Connection timeout.
68
+ # @option settings [String] :logging (false) Turns logging on or off.
69
+ # @option settings [String] :broker (nil) Broker name (use if you intend to use broker-specific features).
70
+ # @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.
71
+ #
72
+ # @return [Hash] Merged configuration parameters.
73
+ def self.configure(settings = nil)
74
+ case settings
75
+ when Hash then
76
+ if username = settings.delete(:username)
77
+ settings[:user] ||= username
78
+ end
79
+
80
+ if password = settings.delete(:password)
81
+ settings[:pass] ||= password
82
+ end
83
+
84
+
85
+ self.default.merge(settings)
86
+ when String then
87
+ settings = self.parse_amqp_url(settings)
88
+ self.default.merge(settings)
89
+ when NilClass then
90
+ self.default
91
+ end
92
+ end
93
+
94
+ # Parses AMQP connection URI and returns its components as a hash.
95
+ #
96
+ # h2. vhost naming schemes
97
+ #
98
+ # It is convenient to be able to specify the AMQP connection
99
+ # parameters as a URI string, and various "amqp" URI schemes
100
+ # exist. Unfortunately, there is no standard for these URIs, so
101
+ # while the schemes share the basic idea, they differ in some
102
+ # details. This implementation aims to encourage URIs that work
103
+ # as widely as possible.
104
+ #
105
+ # The URI scheme should be "amqp", or "amqps" if SSL is required.
106
+ #
107
+ # The host, port, username and password are represented in the
108
+ # authority component of the URI in the same way as in http URIs.
109
+ #
110
+ # The vhost is obtained from the first segment of the path, with the
111
+ # leading slash removed. The path should contain only a single
112
+ # segment (i.e, the only slash in it should be the leading one).
113
+ # If the vhost is to include slashes or other reserved URI
114
+ # characters, these should be percent-escaped.
115
+ #
116
+ # @example How vhost is parsed
117
+ #
118
+ # AMQP::Settings.parse_amqp_url("amqp://dev.rabbitmq.com") # => vhost is nil, so default (/) will be used
119
+ # AMQP::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/") # => vhost is an empty string
120
+ # AMQP::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/%2Fvault") # => vhost is /vault
121
+ # AMQP::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/production") # => vhost is production
122
+ # AMQP::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/a.b.c") # => vhost is a.b.c
123
+ # AMQP::Settings.parse_amqp_url("amqp://dev.rabbitmq.com/foo/bar") # => ArgumentError
124
+ #
125
+ #
126
+ # @param [String] connection_string AMQP connection URI, à la JDBC connection string. For example: amqp://bus.megacorp.internal:5877.
127
+ # @return [Hash] Connection parameters (:username, :password, :vhost, :host, :port, :ssl)
128
+ #
129
+ # @raise [ArgumentError] When connection URI schema is not amqp or amqps, or the path contains multiple segments
130
+ #
131
+ # @see http://bit.ly/ks8MXK Connecting to The Broker documentation guide
132
+ # @api public
133
+ def self.parse_amqp_url(connection_string)
134
+ uri = URI.parse(connection_string)
135
+ raise ArgumentError.new("Connection URI must use amqp or amqps schema (example: amqp://bus.megacorp.internal:5766), learn more at http://rubyamqp.info") unless %w{amqp amqps}.include?(uri.scheme)
136
+
137
+ opts = {}
138
+
139
+ opts[:scheme] = uri.scheme
140
+ opts[:user] = URI.unescape(uri.user) if uri.user
141
+ opts[:pass] = URI.unescape(uri.password) if uri.password
142
+ opts[:host] = uri.host if uri.host
143
+ opts[:port] = uri.port || AMQP::Settings::AMQP_PORTS[uri.scheme]
144
+ opts[:ssl] = uri.scheme == AMQP::Settings::AMQPS
145
+ if uri.path =~ %r{^/(.*)}
146
+ 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://rubyamqp.info") if $1.index('/')
147
+ opts[:vhost] = URI.unescape($1)
148
+ end
149
+
150
+ opts
151
+ end
152
+
153
+ def self.parse_connection_uri(connection_string)
154
+ parse_amqp_url(connection_string)
155
+ end
156
+ end
157
+ end
@@ -6,5 +6,5 @@ module AMQP
6
6
  #
7
7
  # @see AMQ::Protocol::VERSION
8
8
  # @return [String] AMQP gem version
9
- VERSION = '1.1.0.pre1'
9
+ VERSION = '1.1.0.pre2'
10
10
  end
@@ -67,7 +67,7 @@ describe "Authentication attempt" do
67
67
  end # context
68
68
 
69
69
  context "and provided credentials ARE INCORRECT" do
70
- default_timeout 10
70
+ default_timeout 5
71
71
 
72
72
  after(:all) { done }
73
73
 
@@ -29,21 +29,6 @@ describe "confirm.select" do
29
29
  end
30
30
  end
31
31
  end
32
-
33
-
34
- context "with :nowait attribute set" do
35
- it "results in NOT confirm.select-ok response" do
36
- lambda do
37
- @channel.confirm_select(:nowait => true) do
38
- fail "Should never be called"
39
- end
40
- end.should raise_error(ArgumentError, /makes no sense/)
41
-
42
- @channel.confirm_select(:nowait => true)
43
-
44
- done(0.5)
45
- end
46
- end
47
32
  end
48
33
 
49
34
 
@@ -51,7 +51,7 @@ describe "Store-and-forward routing" do
51
51
 
52
52
  @queue.purge
53
53
  @queue.subscribe(:ack => false) do |payload|
54
- payload.should_not be_nil
54
+ payload.should be_instance_of(String)
55
55
  number_of_received_messages += 1
56
56
  payload.should == dispatched_data
57
57
  end # subscribe
@@ -10,7 +10,7 @@ require "evented-spec"
10
10
  require "effin_utf8"
11
11
  require "multi_json"
12
12
 
13
- puts "Using Ruby #{RUBY_VERSION}, amq-client #{AMQ::Client::VERSION} and amq-protocol #{AMQ::Protocol::VERSION}"
13
+ puts "Using Ruby #{RUBY_VERSION} and amq-protocol #{AMQ::Protocol::VERSION}"
14
14
 
15
15
 
16
16
  amqp_config = File.dirname(__FILE__) + '/amqp.yml'
@@ -2,7 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe AMQP::Client do
5
+ require "amqp/settings"
6
+
7
+ describe AMQP::Settings do
6
8
 
7
9
  #
8
10
  # Examples
@@ -3,53 +3,22 @@
3
3
  require 'spec_helper'
4
4
  require 'amqp'
5
5
 
6
- describe AMQP, 'class object' do
7
-
8
- #
9
- # Environment
10
- #
11
-
12
- subject { AMQP }
6
+ describe AMQP do
13
7
 
14
8
  #
15
9
  # Examples
16
10
  #
17
11
 
18
- its(:settings) do
19
- # TODO: rewrite using key should eql value,
20
- # it's not very wise to check frame_max etc.
21
- should == {
22
- :host => "127.0.0.1",
23
- :port => 5672,
24
- :user => "guest",
25
- :pass => "guest",
26
- :vhost => "/",
27
- :timeout => nil,
28
- :logging => false,
29
- :ssl => false,
30
- :broker => nil,
31
- :frame_max => 131072,
32
- :heartbeat => 0,
33
- :auth_mechanism => "PLAIN"
34
- }
35
- end
36
-
37
- its(:client) { should == AMQP::Session }
38
-
39
-
40
-
41
-
42
- describe 'logging' do
43
- after(:all) do
44
- AMQP.logging = false
45
- end
46
-
47
- it 'is silent by default' do
48
- AMQP.logging.should be_false
49
- end
50
- end # .logging=
51
-
12
+ it "has default settings" do
13
+ s = AMQP.settings.dup
52
14
 
15
+ s[:host].should == "127.0.0.1"
16
+ s[:port].should == 5672
17
+ s[:user].should == "guest"
18
+ s[:pass].should == "guest"
19
+ s[:heartbeat].should == 0
20
+ s[:auth_mechanism].should == "PLAIN"
21
+ end
53
22
 
54
23
 
55
24
  describe '.start' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.pre1
4
+ version: 1.1.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aman Gupta
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-25 00:00:00.000000000 Z
13
+ date: 2013-08-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: eventmachine
@@ -26,20 +26,6 @@ dependencies:
26
26
  - - '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
- - !ruby/object:Gem::Dependency
30
- name: amq-client
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - ~>
34
- - !ruby/object:Gem::Version
35
- version: 1.1.0.pre1
36
- type: :runtime
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- version: 1.1.0.pre1
43
29
  - !ruby/object:Gem::Dependency
44
30
  name: amq-protocol
45
31
  requirement: !ruby/object:Gem::Requirement
@@ -238,22 +224,32 @@ files:
238
224
  - examples/tls_certificates/testca/private/cakey.pem
239
225
  - examples/tls_certificates/testca/serial
240
226
  - examples/tls_certificates/testca/serial.old
227
+ - lib/amq/protocol/get_response.rb
241
228
  - lib/amqp.rb
229
+ - lib/amqp/auth_mechanism_adapter.rb
230
+ - lib/amqp/auth_mechanism_adapter/external.rb
231
+ - lib/amqp/auth_mechanism_adapter/plain.rb
242
232
  - lib/amqp/bit_set.rb
243
233
  - lib/amqp/broker.rb
234
+ - lib/amqp/callbacks.rb
244
235
  - lib/amqp/channel.rb
245
- - lib/amqp/client.rb
246
236
  - lib/amqp/compatibility/ruby187_patchlevel_check.rb
247
- - lib/amqp/connection.rb
248
237
  - lib/amqp/consumer.rb
238
+ - lib/amqp/consumer_tag_generator.rb
239
+ - lib/amqp/deferrable.rb
240
+ - lib/amqp/entity.rb
249
241
  - lib/amqp/exceptions.rb
250
242
  - lib/amqp/exchange.rb
251
243
  - lib/amqp/extensions/rabbitmq.rb
244
+ - lib/amqp/framing/string/frame.rb
245
+ - lib/amqp/handlers_registry.rb
252
246
  - lib/amqp/header.rb
253
247
  - lib/amqp/int_allocator.rb
254
248
  - lib/amqp/integration/rails.rb
249
+ - lib/amqp/openable.rb
255
250
  - lib/amqp/queue.rb
256
251
  - lib/amqp/session.rb
252
+ - lib/amqp/settings.rb
257
253
  - lib/amqp/utilities/event_loop_helper.rb
258
254
  - lib/amqp/utilities/server_type.rb
259
255
  - lib/amqp/version.rb
@@ -325,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
325
321
  version: 1.3.1
326
322
  requirements: []
327
323
  rubyforge_project: amqp
328
- rubygems_version: 2.0.3
324
+ rubygems_version: 2.0.5
329
325
  signing_key:
330
326
  specification_version: 4
331
327
  summary: Widely used, feature-rich asynchronous RabbitMQ client with batteries included
@@ -1,100 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'amq/client/settings'
4
- require "amqp/session"
5
-
6
- module AMQP
7
- # @private
8
- module Client
9
-
10
- # @private
11
- AMQP_PORTS = Hash["amqp" => 5672, "amqps" => 5671].freeze
12
- # @private
13
- AMQPS = "amqps".freeze
14
-
15
-
16
- # {AMQP.connect} delegates to this method. There is no reason for applications or
17
- # libraries to use this method directly.
18
- #
19
- #
20
- # @note This method is not part of the public API and may be removed in the future without any warning.
21
- # @see AMQP.start
22
- # @see AMQP.connect
23
- # @api plugin
24
- #
25
- # @see http://rubyamqp.info/articles/connecting_to_broker/ Connecting to The Broker documentation guide
26
- def self.connect(connection_string_or_options = {}, options = {}, &block)
27
- opts = case connection_string_or_options
28
- when String then
29
- parse_connection_uri(connection_string_or_options)
30
- when Hash then
31
- connection_string_or_options
32
- else
33
- Hash.new
34
- end
35
-
36
- connection = if block
37
- AMQP.client.connect(opts.merge(options), &block)
38
- else
39
- AMQP.client.connect(opts.merge(options))
40
- end
41
-
42
- connection
43
- end
44
-
45
- # Parses AMQP connection URI and returns its components as a hash.
46
- #
47
- # h2. vhost naming schemes
48
- #
49
- # It is convenient to be able to specify the AMQP connection
50
- # parameters as a URI string, and various "amqp" URI schemes
51
- # exist. Unfortunately, there is no standard for these URIs, so
52
- # while the schemes share the basic idea, they differ in some
53
- # details. This implementation aims to encourage URIs that work
54
- # as widely as possible.
55
- #
56
- # The URI scheme should be "amqp", or "amqps" if SSL is required.
57
- #
58
- # The host, port, username and password are represented in the
59
- # authority component of the URI in the same way as in http URIs.
60
- #
61
- # The vhost is obtained from the first segment of the path, with the
62
- # leading slash removed. The path should contain only a single
63
- # segment (i.e, the only slash in it should be the leading one).
64
- # If the vhost is to include slashes or other reserved URI
65
- # characters, these should be percent-escaped.
66
- #
67
- # @example How vhost is parsed
68
- #
69
- # AMQP::Client.parse_connection_uri("amqp://dev.rabbitmq.com") # => vhost is nil, so default (/) will be used
70
- # AMQP::Client.parse_connection_uri("amqp://dev.rabbitmq.com/") # => vhost is an empty string
71
- # AMQP::Client.parse_connection_uri("amqp://dev.rabbitmq.com/%2Fvault") # => vhost is /vault
72
- # AMQP::Client.parse_connection_uri("amqp://dev.rabbitmq.com/production") # => vhost is production
73
- # AMQP::Client.parse_connection_uri("amqp://dev.rabbitmq.com/a.b.c") # => vhost is a.b.c
74
- # AMQP::Client.parse_connection_uri("amqp://dev.rabbitmq.com/foo/bar") # => ArgumentError
75
- #
76
- #
77
- # @param [String] connection_string AMQP connection URI, à la JDBC connection string. For example: amqp://bus.megacorp.internal:5877.
78
- # @return [Hash] Connection parameters (:username, :password, :vhost, :host, :port, :ssl)
79
- #
80
- # @raise [ArgumentError] When connection URI schema is not amqp or amqps, or the path contains multiple segments
81
- #
82
- # @see http://rubyamqp.info/articles/connecting_to_broker/ Connecting to The Broker documentation guide
83
- # @api public
84
- def self.parse_connection_uri(connection_string)
85
- AMQ::Client::Settings.parse_amqp_url(connection_string)
86
- end
87
- end # Client
88
-
89
-
90
-
91
- # @private
92
- def self.client
93
- @client_implementation ||= AMQP::Session
94
- end
95
-
96
- # @private
97
- def self.client=(value)
98
- @client_implementation = value
99
- end
100
- end # AMQP