amqp 1.0.0.pre2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.travis.yml +3 -0
  2. data/README.md +80 -72
  3. data/amqp.gemspec +5 -13
  4. data/docs/08Migration.textile +4 -0
  5. data/docs/AMQP091ModelExplained.textile +6 -1
  6. data/docs/Bindings.textile +4 -0
  7. data/docs/Clustering.textile +4 -0
  8. data/docs/ConnectingToTheBroker.textile +4 -0
  9. data/docs/ConnectionEncryptionWithTLS.textile +4 -0
  10. data/docs/DocumentationGuidesIndex.textile +4 -0
  11. data/docs/Durability.textile +4 -0
  12. data/docs/ErrorHandling.textile +4 -0
  13. data/docs/Exchanges.textile +4 -0
  14. data/docs/GettingStarted.textile +4 -0
  15. data/docs/PatternsAndUseCases.textile +4 -1
  16. data/docs/Queues.textile +4 -0
  17. data/docs/RabbitMQVersions.textile +4 -0
  18. data/docs/RunningTests.textile +4 -0
  19. data/docs/TestingWithEventedSpec.textile +4 -0
  20. data/docs/Troubleshooting.textile +4 -0
  21. data/docs/VendorSpecificExtensions.textile +4 -0
  22. data/examples/error_handling/automatic_recovery_of_channel_and_queues.rb +1 -1
  23. data/examples/error_handling/automatically_recovering_hello_world_consumer.rb +1 -1
  24. data/examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb +1 -1
  25. data/examples/error_handling/connection_level_exception.rb +1 -1
  26. data/examples/error_handling/connection_level_exception_with_objects.rb +1 -1
  27. data/examples/error_handling/connection_loss_handler.rb +4 -3
  28. data/examples/error_handling/hello_world_producer.rb +1 -1
  29. data/examples/error_handling/manual_connection_and_channel_recovery.rb +1 -1
  30. data/examples/extensions/rabbitmq/publisher_confirmations_with_transient_messages.rb +1 -1
  31. data/examples/extensions/rabbitmq/using_alternate_exchanges.rb +1 -1
  32. data/examples/guides/getting_started/01_hello_world.rb +1 -1
  33. data/examples/guides/getting_started/02_hello_world_dslified.rb +1 -1
  34. data/examples/hello_world.rb +1 -1
  35. data/examples/hello_world_with_an_empty_string.rb +1 -1
  36. data/examples/hello_world_with_eventmachine_in_a_separate_thread.rb +2 -2
  37. data/examples/hello_world_with_large_payload.rb +41 -41
  38. data/examples/patterns/request_reply/client.rb +1 -2
  39. data/examples/patterns/request_reply/server.rb +0 -1
  40. data/examples/publishing/returned_messages.rb +1 -1
  41. data/examples/queues/accessing_message_metadata.rb +1 -1
  42. data/examples/queues/cancel_default_consumer.rb +1 -1
  43. data/lib/amqp/channel.rb +34 -16
  44. data/lib/amqp/client.rb +2 -2
  45. data/lib/amqp/connection.rb +2 -1
  46. data/lib/amqp/consumer.rb +2 -2
  47. data/lib/amqp/exceptions.rb +11 -2
  48. data/lib/amqp/exchange.rb +5 -5
  49. data/lib/amqp/queue.rb +51 -26
  50. data/lib/amqp/session.rb +5 -5
  51. data/lib/amqp/version.rb +1 -1
  52. data/spec/integration/basic_get_spec.rb +82 -27
  53. data/spec/integration/basic_return_spec.rb +3 -3
  54. data/spec/integration/channel_level_exception_with_multiple_channels_spec.rb +0 -1
  55. data/spec/integration/exchange_declaration_spec.rb +71 -102
  56. data/spec/integration/extensions/rabbitmq/publisher_confirmations_spec.rb +1 -1
  57. data/spec/integration/fanout_exchange_routing_spec.rb +1 -1
  58. data/spec/integration/multiple_consumers_per_queue_spec.rb +3 -160
  59. data/spec/integration/queue_redeclaration_with_incompatible_attributes_spec.rb +25 -12
  60. data/spec/integration/regressions/concurrent_publishing_on_the_same_channel_spec.rb +1 -1
  61. data/spec/integration/remove_individual_binding_spec.rb +51 -0
  62. data/spec/integration/reply_queue_communication_spec.rb +1 -2
  63. data/spec/integration/store_and_forward_spec.rb +6 -9
  64. data/spec/integration/topic_subscription_spec.rb +5 -4
  65. data/spec/spec_helper.rb +8 -2
  66. data/spec/unit/amqp/connection_spec.rb +3 -1
  67. metadata +93 -109
  68. data/spec/integration/immediate_messages_spec.rb +0 -59
@@ -2,6 +2,10 @@
2
2
 
3
3
  h1. Working with exchanges
4
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
5
9
 
6
10
  h2. About this guide
7
11
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  h1. Getting started with the Ruby amqp gem
4
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
5
9
 
6
10
  h2. About this guide
7
11
 
@@ -1,8 +1,11 @@
1
1
  # @title Ruby AMQP gem: Patterns and Use Cases
2
2
 
3
-
4
3
  h1. Patterns and Use Cases
5
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
6
9
 
7
10
  h2. About this guide
8
11
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  h1. Working with queues
4
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
5
9
 
6
10
  h2. About this guide
7
11
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  h1. Ruby amqp gem and RabbitMQ versions compatibility
4
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
5
9
  h2. About this guide
6
10
 
7
11
  This guide covers compatibility of the "Ruby amqp gem":http://github.com/ruby-amqp/amqp with various versions of "RabbitMQ":http://rabbitmq.com messaging broker.
@@ -2,6 +2,10 @@
2
2
 
3
3
  h1. Running amqp gem test suite
4
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
5
9
 
6
10
  h2. About this guide
7
11
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  h1. Testing AMQP applications
4
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
5
9
  h2. About this guide
6
10
 
7
11
  This guide covers unit testing of amqp-based applications, primarily using "evented-spec":http://github.com/ruby-amqp/evented-spec.
@@ -2,6 +2,10 @@
2
2
 
3
3
  h1. Troubleshooting and debugging AMQP applications
4
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
5
9
 
6
10
  h2. About this guide
7
11
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  h1. Vendor-specific AMQP extensions support in amqp gem
4
4
 
5
+ h2. This Documentation Has Moved to rubyamqp.info
6
+
7
+ amqp gem documentation guides are now hosted on "rubyamqp.info":http://rubyamqp.info.
8
+
5
9
  h2. RabbitMQ extensions
6
10
 
7
11
  h2. Supported extensions
@@ -46,5 +46,5 @@ AMQP.start(:host => "localhost") do |connection, open_ok|
46
46
  EM.add_timer(30, show_stopper)
47
47
 
48
48
 
49
- 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."
49
+ puts "Connected, authenticated. To really exercise this example, shut RabbitMQ down for a few seconds. If you don't it will exit gracefully in 30 seconds."
50
50
  end
@@ -47,5 +47,5 @@ AMQP.start(:host => ENV.fetch("BROKER_HOST", "localhost")) do |connection, open_
47
47
 
48
48
 
49
49
  puts "This example needs another script/app to publish messages to amq.fanout. See examples/error_handling/hello_world_producer.rb for example"
50
- 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 45 seconds."
50
+ puts "Connected, authenticated. To really exercise this example, shut RabbitMQ down for a few seconds. If you don't it will exit gracefully in 45 seconds."
51
51
  end
@@ -47,5 +47,5 @@ AMQP.start(:host => "localhost") do |connection, open_ok|
47
47
 
48
48
 
49
49
  puts "This example needs another script/app to publish messages to amq.fanout. See examples/error_handling/hello_world_producer.rb for example"
50
- 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 45 seconds."
50
+ puts "Connected, authenticated. To really exercise this example, shut RabbitMQ down for a few seconds. If you don't it will exit gracefully in 45 seconds."
51
51
  end
@@ -10,7 +10,7 @@ require 'amqp'
10
10
 
11
11
  EventMachine.run do
12
12
  AMQP.connect(:host => '127.0.0.1', :port => 5672) do |connection|
13
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
13
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
14
14
 
15
15
 
16
16
  connection.on_error do |conn, connection_close|
@@ -37,7 +37,7 @@ end
37
37
  EventMachine.run do
38
38
  manager = ConnectionManager.new
39
39
  manager.connect(:host => '127.0.0.1', :port => 5672) do |connection|
40
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
40
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
41
41
 
42
42
  # send_frame is NOT part of the public API, but it is public for entities like AMQ::Client::Channel
43
43
  # and we use it here to trigger a connection-level exception. MK.
@@ -15,7 +15,8 @@ AMQP.start(:port => 5672,
15
15
  :vhost => "amq_client_testbed",
16
16
  :user => "amq_client_gem",
17
17
  :password => "amq_client_gem_password",
18
- :timeout => 0.3,
18
+ :timeout => 0.3,
19
+ :heartbeat => 1.0,
19
20
  :on_tcp_connection_failure => Proc.new { |settings| puts "Failed to connect, this was NOT expected"; EM.stop }) do |connection, open_ok|
20
21
  connection.on_tcp_connection_loss do |cl, settings|
21
22
  puts "tcp_connection_loss handler kicks in"
@@ -28,8 +29,8 @@ AMQP.start(:port => 5672,
28
29
  connection.close { EventMachine.stop }
29
30
  end
30
31
 
31
- 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."
32
+ puts "Connected, authenticated. To really exercise this example, shut RabbitMQ down for a few seconds. If you don't it will exit gracefully in 30 seconds."
32
33
 
33
34
  Signal.trap "INT", show_stopper
34
- EM.add_timer(30, show_stopper)
35
+ EM.add_timer(60, show_stopper)
35
36
  end
@@ -39,7 +39,7 @@ AMQP.start(:host => ENV.fetch("BROKER_HOST", "localhost")) do |connection, open_
39
39
  EventMachine.add_periodic_timer(0.8) do
40
40
  puts "Publishing via amq.fanout..."
41
41
  # messages must be routable & there must be at least one consumer.
42
- exchange.publish("Routed via amq.fanout", :immediate => true, :mandatory => true)
42
+ exchange.publish("Routed via amq.fanout", :mandatory => true)
43
43
  end
44
44
 
45
45
 
@@ -67,5 +67,5 @@ AMQP.start(:host => "localhost") do |connection, open_ok|
67
67
  EM.add_timer(30, show_stopper)
68
68
 
69
69
 
70
- 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."
70
+ puts "Connected, authenticated. To really exercise this example, shut RabbitMQ down for a few seconds. If you don't it will exit gracefully in 30 seconds."
71
71
  end
@@ -10,7 +10,7 @@ require "amqp/extensions/rabbitmq"
10
10
 
11
11
  EventMachine.run do
12
12
  connection = AMQP.connect(:host => '127.0.0.1')
13
- puts "Connecting to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
13
+ puts "Connecting to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
14
14
 
15
15
  AMQP::Channel.new(connection) do |channel|
16
16
  puts "Channel #{channel.id} is now open"
@@ -10,7 +10,7 @@ require 'amqp'
10
10
 
11
11
  EventMachine.run do
12
12
  connection = AMQP.connect(:host => '127.0.0.1')
13
- puts "Connecting to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
13
+ puts "Connecting to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
14
14
 
15
15
  channel = AMQP::Channel.new(connection)
16
16
  queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
@@ -6,7 +6,7 @@ require "amqp"
6
6
 
7
7
  EventMachine.run do
8
8
  connection = AMQP.connect(:host => '127.0.0.1')
9
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
9
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
10
10
 
11
11
  channel = AMQP::Channel.new(connection)
12
12
  queue = channel.queue("amqpgem.examples.helloworld", :auto_delete => true)
@@ -6,7 +6,7 @@ require "amqp"
6
6
 
7
7
  EventMachine.run do
8
8
  AMQP.connect(:host => '127.0.0.1') do |connection|
9
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
9
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
10
10
 
11
11
  channel = AMQP::Channel.new(connection)
12
12
 
@@ -10,7 +10,7 @@ require 'amqp'
10
10
 
11
11
  EventMachine.run do
12
12
  connection = AMQP.connect(:host => '127.0.0.1')
13
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
13
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
14
14
 
15
15
  channel = AMQP::Channel.new(connection)
16
16
  queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
@@ -10,7 +10,7 @@ require 'amqp'
10
10
 
11
11
  EventMachine.run do
12
12
  connection = AMQP.connect(:host => '127.0.0.1')
13
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
13
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
14
14
 
15
15
 
16
16
  connection.on_error do |conn, connection_close|
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  EventMachine.next_tick {
19
19
  connection = AMQP.connect(:host => '127.0.0.1')
20
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
20
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
21
21
 
22
22
  channel = AMQP::Channel.new(connection)
23
23
  queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
@@ -34,4 +34,4 @@ EventMachine.next_tick {
34
34
  exchange.publish "Hello, world!", :routing_key => queue.name
35
35
  }
36
36
 
37
- t.join
37
+ t.join
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  EventMachine.next_tick {
19
19
  connection = AMQP.connect(:host => '127.0.0.1')
20
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
20
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
21
21
 
22
22
  channel = AMQP::Channel.new(connection)
23
23
  queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
@@ -62,31 +62,31 @@ EventMachine.next_tick {
62
62
  A TCP segment consists of a segment header and a data section. The TCP header contains 10 mandatory fields, and an optional extension field (Options, pink background in table).
63
63
 
64
64
  The data section follows the header. Its contents are the payload data carried for the application. The length of the data section is not specified in the TCP segment header. It can be calculated by subtracting the combined length of the TCP header and the encapsulating IP segment header from the total IP segment length (specified in the IP segment header).
65
- TCP Header Bit offset 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
66
- 0 Source port Destination port
67
- 32 Sequence number
68
- 64 Acknowledgment number (if ACK set)
69
- 96 Data offset Reserved C
65
+ TCP Header Bit offset 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
66
+ 0 Source port Destination port
67
+ 32 Sequence number
68
+ 64 Acknowledgment number (if ACK set)
69
+ 96 Data offset Reserved C
70
70
  W
71
- R E
71
+ R E
72
72
  C
73
- E U
73
+ E U
74
74
  R
75
- G A
75
+ G A
76
76
  C
77
- K P
77
+ K P
78
78
  S
79
- H R
79
+ H R
80
80
  S
81
- T S
81
+ T S
82
82
  Y
83
- N F
83
+ N F
84
84
  I
85
- N Window Size
86
- 128 Checksum Urgent pointer (if URG set)
85
+ N Window Size
86
+ 128 Checksum Urgent pointer (if URG set)
87
87
  160
88
- ... Options (if Data Offset > 5)
89
- ... padding
88
+ ... Options (if Data Offset > 5)
89
+ ... padding
90
90
 
91
91
  Source port (16 bits) – identifies the sending port
92
92
  Destination port (16 bits) – identifies the receiving port
@@ -337,17 +337,17 @@ EventMachine.next_tick {
337
337
  The checksum field is the 16 bit one's complement of the one's complement sum of all 16-bit words in the header and text. If a segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a 16-bit word for checksum purposes. The pad is not transmitted as part of the segment. While computing the checksum, the checksum field itself is replaced with zeros.
338
338
 
339
339
  In other words, after appropriate padding, all 16-bit words are added using one's complement arithmetic. The sum is then bitwise complemented and inserted as the checksum field. A pseudo-header that mimics the IPv4 packet header used in the checksum computation is shown in the table below.
340
- TCP pseudo-header (IPv4) Bit offset 0–3 4–7 8–15 16–31
341
- 0 Source address
342
- 32 Destination address
343
- 64 Zeros Protocol TCP length
344
- 96 Source port Destination port
345
- 128 Sequence number
346
- 160 Acknowledgement number
347
- 192 Data offset Reserved Flags Window
348
- 224 Checksum Urgent pointer
349
- 256 Options (optional)
350
- 256/288+
340
+ TCP pseudo-header (IPv4) Bit offset 0–3 4–7 8–15 16–31
341
+ 0 Source address
342
+ 32 Destination address
343
+ 64 Zeros Protocol TCP length
344
+ 96 Source port Destination port
345
+ 128 Sequence number
346
+ 160 Acknowledgement number
347
+ 192 Data offset Reserved Flags Window
348
+ 224 Checksum Urgent pointer
349
+ 256 Options (optional)
350
+ 256/288+
351
351
  Data
352
352
 
353
353
 
@@ -359,24 +359,24 @@ EventMachine.next_tick {
359
359
  Any transport or other upper-layer protocol that includes the addresses from the IP header in its checksum computation must be modified for use over IPv6, to include the 128-bit IPv6 addresses instead of 32-bit IPv4 addresses.
360
360
 
361
361
  A pseudo-header that mimics the IPv6 header for computation of the checksum is shown below.
362
- TCP pseudo-header (IPv6) Bit offset 0 - 7 8–15 16–23 24–31
363
- 0 Source address
362
+ TCP pseudo-header (IPv6) Bit offset 0 - 7 8–15 16–23 24–31
363
+ 0 Source address
364
364
  32
365
365
  64
366
366
  96
367
- 128 Destination address
367
+ 128 Destination address
368
368
  160
369
369
  192
370
370
  224
371
- 256 TCP length
372
- 288 Zeros Next header
373
- 320 Source port Destination port
374
- 352 Sequence number
375
- 384 Acknowledgement number
376
- 416 Data offset Reserved Flags Window
377
- 448 Checksum Urgent pointer
378
- 480 Options (optional)
379
- 480/512+
371
+ 256 TCP length
372
+ 288 Zeros Next header
373
+ 320 Source port Destination port
374
+ 352 Sequence number
375
+ 384 Acknowledgement number
376
+ 416 Data offset Reserved Flags Window
377
+ 448 Checksum Urgent pointer
378
+ 480 Options (optional)
379
+ 480/512+
380
380
  Data
381
381
 
382
382
 
@@ -396,4 +396,4 @@ EventMachine.next_tick {
396
396
  exchange.publish(payload, :routing_key => queue.name)
397
397
  }
398
398
 
399
- t.join
399
+ t.join
@@ -19,8 +19,7 @@ EventMachine.run do
19
19
  channel.default_exchange.publish("get.time",
20
20
  :routing_key => "amqpgem.examples.services.time",
21
21
  :message_id => Kernel.rand(10101010).to_s,
22
- :reply_to => replies_queue.name,
23
- :immediate => true)
22
+ :reply_to => replies_queue.name)
24
23
  end
25
24
 
26
25
 
@@ -14,7 +14,6 @@ EventMachine.run do
14
14
  channel.default_exchange.publish(Time.now.to_s,
15
15
  :routing_key => metadata.reply_to,
16
16
  :correlation_id => metadata.message_id,
17
- :immediate => true,
18
17
  :mandatory => true)
19
18
 
20
19
  metadata.ack
@@ -22,7 +22,7 @@ AMQP.start(:host => '127.0.0.1') do |connection|
22
22
 
23
23
  EventMachine.add_timer(0.3) {
24
24
  10.times do |i|
25
- exchange.publish("Message ##{i}", :immediate => true)
25
+ exchange.publish("Message ##{i}")
26
26
  end
27
27
  }
28
28
 
@@ -10,7 +10,7 @@ require 'amqp'
10
10
 
11
11
  EventMachine.run do
12
12
  connection = AMQP.connect(:host => '127.0.0.1')
13
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
13
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
14
14
 
15
15
  channel = AMQP::Channel.new(connection)
16
16
  queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
@@ -10,7 +10,7 @@ require 'amqp'
10
10
 
11
11
  EventMachine.run do
12
12
  connection = AMQP.connect(:host => '127.0.0.1')
13
- puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
13
+ puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."
14
14
 
15
15
  channel = AMQP::Channel.new(connection)
16
16
  queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
@@ -7,7 +7,7 @@ require "amqp/queue"
7
7
  module AMQP
8
8
  # h2. What are AMQP channels
9
9
  #
10
- # To quote {http://bit.ly/hw2ELX AMQP 0.9.1 specification}:
10
+ # To quote {http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification}:
11
11
  #
12
12
  # AMQP is a multi-channelled protocol. Channels provide a way to multiplex
13
13
  # a heavyweight TCP/IP connection into several light weight connections.
@@ -137,10 +137,10 @@ module AMQP
137
137
  #
138
138
  # h2. RabbitMQ extensions.
139
139
  #
140
- # AMQP gem supports several RabbitMQ extensions taht extend Channel functionality.
140
+ # AMQP gem supports several RabbitMQ extensions that extend Channel functionality.
141
141
  # Learn more in {file:docs/VendorSpecificExtensions.textile}
142
142
  #
143
- # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.2.5)
143
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.2.5)
144
144
  class Channel < AMQ::Client::Channel
145
145
 
146
146
  #
@@ -263,6 +263,9 @@ module AMQP
263
263
  def auto_recover
264
264
  return unless auto_recovering?
265
265
 
266
+ @channel_is_open_deferrable.fail
267
+ @channel_is_open_deferrable = AMQ::Client::EventMachineClient::Deferrable.new
268
+
266
269
  self.open do
267
270
  @channel_is_open_deferrable.succeed
268
271
 
@@ -286,6 +289,9 @@ module AMQP
286
289
  @id = self.class.next_channel_id
287
290
  self.class.release_channel_id(old_id)
288
291
 
292
+ @channel_is_open_deferrable.fail
293
+ @channel_is_open_deferrable = AMQ::Client::EventMachineClient::Deferrable.new
294
+
289
295
  self.open do
290
296
  @channel_is_open_deferrable.succeed
291
297
 
@@ -373,7 +379,7 @@ module AMQP
373
379
  # @see Channel#default_exchange
374
380
  # @see Exchange
375
381
  # @see Exchange#initialize
376
- # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3.1)
382
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3.1)
377
383
  #
378
384
  # @return [Exchange]
379
385
  # @api public
@@ -426,7 +432,7 @@ module AMQP
426
432
  #
427
433
  #
428
434
  # @see Exchange
429
- # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.1.2.4)
435
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.2.4)
430
436
  #
431
437
  # @return [Exchange]
432
438
  # @api public
@@ -481,7 +487,7 @@ module AMQP
481
487
  # @see Exchange
482
488
  # @see Exchange#initialize
483
489
  # @see Channel#default_exchange
484
- # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3.2)
490
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3.2)
485
491
  #
486
492
  # @return [Exchange]
487
493
  # @api public
@@ -597,7 +603,7 @@ module AMQP
597
603
  # @see Exchange
598
604
  # @see Exchange#initialize
599
605
  # @see http://www.rabbitmq.com/faq.html#Binding-and-Routing RabbitMQ FAQ on routing & wildcards
600
- # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3.3)
606
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3.3)
601
607
  #
602
608
  # @return [Exchange]
603
609
  # @api public
@@ -703,7 +709,7 @@ module AMQP
703
709
  # @see Exchange
704
710
  # @see Exchange#initialize
705
711
  # @see Channel#default_exchange
706
- # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3.3)
712
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3.3)
707
713
  #
708
714
  # @return [Exchange]
709
715
  # @api public
@@ -804,7 +810,7 @@ module AMQP
804
810
  #
805
811
  # @see Queue
806
812
  # @see Queue#initialize
807
- # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.1.4)
813
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.4)
808
814
  #
809
815
  # @return [Queue]
810
816
  # @api public
@@ -929,16 +935,27 @@ module AMQP
929
935
  #
930
936
  # @api public
931
937
  def once_open(&block)
932
- @channel_is_open_deferrable.callback(&block)
938
+ @channel_is_open_deferrable.callback do
939
+ # guards against cases when deferred operations
940
+ # don't complete before the channel is closed
941
+ block.call if open?
942
+ end
933
943
  end # once_open(&block)
934
944
  alias once_opened once_open
935
945
 
946
+ # @return [Boolean]
947
+ # @api public
948
+ def closing?
949
+ self.status == :closing
950
+ end
951
+
936
952
  # Closes AMQP channel.
937
953
  #
938
954
  # @api public
939
955
  def close(reply_code = 200, reply_text = DEFAULT_REPLY_TEXT, class_id = 0, method_id = 0, &block)
956
+ self.status = :closing
940
957
  r = super(reply_code, reply_text, class_id, method_id, &block)
941
-
958
+
942
959
  r
943
960
  end
944
961
 
@@ -957,7 +974,7 @@ module AMQP
957
974
  #
958
975
  # @param [Boolean] Desired flow state.
959
976
  #
960
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.5.2.3.)
977
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.5.2.3.)
961
978
  # @api public
962
979
  def flow(active = false, &block)
963
980
  super(active, &block)
@@ -998,7 +1015,7 @@ module AMQP
998
1015
  # @api public
999
1016
  # @see #reject
1000
1017
  # @see #recover
1001
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.13.)
1018
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.8.3.13.)
1002
1019
  def acknowledge(delivery_tag, multiple = false)
1003
1020
  super(delivery_tag, multiple)
1004
1021
  end # acknowledge(delivery_tag, multiple = false)
@@ -1008,7 +1025,7 @@ module AMQP
1008
1025
  # @api public
1009
1026
  # @see #acknowledge
1010
1027
  # @see #recover
1011
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.14.)
1028
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.8.3.14.)
1012
1029
  def reject(delivery_tag, requeue = true)
1013
1030
  super(delivery_tag, requeue)
1014
1031
  end # reject(delivery_tag, requeue = true)
@@ -1019,7 +1036,7 @@ module AMQP
1019
1036
  # @return [Channel] self
1020
1037
  #
1021
1038
  # @note RabbitMQ as of 2.3.1 does not support basic.recover with requeue = false.
1022
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.16.)
1039
+ # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.8.3.16.)
1023
1040
  # @see #acknowledge
1024
1041
  # @api public
1025
1042
  def recover(requeue = true, &block)
@@ -1120,8 +1137,9 @@ module AMQP
1120
1137
  super(method)
1121
1138
 
1122
1139
  self.class.error(method.reply_text)
1140
+ self.class.release_channel_id(@id)
1123
1141
  end
1124
-
1142
+
1125
1143
  # Overrides AMQ::Client::Channel version to also release the channel id
1126
1144
  #
1127
1145
  # @private