amqp 0.8.0.rc12 → 0.8.0.rc13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.travis.yml +1 -1
  2. data/.yardopts +2 -1
  3. data/CONTRIBUTORS +29 -22
  4. data/Gemfile +2 -1
  5. data/README.md +241 -0
  6. data/amqp.gemspec +7 -5
  7. data/bin/set_test_suite_realms_up.sh +6 -6
  8. data/docs/08Migration.textile +3 -1
  9. data/docs/Bindings.textile +3 -1
  10. data/docs/Clustering.textile +4 -0
  11. data/docs/ConnectingToTheBroker.textile +108 -86
  12. data/docs/ConnectionEncryptionWithTLS.textile +3 -1
  13. data/docs/DocumentationGuidesIndex.textile +24 -2
  14. data/docs/Durability.textile +22 -1
  15. data/docs/ErrorHandling.textile +21 -1
  16. data/docs/Exchanges.textile +181 -9
  17. data/docs/GettingStarted.textile +65 -167
  18. data/docs/Queues.textile +400 -355
  19. data/docs/RabbitMQVersions.textile +34 -3
  20. data/docs/Routing.textile +4 -1
  21. data/docs/RunningTests.textile +116 -0
  22. data/docs/Troubleshooting.textile +131 -0
  23. data/docs/VendorSpecificExtensions.textile +20 -0
  24. data/examples/channels/qos_aka_prefetch.rb +3 -3
  25. data/examples/channels/qos_aka_prefetch_without_callback.rb +2 -2
  26. data/examples/error_handling/channel_level_exception.rb +1 -1
  27. data/examples/error_handling/channel_level_exception_with_multiple_channels_involved.rb +1 -0
  28. data/examples/error_handling/connection_level_exception.rb +26 -0
  29. data/examples/error_handling/global_channel_level_exception_handler.rb +3 -3
  30. data/examples/exchanges/autodeletion_of_exchanges.rb +37 -0
  31. data/examples/extensions/rabbitmq/per_queue_message_ttl.rb +3 -3
  32. data/examples/extensions/rabbitmq/publisher_confirmations_with_transient_messages.rb +2 -2
  33. data/examples/guides/getting_started/{03_babblr.rb → 03_blabbr.rb} +0 -0
  34. data/examples/guides/queues/01a_declaring_a_server_named_queue_using_queue_constructor.rb +18 -0
  35. data/examples/guides/queues/01b_declaring_a_queue_using_queue_constructor.rb +18 -0
  36. data/examples/guides/queues/02a_declaring_a_durable_shared_queue.rb +18 -0
  37. data/examples/guides/queues/02b_declaring_a_durable_shared_queue.rb +18 -0
  38. data/examples/guides/queues/03a_declaring_a_temporary_exclusive_queue.rb +19 -0
  39. data/examples/guides/queues/03b_declaring_a_temporary_exclusive_queue.rb +18 -0
  40. data/examples/guides/queues/{05_binding_a_queue_using_exchange_instance.rb → 04_bind_a_queue_using_exchange_instance.rb} +2 -2
  41. data/examples/guides/queues/{06_biding_a_queue_using_exchange_name_string.rb → 05_bind_a_queue_using_exchange_name.rb} +2 -2
  42. data/examples/guides/queues/{07_subscribing_to_receive_messages.rb → 06_subscribe_to_receive_messages.rb} +1 -1
  43. data/examples/guides/queues/{08_poll_for_messages.rb → 07_fetch_a_message_from_the_queue.rb} +1 -1
  44. data/examples/guides/queues/{09_unsubscribing_a_consumer.rb → 08_unsubscribing_a_consumer.rb} +0 -0
  45. data/examples/guides/queues/{10_unbinding_from_exchange.rb → 09_unbinding_from_exchange.rb} +2 -2
  46. data/examples/guides/queues/{11_purge_a_queue.rb → 10_purge_a_queue.rb} +2 -2
  47. data/examples/guides/queues/{12_deleting_a_queue.rb → 11_deleting_a_queue.rb} +2 -2
  48. data/examples/hello_world.rb +1 -1
  49. data/examples/hello_world_with_an_empty_string.rb +33 -0
  50. data/examples/issues/amq_client_issue_7.rb +31 -0
  51. data/examples/issues/amq_protocol_issue_14.rb +46 -0
  52. data/examples/issues/issue_75.rb +23 -0
  53. data/examples/issues/issue_79.rb +35 -0
  54. data/examples/issues/issue_80.rb +40 -0
  55. data/examples/publishing/{publishing_and_immediately_stopping_event_loop.rb → publishing_a_one_off_message.rb} +9 -12
  56. data/examples/publishing/publishing_callback.rb +52 -0
  57. data/examples/publishing/returned_messages.rb +3 -3
  58. data/examples/queues/accessing_message_metadata.rb +60 -0
  59. data/examples/queues/queue_status.rb +0 -7
  60. data/examples/queues/rejecting_messages_without_requeueuing.rb +47 -0
  61. data/examples/queues/using_explicit_acknowledgements.rb +96 -0
  62. data/examples/routing/headers_routing.rb +54 -0
  63. data/lib/amqp/channel.rb +245 -40
  64. data/lib/amqp/client.rb +23 -11
  65. data/lib/amqp/exchange.rb +58 -41
  66. data/lib/amqp/queue.rb +66 -13
  67. data/lib/amqp/version.rb +1 -1
  68. data/spec/integration/authentication_spec.rb +5 -5
  69. data/spec/integration/basic_get_spec.rb +1 -1
  70. data/spec/integration/channel_close_spec.rb +10 -3
  71. data/spec/integration/queue_declaration_spec.rb +26 -5
  72. data/spec/integration/topic_subscription_spec.rb +1 -1
  73. data/spec/unit/amqp/client_spec.rb +7 -54
  74. data/tasks.rb +1 -8
  75. metadata +64 -23
  76. data/README.textile +0 -229
@@ -13,8 +13,8 @@ AMQP.start do |connection|
13
13
  AMQP::Channel.new(connection) do |channel, open_ok|
14
14
  puts "Channel #{channel.id} is now open"
15
15
 
16
- channel.on_error do
17
- puts "Oops, there is a channel-levle exceptions!"
16
+ channel.on_error do |ch, channel_close|
17
+ puts "Oops! a channel-level exception: #{channel_close.reply_text}"
18
18
  end
19
19
 
20
20
  x = channel.fanout("amq.fanout")
@@ -54,4 +54,4 @@ AMQP.start do |connection|
54
54
  EM.add_timer(3, show_stopper)
55
55
  Signal.trap('INT', show_stopper)
56
56
  Signal.trap('TERM', show_stopper)
57
- end
57
+ end
@@ -14,8 +14,8 @@ AMQP.start do |connection|
14
14
  puts "Channel #{channel.id} is now open"
15
15
 
16
16
  channel.confirm_select
17
- channel.on_error do
18
- puts "Oops, there is a channel-levle exceptions!"
17
+ channel.on_error do |ch, channel_close|
18
+ puts "Oops! a channel-level exception: #{channel_close.reply_text}"
19
19
  end
20
20
 
21
21
 
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ # Declaring a server-named queue using AMQP::Queue constructor
8
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
9
+ AMQP::Channel.new do |channel, open_ok|
10
+ AMQP::Queue.new(channel, "", :auto_delete => true) do |queue, declare_ok|
11
+ puts "#{queue.name} is ready to go. AMQP method: #{declare_ok.inspect}"
12
+
13
+ connection.close {
14
+ EventMachine.stop { exit }
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ # Declaring a queue with explicitly given name using AMQP::Queue constructor
8
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
9
+ AMQP::Channel.new do |channel, open_ok|
10
+ AMQP::Queue.new(channel, "images.resize", :auto_delete => true) do |queue, declare_ok|
11
+ puts "#{queue.name} is ready to go."
12
+
13
+ connection.close {
14
+ EventMachine.stop { exit }
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ # Declaring a durable shared queue
8
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
9
+ AMQP::Channel.new do |channel, open_ok|
10
+ AMQP::Queue.new(channel, "images.resize", :durable => true) do |queue, declare_ok|
11
+ puts "#{queue.name} is ready to go."
12
+
13
+ connection.close {
14
+ EventMachine.stop { exit }
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ # Declaring a durable shared queue using AMQP::Channel#queue method
8
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
9
+ AMQP::Channel.new do |channel, open_ok|
10
+ channel.queue("images.resize", :durable => true) do |queue, declare_ok|
11
+ puts "#{queue.name} is ready to go."
12
+
13
+ connection.close {
14
+ EventMachine.stop { exit }
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ # Declaring a temporary exclusive queue
8
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
9
+ AMQP::Channel.new do |channel, open_ok|
10
+ AMQP::Queue.new(channel, "", :auto_delete => true, :exclusive => true) do |queue, declare_ok|
11
+ puts "#{queue.name} is ready to go."
12
+
13
+ connection.close {
14
+ EventMachine.stop { exit }
15
+ }
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ # Declaring a temporary exclusive queue
8
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
9
+ AMQP::Channel.new do |channel, open_ok|
10
+ channel.queue("", :auto_delete => true, :exclusive => true) do |queue, declare_ok|
11
+ puts "#{queue.name} is ready to go."
12
+
13
+ connection.close {
14
+ EventMachine.stop { exit }
15
+ }
16
+ end
17
+ end
18
+ end
@@ -5,7 +5,7 @@ require "rubygems"
5
5
  require "amqp"
6
6
 
7
7
  # Binding a queue to an exchange
8
- AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
8
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
9
9
  AMQP::Channel.new do |channel, open_ok|
10
10
  exchange = channel.fanout("amq.fanout")
11
11
 
@@ -15,7 +15,7 @@ AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
15
15
  end
16
16
 
17
17
  connection.close {
18
- EM.stop { exit }
18
+ EventMachine.stop { exit }
19
19
  }
20
20
  end
21
21
  end
@@ -5,7 +5,7 @@ require "rubygems"
5
5
  require "amqp"
6
6
 
7
7
  # Binding a queue to an exchange
8
- AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
8
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
9
9
  AMQP::Channel.new do |channel, open_ok|
10
10
  exchange_name = "amq.fanout"
11
11
 
@@ -15,7 +15,7 @@ AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
15
15
  end
16
16
 
17
17
  connection.close {
18
- EM.stop { exit }
18
+ EventMachine.stop { exit }
19
19
  }
20
20
  end
21
21
  end
@@ -4,7 +4,7 @@
4
4
  require "rubygems"
5
5
  require "amqp"
6
6
 
7
- AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
7
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
8
8
  AMQP::Channel.new do |channel, open_ok|
9
9
  exchange = channel.fanout("amq.fanout")
10
10
 
@@ -4,7 +4,7 @@
4
4
  require "rubygems"
5
5
  require "amqp"
6
6
 
7
- AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
7
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
8
8
  AMQP::Channel.new do |channel, open_ok|
9
9
  exchange = channel.fanout("amq.fanout")
10
10
 
@@ -8,8 +8,8 @@ AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
8
8
  puts "Connected"
9
9
  AMQP::Channel.new(connection) do |channel, open_ok|
10
10
  puts "Opened a channel"
11
- channel.on_error do |arg|
12
- raise "Channel-level exception: #{arg.inspect}"
11
+ channel.on_error do |ch, channel_close|
12
+ raise "Channel-level exception: #{channel_close.reply_text}"
13
13
  end
14
14
  exchange = channel.fanout("amq.fanout")
15
15
 
@@ -8,8 +8,8 @@ AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
8
8
  puts "Connected"
9
9
  AMQP::Channel.new(connection) do |channel, open_ok|
10
10
  puts "Opened a channel"
11
- channel.on_error do |arg|
12
- raise "Channel-level exception: #{arg.inspect}"
11
+ channel.on_error do |ch, channel_close|
12
+ raise "Channel-level exception: #{channel_close.reply_text}"
13
13
  end
14
14
  exchange = channel.fanout("amq.fanout")
15
15
 
@@ -8,8 +8,8 @@ AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
8
8
  puts "Connected"
9
9
  AMQP::Channel.new(connection) do |channel, open_ok|
10
10
  puts "Opened a channel"
11
- channel.on_error do |arg|
12
- raise "Channel-level exception: #{arg.inspect}"
11
+ channel.on_error do |ch, channel_close|
12
+ raise "Channel-level exception: #{channel_close.reply_text}"
13
13
  end
14
14
  exchange = channel.fanout("amq.fanout")
15
15
 
@@ -24,5 +24,5 @@ EventMachine.run do
24
24
  }
25
25
  end
26
26
 
27
- exchange.publish "Hello, world!", :routing_key => queue.name
27
+ exchange.publish "Hello, world!", :routing_key => queue.name, :app_id => "Hello world"
28
28
  end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+ EventMachine.run do
12
+ connection = AMQP.connect(:host => '127.0.0.1', :port => 5672)
13
+ puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
14
+
15
+
16
+ connection.on_error do |conn, connection_close|
17
+ puts "Handling a connection-level exception: #{connection_close.reply_text}"
18
+ end
19
+
20
+ channel = AMQP::Channel.new(connection)
21
+ queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => false)
22
+ exchange = channel.direct("")
23
+
24
+ queue.subscribe do |payload|
25
+ puts "Received a message: #{payload}. Disconnecting..."
26
+
27
+ connection.close {
28
+ EM.stop { exit }
29
+ }
30
+ end
31
+
32
+ exchange.publish "1", :routing_key => queue.name, :app_id => "Hello world"
33
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+ puts "Running amqp gem #{AMQP::VERSION}"
12
+
13
+ EM.run do
14
+
15
+ AMQP.connect do |conn|
16
+ @amqp_connection = conn
17
+
18
+ AMQP::Channel.new(@amqp_connection) do |channel|
19
+ @amqp_channel = channel
20
+ @amqp_exchange = @amqp_channel.topic
21
+
22
+ EventMachine.add_periodic_timer(0) do
23
+ random_binary_string = Array.new(rand(1000)) { rand(256) }.pack('c*')
24
+ random_binary_string.force_encoding('BINARY')
25
+ p random_binary_string
26
+ @amqp_exchange.publish(random_binary_string, :routing_key => "a.my.pattern")
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+
12
+ puts
13
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
14
+ AMQP::Channel.new do |channel, open_ok|
15
+ puts "Channel ##{channel.id} is now open!"
16
+
17
+ channel.on_error do |ch, channel_close|
18
+ puts "channel.close = #{channel_close.inspect}"
19
+ puts "Handling a channel-level exception"
20
+ end
21
+
22
+ EventMachine.add_timer(0.4) do
23
+ # this one works
24
+ # binding = '12345678901234567890123456789012'
25
+
26
+ # this one does not work
27
+ binding = '123456789012345678901234567890123'
28
+ queue = channel.queue 'test', :auto_delete => true, :durable => false
29
+ queue.bind('amq.topic', :routing_key => binding)
30
+ queue.unbind('amq.topic', :routing_key => binding)
31
+ queue.unbind('amq.topic', :routing_key => binding)
32
+ end
33
+ end
34
+
35
+
36
+ show_stopper = Proc.new do
37
+ $stdout.puts "Stopping..."
38
+
39
+ connection.close {
40
+ EM.stop { exit }
41
+ }
42
+ end
43
+
44
+ Signal.trap "INT", show_stopper
45
+ EM.add_timer(2, show_stopper)
46
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+ puts "Running amqp gem #{AMQP::VERSION}"
12
+
13
+ AMQP.start(:host => "localhost") do |connection|
14
+ channel = AMQP::Channel.new(connection)
15
+ channel.fanout("logs.nad", :auto_delete => false)
16
+ channel.fanout("logs.ad", :auto_delete => true)
17
+
18
+ EM.add_timer(1) do
19
+ connection.close do
20
+ EM.stop { exit }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+ puts "Running amqp gem #{AMQP::VERSION}"
12
+
13
+
14
+
15
+ AMQP.start do |conn|
16
+ @amqp_connection = conn
17
+
18
+ AMQP::Channel.new(@amqp_connection) do |channel|
19
+ @amqp_channel = channel
20
+ @amqp_exchange = @amqp_channel.topic
21
+
22
+ AMQP::Queue.new(@amqp_channel, "") do |queue|
23
+ queue.bind(@amqp_exchange, :routing_key => "a.*.pattern").subscribe(:ack => true) do |header, payload|
24
+ p header.class
25
+ p header.to_hash
26
+
27
+ conn.close { EventMachine.stop }
28
+ end
29
+ end
30
+
31
+ EventMachine.add_timer(0.3) do
32
+ @amqp_exchange.publish "a message", :routing_key => "a.b.pattern"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "bundler"
5
+ Bundler.setup
6
+
7
+ $:.unshift(File.expand_path("../../../lib", __FILE__))
8
+
9
+ require 'amqp'
10
+
11
+ puts "Running amqp gem #{AMQP::VERSION}"
12
+
13
+
14
+ AMQP.start("amqp://guest:guest@localhost:5672") do |connection, open_ok|
15
+ channel = AMQP::Channel.new(connection)
16
+ channel.on_error { |ch, channel_close| puts "Error #{channel_close.inspect}" }
17
+ queue = channel.queue("reset_test", :auto_delete => false, :durable=>true)
18
+ exchange = channel.direct("foo")
19
+ queue.bind(exchange) { puts 'Got bind ok'}
20
+
21
+ EM.add_timer(2) do
22
+ channel.reset
23
+ queue = channel.queue("reset_test", :auto_delete => false, :durable=>true)
24
+ exchange = channel.direct("foo")
25
+ queue.unbind(exchange) { puts 'Got unbind ok'}
26
+ end
27
+
28
+ show_stopper = Proc.new do
29
+ $stdout.puts "Stopping..."
30
+
31
+ queue.delete
32
+ exchange.delete
33
+ connection.close {
34
+ EM.stop { exit }
35
+ }
36
+ end
37
+
38
+ Signal.trap "INT", show_stopper
39
+ EM.add_timer(4, show_stopper)
40
+ end