amq-client 0.7.0.alpha35 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.rspec +0 -1
  2. data/.travis.yml +9 -3
  3. data/Gemfile +22 -12
  4. data/amq-client.gemspec +1 -1
  5. data/examples/coolio_adapter/example_helper.rb +2 -0
  6. data/examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb +3 -3
  7. data/examples/eventmachine_adapter/{connection_failure_callback.rb → error_handling/connection_failure_callback.rb} +4 -8
  8. data/examples/eventmachine_adapter/{connection_failure_exception.rb → error_handling/connection_failure_exception.rb} +5 -9
  9. data/examples/eventmachine_adapter/{connection_loss_handler.rb → error_handling/connection_loss_handler_that_fails_over.rb} +12 -12
  10. data/examples/eventmachine_adapter/error_handling/connection_loss_handler_with_automatic_recovery.rb +85 -0
  11. data/examples/eventmachine_adapter/error_handling/connection_loss_handler_with_manual_recovery.rb +85 -0
  12. data/examples/eventmachine_adapter/error_handling/handling_a_channel_level_exception.rb +2 -5
  13. data/examples/eventmachine_adapter/example_helper.rb +2 -0
  14. data/examples/eventmachine_adapter/server_capabilities.rb +12 -0
  15. data/examples/eventmachine_adapter/tls/tls_without_peer_verification.rb +2 -2
  16. data/lib/amq/client/async/adapter.rb +170 -31
  17. data/lib/amq/client/async/adapters/coolio.rb +18 -1
  18. data/lib/amq/client/async/adapters/event_machine.rb +48 -32
  19. data/lib/amq/client/async/adapters/eventmachine.rb +3 -1
  20. data/lib/amq/client/async/callbacks.rb +9 -7
  21. data/lib/amq/client/async/channel.rb +113 -20
  22. data/lib/amq/client/async/consumer.rb +270 -0
  23. data/lib/amq/client/async/exchange.rb +137 -16
  24. data/lib/amq/client/async/extensions/rabbitmq/confirm.rb +4 -4
  25. data/lib/amq/client/async/queue.rb +217 -113
  26. data/lib/amq/client/callbacks.rb +2 -0
  27. data/lib/amq/client/consumer_tag_generator.rb +24 -0
  28. data/lib/amq/client/exceptions.rb +10 -6
  29. data/lib/amq/client/handlers_registry.rb +2 -0
  30. data/lib/amq/client/queue.rb +2 -0
  31. data/lib/amq/client/server_named_entity.rb +1 -8
  32. data/lib/amq/client/settings.rb +64 -2
  33. data/lib/amq/client/version.rb +3 -1
  34. data/spec/benchmarks/adapters.rb +2 -0
  35. data/spec/client/framing/io_frame_spec.rb +9 -6
  36. data/spec/integration/coolio/basic_ack_spec.rb +2 -0
  37. data/spec/integration/coolio/basic_cancel_spec.rb +2 -0
  38. data/spec/integration/coolio/basic_consume_spec.rb +58 -0
  39. data/spec/integration/coolio/basic_get_spec.rb +2 -0
  40. data/spec/integration/coolio/basic_return_spec.rb +2 -0
  41. data/spec/integration/coolio/channel_close_spec.rb +2 -0
  42. data/spec/integration/coolio/channel_flow_spec.rb +2 -0
  43. data/spec/integration/coolio/connection_close_spec.rb +2 -0
  44. data/spec/integration/coolio/connection_start_spec.rb +2 -0
  45. data/spec/integration/coolio/exchange_declare_spec.rb +8 -6
  46. data/spec/integration/coolio/spec_helper.rb +2 -0
  47. data/spec/integration/coolio/tx_commit_spec.rb +2 -1
  48. data/spec/integration/coolio/tx_rollback_spec.rb +1 -1
  49. data/spec/integration/eventmachine/basic_ack_spec.rb +3 -1
  50. data/spec/integration/eventmachine/basic_cancel_spec.rb +2 -0
  51. data/spec/integration/eventmachine/basic_consume_spec.rb +90 -6
  52. data/spec/integration/eventmachine/basic_get_spec.rb +2 -0
  53. data/spec/integration/eventmachine/basic_return_spec.rb +2 -0
  54. data/spec/integration/eventmachine/channel_close_spec.rb +2 -0
  55. data/spec/integration/eventmachine/channel_flow_spec.rb +4 -2
  56. data/spec/integration/eventmachine/concurrent_basic_publish_spec.rb +79 -0
  57. data/spec/integration/eventmachine/connection_close_spec.rb +2 -0
  58. data/spec/integration/eventmachine/connection_start_spec.rb +2 -0
  59. data/spec/integration/eventmachine/exchange_declare_spec.rb +4 -2
  60. data/spec/integration/eventmachine/queue_declare_spec.rb +2 -0
  61. data/spec/integration/eventmachine/regressions/amqp_gem_issue66_spec.rb +2 -0
  62. data/spec/integration/eventmachine/spec_helper.rb +2 -0
  63. data/spec/integration/eventmachine/tx_commit_spec.rb +2 -1
  64. data/spec/integration/eventmachine/tx_rollback_spec.rb +1 -1
  65. data/spec/regression/bad_frame_slicing_in_adapters_spec.rb +2 -0
  66. data/spec/spec_helper.rb +10 -0
  67. data/spec/unit/client/settings_spec.rb +92 -3
  68. metadata +24 -23
  69. data/CONTRIBUTORS +0 -3
data/.rspec CHANGED
@@ -1,2 +1 @@
1
1
  --colour
2
- --format nested
data/.travis.yml CHANGED
@@ -1,14 +1,20 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
1
2
  bundler_args: --without development
2
3
  script: "bundle exec rspec spec"
3
4
  before_script: ./bin/ci/before_build.sh
4
5
  rvm:
5
6
  - 1.8.7
6
- - 1.8.7-p174
7
+ - 1.8.7-p249
7
8
  - ree
8
- - rbx
9
+ - rbx-2.0
9
10
  - 1.9.2
10
- - jruby
11
11
  - ruby-head
12
+ - jruby
12
13
  gemfile:
13
14
  - Gemfile
14
15
  - gemfiles/eventmachine-pre
16
+ notifications:
17
+ recipients:
18
+ - jakub@rabbitmq.com
19
+ - michaelklishin@me.com
20
+ - markizko@gmail.com
data/Gemfile CHANGED
@@ -4,20 +4,26 @@ source :rubygems
4
4
 
5
5
  # Use local clones if possible.
6
6
  # If you want to use your local copy, just symlink it to vendor.
7
- def custom_gem(name, options = Hash.new)
8
- local_path = File.expand_path("../vendor/#{name}", __FILE__)
9
- if File.exist?(local_path)
10
- gem name, options.merge(:path => local_path).delete_if { |key, _| [:git, :branch].include?(key) }
11
- else
12
- gem name, options
7
+ # See http://blog.101ideas.cz/posts/custom-gems-in-gemfile.html
8
+ extend Module.new {
9
+ def gem(name, *args)
10
+ options = args.last.is_a?(Hash) ? args.last : Hash.new
11
+
12
+ local_path = File.expand_path("../vendor/#{name}", __FILE__)
13
+ if File.exist?(local_path)
14
+ super name, options.merge(:path => local_path).
15
+ delete_if { |key, _| [:git, :branch].include?(key) }
16
+ else
17
+ super name, *args
18
+ end
13
19
  end
14
- end
20
+ }
15
21
 
16
- custom_gem "eventmachine"
22
+ gem "eventmachine"
17
23
  # cool.io uses iobuffer that won't compile on JRuby
18
24
  # (and, probably, Windows)
19
25
  gem "cool.io", :platform => :ruby
20
- custom_gem "amq-protocol", :git => "git://github.com/ruby-amqp/amq-protocol.git", :branch => "master"
26
+ gem "amq-protocol", :git => "git://github.com/ruby-amqp/amq-protocol.git", :branch => "master"
21
27
 
22
28
  group :development do
23
29
  gem "yard"
@@ -25,8 +31,6 @@ group :development do
25
31
  gem "RedCloth", :platform => :mri
26
32
 
27
33
  gem "nake", :platform => :ruby_19
28
- gem "contributors", :platform => :ruby_19
29
-
30
34
  # excludes Windows and JRuby
31
35
  gem "perftools.rb", :platform => :mri
32
36
  end
@@ -34,5 +38,11 @@ end
34
38
  group :test do
35
39
  gem "rspec", ">=2.0.0"
36
40
  gem "autotest"
37
- custom_gem "evented-spec", :git => "git://github.com/ruby-amqp/evented-spec.git", :branch => "master"
41
+ gem "evented-spec", :git => "git://github.com/ruby-amqp/evented-spec.git", :branch => "master"
42
+ gem "effin_utf8"
43
+
44
+ gem "multi_json"
45
+
46
+ gem "json", :platform => :jruby
47
+ gem "yajl-ruby", :platform => :ruby_18
38
48
  end
data/amq-client.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # Dependencies
22
22
  s.add_dependency "eventmachine"
23
- s.add_dependency "amq-protocol", ">= 0.7.0.alpha6"
23
+ s.add_dependency "amq-protocol", ">= 0.8.0"
24
24
 
25
25
 
26
26
  # RubyForge
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "bundler"
2
4
 
3
5
  Bundler.setup
@@ -18,10 +18,10 @@ amq_client_example "Acknowledge a message using basic.ack" do |client|
18
18
  end
19
19
 
20
20
  queue.consume do |consumer_tag|
21
- queue.on_delivery do |method, header, payload|
22
- puts "Got a delivery: #{payload} (delivery tag: #{method.delivery_tag}), ack-ing..."
21
+ queue.on_delivery do |basic_deliver, header, payload|
22
+ puts "Got a delivery: #{payload} (delivery tag: #{basic_deliver.delivery_tag}), ack-ing..."
23
23
 
24
- queue.acknowledge(method.delivery_tag)
24
+ queue.acknowledge(basic_deliver.delivery_tag)
25
25
  end
26
26
 
27
27
  exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
@@ -2,21 +2,17 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __dir = File.join(File.dirname(File.expand_path(__FILE__)))
5
- require File.join(__dir, "example_helper")
5
+ require File.join(__dir, "..", "example_helper")
6
6
 
7
7
  EM.run do
8
8
 
9
- show_stopper = Proc.new {
10
- EM.stop
11
- }
12
-
13
- Signal.trap "INT", show_stopper
9
+ show_stopper = Proc.new { EventMachine.stop }
14
10
  Signal.trap "TERM", show_stopper
15
-
16
11
  EM.add_timer(4, show_stopper)
17
12
 
13
+
18
14
  AMQ::Client::EventMachineClient.connect(:port => 9689,
19
- :vhost => "/amq_client_testbed",
15
+ :vhost => "amq_client_testbed",
20
16
  :user => "amq_client_gem",
21
17
  :password => "amq_client_gem_password",
22
18
  :timeout => 0.3,
@@ -2,22 +2,18 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __dir = File.join(File.dirname(File.expand_path(__FILE__)))
5
- require File.join(__dir, "example_helper")
5
+ require File.join(__dir, "..", "example_helper")
6
6
 
7
7
  begin
8
8
  EventMachine.run do
9
9
 
10
- show_stopper = Proc.new {
11
- EM.stop
12
- }
13
-
14
- Signal.trap "INT", show_stopper
10
+ show_stopper = Proc.new { EventMachine.stop }
15
11
  Signal.trap "TERM", show_stopper
16
-
17
12
  EventMachine.add_timer(4, show_stopper)
18
13
 
14
+
19
15
  AMQ::Client::EventMachineClient.connect(:port => 9689,
20
- :vhost => "/amq_client_testbed",
16
+ :vhost => "amq_client_testbed",
21
17
  :user => "amq_client_gem",
22
18
  :password => "amq_client_gem_password",
23
19
  :timeout => 0.3) do |client|
@@ -27,4 +23,4 @@ begin
27
23
  rescue AMQ::Client::TCPConnectionFailed => e
28
24
  puts "TCP connection has failed, as expected. Shutting down…"
29
25
  EventMachine.stop if EventMachine.reactor_running?
30
- end
26
+ end
@@ -2,32 +2,32 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __dir = File.join(File.dirname(File.expand_path(__FILE__)))
5
- require File.join(__dir, "example_helper")
5
+ require File.join(__dir, "..", "example_helper")
6
6
 
7
7
 
8
8
  EM.run do
9
9
  AMQ::Client::EventMachineClient.connect(:port => 5672,
10
- :vhost => "/amq_client_testbed",
10
+ :vhost => "amq_client_testbed",
11
11
  :user => "amq_client_gem",
12
12
  :password => "amq_client_gem_password",
13
13
  :timeout => 0.3,
14
- :on_tcp_connection_failure => Proc.new { |settings| puts "Failed to connect, this was NOT expected"; EM.stop }) do |client|
14
+ :on_tcp_connection_failure => Proc.new { |settings| puts "Failed to connect, this was NOT expected"; EM.stop }) do |connection|
15
15
 
16
- client.on_tcp_connection_loss do |cl, settings|
17
- puts "tcp_connection_loss handler kicks in"
18
- cl.reconnect(false, 2)
16
+ connection.on_tcp_connection_loss do |conn, settings|
17
+ puts "Trying to reconnect..."
18
+ conn.reconnect_to(:host => "dev.rabbitmq.com")
19
+ end
20
+
21
+ connection.on_recovery do |conn, settings|
22
+ puts "Connection recovered"
19
23
  end
20
24
 
21
25
  show_stopper = Proc.new {
22
- client.disconnect {
23
- puts "Disconnected. Exiting…"
24
- EM.stop
25
- }
26
+ connection.disconnect { puts "Disconnected. Exiting…"; EventMachine.stop }
26
27
  }
27
28
 
28
- Signal.trap "INT", show_stopper
29
29
  Signal.trap "TERM", show_stopper
30
-
30
+ Signal.trap "INT", show_stopper
31
31
  EM.add_timer(30, show_stopper)
32
32
 
33
33
 
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ __dir = File.join(File.dirname(File.expand_path(__FILE__)))
5
+ require File.join(__dir, "..", "example_helper")
6
+
7
+
8
+ EM.run do
9
+ AMQ::Client::EventMachineClient.connect(:port => 5672,
10
+ :vhost => "amq_client_testbed",
11
+ :user => "amq_client_gem",
12
+ :password => "amq_client_gem_password",
13
+ :timeout => 0.3,
14
+ :on_tcp_connection_failure => Proc.new { |settings| puts "Failed to connect, this was NOT expected"; EM.stop }) do |connection|
15
+
16
+ if connection.auto_recovering?
17
+ puts "Connection is auto-recovering..."
18
+ end
19
+
20
+ ch1 = AMQ::Client::Channel.new(connection, 1, :auto_recovery => true)
21
+ ch1.on_error do |ch, channel_close|
22
+ raise channel_close.reply_text
23
+ end
24
+ ch1.open do
25
+ puts "Channel 1 open now"
26
+ end
27
+ if ch1.auto_recovering?
28
+ puts "Channel 1 is auto-recovering"
29
+ end
30
+ ch1.on_recovery do |c|
31
+ puts "Channel #{c.id} has recovered"
32
+ end
33
+
34
+ ch2 = AMQ::Client::Channel.new(connection, 2, :auto_recovery => true)
35
+ ch2.on_error do |ch, channel_close|
36
+ raise channel_close.reply_text
37
+ end
38
+ ch2.open do
39
+ puts "Channel 2 open now"
40
+ end
41
+ if ch2.auto_recovering?
42
+ puts "Channel 2 is auto-recovering"
43
+ end
44
+
45
+
46
+ queues = Array.new(4) do
47
+ q = AMQ::Client::Queue.new(connection, ch1, AMQ::Protocol::EMPTY_STRING)
48
+ q.declare(false, false, false, true) do
49
+ q.consume { puts "Added a consumer on #{q.name}"; q.on_delivery { |*args| puts(args.inspect) } }
50
+ end
51
+
52
+ q.on_recovery { |_| puts "Queue #{q.name} has recovered" }
53
+
54
+ q
55
+ end
56
+
57
+ x = AMQ::Client::Exchange.new(connection, ch1, "amqclient.examples.exchanges.fanout", :fanout)
58
+ x2 = AMQ::Client::Exchange.new(connection, ch1, "amq.fanout", :fanout)
59
+ x.declare(false, false, true)
60
+ x.after_connection_interruption { |x| puts "Exchange #{x.name} has reacted to connection interruption" }
61
+ x.after_recovery { |x| puts "Exchange #{x.name} has recovered" }
62
+ queues.each { |q| q.bind(x) }
63
+
64
+
65
+ connection.on_tcp_connection_loss do |conn, settings|
66
+ puts "Trying to reconnect..."
67
+ conn.reconnect(false, 2)
68
+ end
69
+
70
+ connection.on_recovery do |conn, settings|
71
+ puts "Connection recovered"
72
+ end
73
+
74
+ show_stopper = Proc.new {
75
+ connection.disconnect { puts "Disconnected. Exiting…"; EventMachine.stop }
76
+ }
77
+
78
+ Signal.trap "TERM", show_stopper
79
+ Signal.trap "INT", show_stopper
80
+ EM.add_timer(30, show_stopper)
81
+
82
+
83
+ puts "Connected, authenticated. To really exercise this example, shut AMQP broker down for a few seconds. If you don't it will exit gracefully in 30 seconds."
84
+ end
85
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ __dir = File.join(File.dirname(File.expand_path(__FILE__)))
5
+ require File.join(__dir, "..", "example_helper")
6
+
7
+
8
+ EM.run do
9
+ AMQ::Client::EventMachineClient.connect(:port => 5672,
10
+ :vhost => "amq_client_testbed",
11
+ :user => "amq_client_gem",
12
+ :password => "amq_client_gem_password",
13
+ :timeout => 0.3,
14
+ :on_tcp_connection_failure => Proc.new { |settings| puts "Failed to connect, this was NOT expected"; EM.stop }) do |connection|
15
+
16
+ if connection.auto_recovering?
17
+ puts "Connection is auto-recovering..."
18
+ end
19
+
20
+ ch1 = AMQ::Client::Channel.new(connection, 1)
21
+ ch1.on_error do |ch, channel_close|
22
+ raise channel_close.reply_text
23
+ end
24
+ ch1.open do
25
+ puts "Channel 1 open now"
26
+ end
27
+ if ch1.auto_recovering?
28
+ puts "Channel 1 is auto-recovering"
29
+ end
30
+ ch1.on_recovery do |c|
31
+ puts "Channel #{c.id} has recovered"
32
+ end
33
+
34
+ ch2 = AMQ::Client::Channel.new(connection, 2)
35
+ ch2.on_error do |ch, channel_close|
36
+ raise channel_close.reply_text
37
+ end
38
+ ch2.open do
39
+ puts "Channel 2 open now"
40
+ end
41
+ if ch2.auto_recovering?
42
+ puts "Channel 2 is auto-recovering"
43
+ end
44
+
45
+
46
+ queues = Array.new(4) do
47
+ q = AMQ::Client::Queue.new(connection, ch1, AMQ::Protocol::EMPTY_STRING)
48
+ q.declare(false, false, false, true) do
49
+ q.consume { puts "Added a consumer on #{q.name}"; q.on_delivery { |*args| puts(args.inspect) } }
50
+ end
51
+
52
+ q.on_recovery { |_| puts "Queue #{q.name} has recovered" }
53
+
54
+ q
55
+ end
56
+
57
+ x = AMQ::Client::Exchange.new(connection, ch1, "amqclient.examples.exchanges.fanout", :fanout)
58
+ x2 = AMQ::Client::Exchange.new(connection, ch1, "amq.fanout", :fanout)
59
+ x.declare(false, false, true)
60
+ x.after_connection_interruption { |x| puts "Exchange #{x.name} has reacted to connection interruption" }
61
+ x.after_recovery { |x| puts "Exchange #{x.name} has recovered" }
62
+ queues.each { |q| q.bind(x) }
63
+
64
+
65
+ connection.on_tcp_connection_loss do |conn, settings|
66
+ puts "Trying to reconnect..."
67
+ conn.reconnect(false, 2)
68
+ end
69
+
70
+ connection.on_recovery do |conn, settings|
71
+ puts "Connection recovered"
72
+ end
73
+
74
+ show_stopper = Proc.new {
75
+ connection.disconnect { puts "Disconnected. Exiting…"; EventMachine.stop }
76
+ }
77
+
78
+ Signal.trap "TERM", show_stopper
79
+ Signal.trap "INT", show_stopper
80
+ EM.add_timer(30, show_stopper)
81
+
82
+
83
+ puts "Connected, authenticated. To really exercise this example, shut AMQP broker down for a few seconds. If you don't it will exit gracefully in 30 seconds."
84
+ end
85
+ end
@@ -4,7 +4,7 @@
4
4
  __dir = File.dirname(File.expand_path(__FILE__))
5
5
  require File.join(__dir, "..", "example_helper")
6
6
 
7
- amq_client_example "Declare a new fanout exchange" do |connection|
7
+ amq_client_example "Handling a channel-level exception" do |connection|
8
8
  channel = AMQ::Client::Channel.new(connection, 1)
9
9
  channel.open do
10
10
  puts "Channel #{channel.id} is now open!"
@@ -30,10 +30,7 @@ amq_client_example "Declare a new fanout exchange" do |connection|
30
30
 
31
31
  show_stopper = Proc.new do
32
32
  $stdout.puts "Stopping..."
33
-
34
- connection.close {
35
- EM.stop { exit }
36
- }
33
+ connection.close { EventMachine.stop }
37
34
  end
38
35
 
39
36
  Signal.trap "INT", show_stopper
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "bundler"
2
4
 
3
5
  Bundler.setup
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ __dir = File.dirname(File.expand_path(__FILE__))
5
+ require File.join(__dir, "example_helper")
6
+
7
+ amq_client_example "Inspecting server information & capabilities" do |client|
8
+ puts client.server_capabilities.inspect
9
+ puts client.server_properties.inspect
10
+
11
+ client.disconnect { EventMachine.stop }
12
+ end
@@ -10,7 +10,7 @@ client_private_key_file_path = File.join(examples_dir, "tls_certificates", "clie
10
10
 
11
11
  EM.run do
12
12
  AMQ::Client::EventMachineClient.connect(:port => 5671,
13
- :vhost => "/amq_client_testbed",
13
+ :vhost => "amq_client_testbed",
14
14
  :user => "amq_client_gem",
15
15
  :password => "amq_client_gem_password",
16
16
  :ssl => {
@@ -33,4 +33,4 @@ EM.run do
33
33
  # TLS connections take forever and a day
34
34
  # (compared to non-TLS connections) to estabilish.
35
35
  EM.add_timer(8, show_stopper)
36
- end
36
+ end