amqp 0.8.0.rc2 → 0.8.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.gitignore +2 -3
  2. data/.travis.yml +5 -2
  3. data/.yardopts +2 -0
  4. data/CHANGELOG +17 -20
  5. data/Gemfile +7 -5
  6. data/README.textile +67 -29
  7. data/Rakefile +6 -0
  8. data/amqp.gemspec +5 -5
  9. data/docs/08Migration.textile +27 -0
  10. data/docs/Bindings.textile +27 -0
  11. data/docs/ConnectingToTheBroker.textile +277 -0
  12. data/docs/DocumentationGuidesIndex.textile +25 -0
  13. data/docs/Durability.textile +27 -0
  14. data/docs/ErrorHandling.textile +84 -0
  15. data/docs/Exchanges.textile +27 -0
  16. data/docs/GettingStarted.textile +585 -0
  17. data/docs/Queues.textile +27 -0
  18. data/docs/RabbitMQVersions.textile +12 -2
  19. data/docs/Routing.textile +27 -0
  20. data/docs/TLS.textile +27 -0
  21. data/docs/VendorSpecificExtensions.textile +11 -1
  22. data/examples/{various → channels}/open_channel_without_assignment.rb +0 -4
  23. data/examples/channels/prefetch_as_constructor_argument.rb +31 -0
  24. data/examples/channels/qos_aka_prefetch.rb +34 -0
  25. data/examples/channels/qos_aka_prefetch_without_callback.rb +32 -0
  26. data/examples/error_handling/channel_level_exception.rb +47 -0
  27. data/examples/error_handling/channel_level_exception_with_multiple_channels_involved.rb +54 -0
  28. data/examples/error_handling/connection_loss_handler.rb +39 -0
  29. data/examples/error_handling/global_channel_level_exception_handler.rb +65 -0
  30. data/examples/error_handling/handling_authentication_failure_with_a_callback.rb +33 -0
  31. data/examples/error_handling/tcp_connection_failure_handling_with_a_rescue_block.rb +30 -0
  32. data/examples/error_handling/tcp_connection_failure_with_a_callback.rb +28 -0
  33. data/examples/{various → exchanges}/declare_an_exchange_without_assignment.rb +0 -4
  34. data/examples/guides/getting_started/01_hello_world.rb +24 -0
  35. data/examples/guides/getting_started/02_hello_world_dslified.rb +23 -0
  36. data/examples/guides/getting_started/03_babblr.rb +33 -0
  37. data/examples/guides/getting_started/04_weathr.rb +56 -0
  38. data/examples/hello_world.rb +12 -13
  39. data/examples/hello_world_with_eventmachine_in_a_separate_thread.rb +37 -0
  40. data/examples/{various → legacy}/ack.rb +0 -0
  41. data/examples/{various → legacy}/callbacks.rb +0 -0
  42. data/examples/{various → legacy}/clock.rb +0 -0
  43. data/examples/{various → legacy}/hashtable.rb +0 -0
  44. data/examples/{various → legacy}/logger.rb +0 -0
  45. data/examples/{various → legacy}/multiclock.rb +0 -0
  46. data/examples/{various → legacy}/pingpong.rb +0 -2
  47. data/examples/{various → legacy}/primes-simple.rb +0 -0
  48. data/examples/{various → legacy}/primes.rb +0 -2
  49. data/examples/{various → legacy}/stocks.rb +0 -0
  50. data/examples/{various → queues}/automatic_binding_for_default_direct_exchange.rb +4 -0
  51. data/examples/{various → queues}/basic_get.rb +0 -2
  52. data/examples/{various → queues}/declare_a_queue_without_assignment.rb +0 -4
  53. data/examples/queues/declare_and_bind_a_server_named_queue.rb +43 -0
  54. data/examples/{various → queues}/queue_status.rb +3 -8
  55. data/examples/{various → routing}/pubsub.rb +0 -0
  56. data/examples/{various → routing}/weather_updates.rb +1 -1
  57. data/lib/amqp/channel.rb +231 -52
  58. data/lib/amqp/client.rb +6 -3
  59. data/lib/amqp/connection.rb +9 -10
  60. data/lib/amqp/deprecated/fork.rb +3 -3
  61. data/lib/amqp/deprecated/logger.rb +1 -0
  62. data/lib/amqp/deprecated/mq.rb +23 -1
  63. data/lib/amqp/deprecated/rpc.rb +1 -0
  64. data/lib/amqp/exceptions.rb +45 -3
  65. data/lib/amqp/exchange.rb +29 -35
  66. data/lib/amqp/ext/em.rb +0 -7
  67. data/lib/amqp/ext/emfork.rb +3 -2
  68. data/lib/amqp/header.rb +4 -0
  69. data/lib/amqp/queue.rb +96 -33
  70. data/lib/amqp/session.rb +140 -0
  71. data/lib/amqp/version.rb +6 -1
  72. data/spec/integration/automatic_binding_for_default_direct_exchange_spec.rb +7 -7
  73. data/spec/integration/channel_level_exception_with_multiple_channels_spec.rb +69 -0
  74. data/spec/integration/declare_and_immediately_bind_a_server_named_queue_spec.rb +42 -0
  75. data/spec/integration/queue_declaration_spec.rb +8 -24
  76. data/spec/integration/queue_redeclaration_with_incompatible_attributes_spec.rb +43 -0
  77. data/spec/unit/amqp/connection_spec.rb +1 -1
  78. metadata +200 -182
  79. data/lib/amqp/basic_client.rb +0 -27
@@ -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
+
12
+ puts "=> TCP connection failure handling with a callback"
13
+ puts
14
+
15
+ handler = Proc.new { |settings| puts "Failed to connect, as expected"; EM.stop }
16
+ connection_settings = {
17
+ :port => 5672,
18
+ :vhost => "/amq_client_testbed",
19
+ :user => "amq_client_gem",
20
+ :password => "amq_client_gem_password_that_is_incorrect #{Time.now.to_i}",
21
+ :timeout => 0.3,
22
+ :on_tcp_connection_failure => handler,
23
+ :on_possible_authentication_failure => Proc.new { |settings|
24
+ puts "Authentication failed, as expected, settings are: #{settings.inspect}"
25
+
26
+ EM.stop
27
+ }
28
+ }
29
+
30
+
31
+ AMQP.start(connection_settings) do |connection, open_ok|
32
+ raise "This should not be reachable"
33
+ end
@@ -0,0 +1,30 @@
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 "=> TCP connection failure handling with a rescue statement"
13
+ puts
14
+
15
+ connection_settings = {
16
+ :port => 9689,
17
+ :vhost => "/amq_client_testbed",
18
+ :user => "amq_client_gem",
19
+ :password => "amq_client_gem_password",
20
+ :timeout => 0.3
21
+ }
22
+
23
+ begin
24
+ AMQP.start(connection_settings) do |connection, open_ok|
25
+ raise "This should not be reachable"
26
+ end
27
+ rescue AMQP::TCPConnectionFailed => e
28
+ puts "Caught AMQP::TCPConnectionFailed => TCP connection failed, as expected."
29
+ end
30
+
@@ -0,0 +1,28 @@
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 "=> TCP connection failure handling with a callback"
13
+ puts
14
+
15
+ handler = Proc.new { |settings| puts "Failed to connect, as expected"; EM.stop }
16
+ connection_settings = {
17
+ :port => 9689,
18
+ :vhost => "/amq_client_testbed",
19
+ :user => "amq_client_gem",
20
+ :password => "amq_client_gem_password",
21
+ :timeout => 0.3,
22
+ :on_tcp_connection_failure => handler
23
+ }
24
+
25
+
26
+ AMQP.start(connection_settings) do |connection, open_ok|
27
+ raise "This should not be reachable"
28
+ end
@@ -32,10 +32,6 @@ AMQP.start(:host => 'localhost') do |connection|
32
32
  show_stopper = Proc.new do
33
33
  $stdout.puts "Stopping..."
34
34
 
35
- # queue.purge :nowait => true
36
-
37
- # now change this to just EM.stop and it
38
- # unbinds instantly
39
35
  connection.close {
40
36
  EM.stop { exit }
41
37
  }
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ EventMachine.run do
8
+ connection = AMQP.connect(:host => '127.0.0.1')
9
+ puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
10
+
11
+ channel = AMQP::Channel.new(connection)
12
+ queue = channel.queue("amqpgem.examples.helloworld", :auto_delete => true)
13
+ exchange = channel.direct("")
14
+
15
+ queue.subscribe do |payload|
16
+ puts "Received a message: #{payload}. Disconnecting..."
17
+
18
+ connection.close {
19
+ EM.stop { exit }
20
+ }
21
+ end
22
+
23
+ exchange.publish "Hello, world!", :routing_key => queue.name
24
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ EventMachine.run do
8
+ AMQP.connect(:host => '127.0.0.1') do |connection|
9
+ puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
10
+
11
+ channel = AMQP::Channel.new(connection)
12
+
13
+ channel.queue("amqpgem.examples.helloworld", :auto_delete => true).subscribe do |payload|
14
+ puts "Received a message: #{payload}. Disconnecting..."
15
+
16
+ connection.close {
17
+ EM.stop { exit }
18
+ }
19
+ end
20
+
21
+ channel.direct("").publish "Hello, world!", :routing_key => queue.name
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ AMQP.start("amqp://dev.rabbitmq.com:5672/") do |connection|
8
+ channel = AMQP::Channel.new(connection)
9
+ exchange = channel.fanout("nba.scores")
10
+
11
+ channel.queue("joe", :auto_delete => true).bind(exchange).subscribe do |payload|
12
+ puts "#{payload} => joe"
13
+ end
14
+
15
+ channel.queue("aaron", :auto_delete => true).bind(exchange).subscribe do |payload|
16
+ puts "#{payload} => aaron"
17
+ end
18
+
19
+ channel.queue("bob", :auto_delete => true).bind(exchange).subscribe do |payload|
20
+ puts "#{payload} => bob"
21
+ end
22
+
23
+ exchange.publish("BOS 101, NYK 89").publish("ORL 85, ALT 88")
24
+
25
+ # disconnect & exit after 1 second
26
+ EventMachine.add_timer(1) do
27
+ exchange.delete
28
+
29
+ connection.close {
30
+ EM.stop { exit }
31
+ }
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "rubygems"
5
+ require "amqp"
6
+
7
+ EventMachine.run do
8
+ AMQP.connect do |connection|
9
+ channel = AMQP::Channel.new(connection)
10
+ exchange = channel.topic("pub/sub", :auto_delete => true)
11
+
12
+ # Subscribers.
13
+ channel.queue("", :exclusive => true) do |queue|
14
+ queue.bind(exchange, :routing_key => "americas.north.#").subscribe do |headers, payload|
15
+ puts "An update for North America: #{payload}, routing key is #{headers.routing_key}"
16
+ end
17
+ end
18
+ channel.queue("americas.south").bind(exchange, :routing_key => "americas.south.#").subscribe do |headers, payload|
19
+ puts "An update for South America: #{payload}, routing key is #{headers.routing_key}"
20
+ end
21
+ channel.queue("us.california").bind(exchange, :routing_key => "americas.north.us.ca.*").subscribe do |headers, payload|
22
+ puts "An update for US/California: #{payload}, routing key is #{headers.routing_key}"
23
+ end
24
+ channel.queue("us.tx.austin").bind(exchange, :routing_key => "#.tx.austin").subscribe do |headers, payload|
25
+ puts "An update for Austin, TX: #{payload}, routing key is #{headers.routing_key}"
26
+ end
27
+ channel.queue("it.rome").bind(exchange, :routing_key => "europe.italy.rome").subscribe do |headers, payload|
28
+ puts "An update for Rome, Italy: #{payload}, routing key is #{headers.routing_key}"
29
+ end
30
+ channel.queue("asia.hk").bind(exchange, :routing_key => "asia.southeast.hk.#").subscribe do |headers, payload|
31
+ puts "An update for Hong Kong: #{payload}, routing key is #{headers.routing_key}"
32
+ end
33
+
34
+ EM.add_timer(1) do
35
+ exchange.publish("San Diego update", :routing_key => "americas.north.us.ca.sandiego").
36
+ publish("Berkeley update", :routing_key => "americas.north.us.ca.berkeley").
37
+ publish("San Francisco update", :routing_key => "americas.north.us.ca.sanfrancisco").
38
+ publish("New York update", :routing_key => "americas.north.us.ny.newyork").
39
+ publish("São Paolo update", :routing_key => "americas.south.brazil.saopaolo").
40
+ publish("Hong Kong update", :routing_key => "asia.southeast.hk.hongkong").
41
+ publish("Kyoto update", :routing_key => "asia.southeast.japan.kyoto").
42
+ publish("Shanghai update", :routing_key => "asia.southeast.prc.shanghai").
43
+ publish("Rome update", :routing_key => "europe.italy.roma").
44
+ publish("Paris update", :routing_key => "europe.france.paris")
45
+ end
46
+
47
+
48
+ show_stopper = Proc.new {
49
+ connection.close do
50
+ EM.stop
51
+ end
52
+ }
53
+
54
+ EM.add_timer(2, show_stopper)
55
+ end
56
+ end
@@ -9,21 +9,20 @@ $:.unshift(File.expand_path("../../lib", __FILE__))
9
9
  require 'amqp'
10
10
 
11
11
  EventMachine.run do
12
- AMQP.connect(:host => 'localhost') do |connection|
13
- puts "Connected to AMQP broker"
12
+ connection = AMQP.connect(:host => '127.0.0.1')
13
+ puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
14
14
 
15
- channel = AMQP::Channel.new(connection)
16
- queue = channel.queue("amqpgem.examples.hello_world")
17
- exchange = channel.default_exchange
15
+ channel = AMQP::Channel.new(connection)
16
+ queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
17
+ exchange = channel.direct("")
18
18
 
19
- queue.subscribe do |payload|
20
- puts "Received a message: #{payload}. Disconnecting..."
19
+ queue.subscribe do |payload|
20
+ puts "Received a message: #{payload}. Disconnecting..."
21
21
 
22
- connection.close {
23
- EM.stop { exit }
24
- }
25
- end
22
+ connection.close {
23
+ EM.stop { exit }
24
+ }
25
+ end
26
26
 
27
- exchange.publish "Hello, world!", :routing_key => queue.name
28
- end
27
+ exchange.publish "Hello, world!", :routing_key => queue.name
29
28
  end
@@ -0,0 +1,37 @@
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
+ t = Thread.new { EventMachine.run }
12
+ if defined?(JRUBY_VERSION)
13
+ # on the JVM, event loop startup takes longer and .next_tick behavior
14
+ # seem to be a bit different. Blocking current thread for a moment helps.
15
+ sleep 0.5
16
+ end
17
+
18
+ EventMachine.next_tick {
19
+ connection = AMQP.connect(:host => '127.0.0.1')
20
+ puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
21
+
22
+ channel = AMQP::Channel.new(connection)
23
+ queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
24
+ exchange = channel.direct("")
25
+
26
+ queue.subscribe do |payload|
27
+ puts "Received a message: #{payload}. Disconnecting..."
28
+
29
+ connection.close {
30
+ EM.stop { exit }
31
+ }
32
+ end
33
+
34
+ exchange.publish "Hello, world!", :routing_key => queue.name
35
+ }
36
+
37
+ t.join
File without changes
File without changes
File without changes
@@ -38,8 +38,6 @@ AMQP.start(:host => 'localhost') do |connection|
38
38
 
39
39
  show_stopper = Proc.new do
40
40
  $stdout.puts "Stopping..."
41
- # now change this to just EM.stop and it
42
- # unbinds instantly
43
41
  connection.close {
44
42
  EM.stop { exit }
45
43
  }
@@ -46,8 +46,6 @@ AMQP.start(:host => 'localhost') do |connection|
46
46
 
47
47
  show_stopper = Proc.new do
48
48
  $stdout.puts "Stopping..."
49
- # now change this to just EM.stop and it
50
- # unbinds instantly
51
49
  connection.close {
52
50
  EM.stop { exit }
53
51
  }
File without changes
@@ -41,6 +41,10 @@ AMQP.start(:host => 'localhost') do |connection|
41
41
 
42
42
 
43
43
  show_stopper = Proc.new do
44
+ queue1.delete
45
+ queue2.delete
46
+ queue3.delete
47
+
44
48
  $stdout.puts "Stopping..."
45
49
  connection.close {
46
50
  EM.stop { exit }
@@ -53,8 +53,6 @@ AMQP.start(:host => 'localhost') do |connection|
53
53
 
54
54
  show_stopper = Proc.new do
55
55
  $stdout.puts "Stopping..."
56
- # now change this to just EM.stop and it
57
- # unbinds instantly
58
56
  connection.close {
59
57
  EM.stop { exit }
60
58
  }
@@ -32,10 +32,6 @@ AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672/") do |connection, open_ok|
32
32
  show_stopper = Proc.new do
33
33
  $stdout.puts "Stopping..."
34
34
 
35
- # queue.purge :nowait => true
36
-
37
- # now change this to just EM.stop and it
38
- # unbinds instantly
39
35
  connection.close {
40
36
  EM.stop { exit }
41
37
  }
@@ -0,0 +1,43 @@
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 "=> Queue#initialize example that uses a block"
13
+ puts
14
+ AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672/") do |connection, open_ok|
15
+ AMQP::Channel.new do |channel, open_ok|
16
+ puts "Channel ##{channel.id} is now open!" if channel.open?
17
+
18
+ xchange = channel.fanout("amq.fanout", :nowait => true)
19
+ q = AMQP::Queue.new(channel, "", :auto_delete => true)
20
+
21
+
22
+ EM.add_timer(0.5) do
23
+ puts "Channel ##{channel.id} is still open!" if channel.open?
24
+ q.bind(xchange).subscribe do |header, payload|
25
+ puts "Got a payload: #{payload}"
26
+ end
27
+
28
+ EventMachine.add_timer(0.3) { xchange.publish("à bientôt!") }
29
+ end
30
+ end
31
+
32
+
33
+ show_stopper = Proc.new do
34
+ $stdout.puts "Stopping..."
35
+
36
+ connection.close {
37
+ EM.stop { exit }
38
+ }
39
+ end
40
+
41
+ Signal.trap "INT", show_stopper
42
+ EM.add_timer(2, show_stopper)
43
+ end
@@ -19,12 +19,12 @@ puts "=> Queue#status example"
19
19
  puts
20
20
  AMQP.start(:host => 'localhost') do |connection|
21
21
  channel = AMQP::Channel.new
22
-
22
+
23
23
  queue_name = "amqpgem.integration.queue.status.queue"
24
-
24
+
25
25
  exchange = channel.fanout("amqpgem.integration.queue.status.fanout", :auto_delete => true)
26
26
  queue = channel.queue(queue_name, :auto_delete => true)
27
-
27
+
28
28
  queue.bind(exchange) do
29
29
  puts "Bound #{exchange.name} => #{queue.name}"
30
30
  end
@@ -43,11 +43,6 @@ AMQP.start(:host => 'localhost') do |connection|
43
43
 
44
44
  show_stopper = Proc.new do
45
45
  $stdout.puts "Stopping..."
46
-
47
- # queue.purge :nowait => true
48
-
49
- # now change this to just EM.stop and it
50
- # unbinds instantly
51
46
  connection.close {
52
47
  EM.stop { exit }
53
48
  }