amqp 0.9.10 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.travis.yml +0 -3
  2. data/CHANGELOG +4 -0
  3. data/Gemfile +1 -0
  4. data/README.md +72 -81
  5. data/amqp.gemspec +14 -5
  6. data/docs/08Migration.textile +0 -4
  7. data/docs/AMQP091ModelExplained.textile +0 -5
  8. data/docs/Bindings.textile +0 -4
  9. data/docs/Clustering.textile +0 -4
  10. data/docs/ConnectingToTheBroker.textile +1 -5
  11. data/docs/ConnectionEncryptionWithTLS.textile +0 -4
  12. data/docs/DocumentationGuidesIndex.textile +0 -4
  13. data/docs/Durability.textile +0 -4
  14. data/docs/ErrorHandling.textile +40 -106
  15. data/docs/Exchanges.textile +0 -4
  16. data/docs/GettingStarted.textile +6 -10
  17. data/docs/PatternsAndUseCases.textile +1 -4
  18. data/docs/Queues.textile +0 -4
  19. data/docs/RabbitMQVersions.textile +0 -4
  20. data/docs/RunningTests.textile +0 -4
  21. data/docs/TestingWithEventedSpec.textile +0 -4
  22. data/docs/Troubleshooting.textile +0 -4
  23. data/docs/VendorSpecificExtensions.textile +0 -4
  24. data/examples/error_handling/hello_world_producer.rb +1 -1
  25. data/examples/issues/issue_121.rb +23 -0
  26. data/examples/patterns/request_reply/client.rb +2 -1
  27. data/examples/patterns/request_reply/server.rb +1 -0
  28. data/examples/publishing/returned_messages.rb +1 -1
  29. data/lib/amqp.rb +0 -7
  30. data/lib/amqp/channel.rb +15 -33
  31. data/lib/amqp/client.rb +2 -2
  32. data/lib/amqp/compatibility/ruby187_patchlevel_check.rb +4 -4
  33. data/lib/amqp/connection.rb +0 -1
  34. data/lib/amqp/consumer.rb +2 -2
  35. data/lib/amqp/exceptions.rb +1 -10
  36. data/lib/amqp/exchange.rb +5 -5
  37. data/lib/amqp/queue.rb +23 -47
  38. data/lib/amqp/session.rb +4 -4
  39. data/lib/amqp/version.rb +1 -1
  40. data/spec/integration/basic_get_spec.rb +24 -80
  41. data/spec/integration/basic_return_spec.rb +3 -3
  42. data/spec/integration/channel_level_exception_with_multiple_channels_spec.rb +1 -0
  43. data/spec/integration/exchange_declaration_spec.rb +102 -71
  44. data/spec/integration/extensions/rabbitmq/publisher_confirmations_spec.rb +17 -1
  45. data/spec/integration/fanout_exchange_routing_spec.rb +1 -1
  46. data/spec/integration/immediate_messages_spec.rb +59 -0
  47. data/spec/integration/multiple_consumers_per_queue_spec.rb +101 -39
  48. data/spec/integration/queue_redeclaration_with_incompatible_attributes_spec.rb +12 -25
  49. data/spec/integration/regressions/concurrent_publishing_on_the_same_channel_spec.rb +1 -1
  50. data/spec/integration/reply_queue_communication_spec.rb +2 -1
  51. data/spec/integration/store_and_forward_spec.rb +9 -6
  52. data/spec/integration/topic_subscription_spec.rb +4 -5
  53. data/spec/spec_helper.rb +2 -8
  54. data/spec/unit/amqp/connection_spec.rb +1 -3
  55. metadata +112 -116
  56. data/examples/deprecated/default_thread_local_channel_instance.rb +0 -34
  57. data/examples/legacy/ack.rb +0 -70
  58. data/examples/legacy/callbacks.rb +0 -45
  59. data/examples/legacy/clock.rb +0 -74
  60. data/examples/legacy/hashtable.rb +0 -60
  61. data/examples/legacy/logger.rb +0 -92
  62. data/examples/legacy/multiclock.rb +0 -56
  63. data/examples/legacy/pingpong.rb +0 -51
  64. data/examples/legacy/primes-simple.rb +0 -29
  65. data/examples/legacy/primes.rb +0 -74
  66. data/examples/legacy/stocks.rb +0 -59
  67. data/lib/amqp/deprecated/fork.rb +0 -17
  68. data/lib/amqp/deprecated/logger.rb +0 -100
  69. data/lib/amqp/deprecated/mq.rb +0 -22
  70. data/lib/amqp/deprecated/rpc.rb +0 -169
  71. data/lib/amqp/ext/em.rb +0 -3
  72. data/lib/amqp/ext/emfork.rb +0 -72
  73. data/lib/amqp/logger.rb +0 -19
  74. data/lib/amqp/rpc.rb +0 -20
  75. data/lib/mq.rb +0 -35
  76. data/lib/mq/logger.rb +0 -4
  77. data/lib/mq/rpc.rb +0 -4
  78. data/spec/integration/remove_individual_binding_spec.rb +0 -51
@@ -2,10 +2,6 @@
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
-
9
5
  h2. About this guide
10
6
 
11
7
  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,10 +2,6 @@
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
-
9
5
 
10
6
  h2. About this guide
11
7
 
@@ -2,10 +2,6 @@
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
-
9
5
  h2. About this guide
10
6
 
11
7
  This guide covers unit testing of amqp-based applications, primarily using "evented-spec":http://github.com/ruby-amqp/evented-spec.
@@ -2,10 +2,6 @@
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
-
9
5
 
10
6
  h2. About this guide
11
7
 
@@ -2,10 +2,6 @@
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
-
9
5
  h2. RabbitMQ extensions
10
6
 
11
7
  h2. Supported extensions
@@ -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", :mandatory => true)
42
+ exchange.publish("Routed via amq.fanout", :immediate => true, :mandatory => true)
43
43
  end
44
44
 
45
45
 
@@ -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
+
10
+
11
+ require 'amqp'
12
+ require 'amqp/extensions/rabbitmq'
13
+ AMQP.start(:user => 'guest',:pass => 'guest',:vhost => '/') do |connection|
14
+ channel = AMQP::Channel.new(connection)
15
+ channel.queue("shuki_q",{:nowait => true,:passive=>false, :auto_delete=>false, :arguments=>{"x-expires"=>5600000}}) do |queue|
16
+ queue.bind('raw.shuki',:routing_key => 'ShukiesTukies')
17
+ puts "before subscribe"
18
+ queue.subscribe(:ack => true) do |header, payload|
19
+ puts "inside subscribe"
20
+ p header.class
21
+ end
22
+ end
23
+ end
@@ -19,7 +19,8 @@ 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)
22
+ :reply_to => replies_queue.name,
23
+ :immediate => true)
23
24
  end
24
25
 
25
26
 
@@ -14,6 +14,7 @@ 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,
17
18
  :mandatory => true)
18
19
 
19
20
  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}")
25
+ exchange.publish("Message ##{i}", :immediate => true)
26
26
  end
27
27
  }
28
28
 
@@ -14,10 +14,3 @@ require "amqp/exchange"
14
14
  require "amqp/queue"
15
15
  require "amqp/channel"
16
16
  require "amqp/header"
17
-
18
-
19
- # Will be removed before 1.0.
20
-
21
- require "amqp/deprecated/mq"
22
- require "amqp/deprecated/rpc"
23
- require "amqp/deprecated/fork"
@@ -7,7 +7,7 @@ require "amqp/queue"
7
7
  module AMQP
8
8
  # h2. What are AMQP channels
9
9
  #
10
- # To quote {http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification}:
10
+ # To quote {http://bit.ly/hw2ELX 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.
@@ -140,7 +140,7 @@ module AMQP
140
140
  # AMQP gem supports several RabbitMQ extensions taht extend Channel functionality.
141
141
  # Learn more in {file:docs/VendorSpecificExtensions.textile}
142
142
  #
143
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.2.5)
143
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.2.5)
144
144
  class Channel < AMQ::Client::Channel
145
145
 
146
146
  #
@@ -263,9 +263,6 @@ 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
-
269
266
  self.open do
270
267
  @channel_is_open_deferrable.succeed
271
268
 
@@ -289,9 +286,6 @@ module AMQP
289
286
  @id = self.class.next_channel_id
290
287
  self.class.release_channel_id(old_id)
291
288
 
292
- @channel_is_open_deferrable.fail
293
- @channel_is_open_deferrable = AMQ::Client::EventMachineClient::Deferrable.new
294
-
295
289
  self.open do
296
290
  @channel_is_open_deferrable.succeed
297
291
 
@@ -379,7 +373,7 @@ module AMQP
379
373
  # @see Channel#default_exchange
380
374
  # @see Exchange
381
375
  # @see Exchange#initialize
382
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3.1)
376
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3.1)
383
377
  #
384
378
  # @return [Exchange]
385
379
  # @api public
@@ -432,7 +426,7 @@ module AMQP
432
426
  #
433
427
  #
434
428
  # @see Exchange
435
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.2.4)
429
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.1.2.4)
436
430
  #
437
431
  # @return [Exchange]
438
432
  # @api public
@@ -487,7 +481,7 @@ module AMQP
487
481
  # @see Exchange
488
482
  # @see Exchange#initialize
489
483
  # @see Channel#default_exchange
490
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3.2)
484
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3.2)
491
485
  #
492
486
  # @return [Exchange]
493
487
  # @api public
@@ -603,7 +597,7 @@ module AMQP
603
597
  # @see Exchange
604
598
  # @see Exchange#initialize
605
599
  # @see http://www.rabbitmq.com/faq.html#Binding-and-Routing RabbitMQ FAQ on routing & wildcards
606
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3.3)
600
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3.3)
607
601
  #
608
602
  # @return [Exchange]
609
603
  # @api public
@@ -709,7 +703,7 @@ module AMQP
709
703
  # @see Exchange
710
704
  # @see Exchange#initialize
711
705
  # @see Channel#default_exchange
712
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3.3)
706
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3.3)
713
707
  #
714
708
  # @return [Exchange]
715
709
  # @api public
@@ -810,7 +804,7 @@ module AMQP
810
804
  #
811
805
  # @see Queue
812
806
  # @see Queue#initialize
813
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.4)
807
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.1.4)
814
808
  #
815
809
  # @return [Queue]
816
810
  # @api public
@@ -935,27 +929,16 @@ module AMQP
935
929
  #
936
930
  # @api public
937
931
  def once_open(&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
932
+ @channel_is_open_deferrable.callback(&block)
943
933
  end # once_open(&block)
944
934
  alias once_opened once_open
945
935
 
946
- # @return [Boolean]
947
- # @api public
948
- def closing?
949
- self.status == :closing
950
- end
951
-
952
936
  # Closes AMQP channel.
953
937
  #
954
938
  # @api public
955
939
  def close(reply_code = 200, reply_text = DEFAULT_REPLY_TEXT, class_id = 0, method_id = 0, &block)
956
- self.status = :closing
957
940
  r = super(reply_code, reply_text, class_id, method_id, &block)
958
-
941
+
959
942
  r
960
943
  end
961
944
 
@@ -974,7 +957,7 @@ module AMQP
974
957
  #
975
958
  # @param [Boolean] Desired flow state.
976
959
  #
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.)
960
+ # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.5.2.3.)
978
961
  # @api public
979
962
  def flow(active = false, &block)
980
963
  super(active, &block)
@@ -1015,7 +998,7 @@ module AMQP
1015
998
  # @api public
1016
999
  # @see #reject
1017
1000
  # @see #recover
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.)
1001
+ # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.13.)
1019
1002
  def acknowledge(delivery_tag, multiple = false)
1020
1003
  super(delivery_tag, multiple)
1021
1004
  end # acknowledge(delivery_tag, multiple = false)
@@ -1025,7 +1008,7 @@ module AMQP
1025
1008
  # @api public
1026
1009
  # @see #acknowledge
1027
1010
  # @see #recover
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.)
1011
+ # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.14.)
1029
1012
  def reject(delivery_tag, requeue = true)
1030
1013
  super(delivery_tag, requeue)
1031
1014
  end # reject(delivery_tag, requeue = true)
@@ -1036,7 +1019,7 @@ module AMQP
1036
1019
  # @return [Channel] self
1037
1020
  #
1038
1021
  # @note RabbitMQ as of 2.3.1 does not support basic.recover with requeue = false.
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.)
1022
+ # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.16.)
1040
1023
  # @see #acknowledge
1041
1024
  # @api public
1042
1025
  def recover(requeue = true, &block)
@@ -1137,9 +1120,8 @@ module AMQP
1137
1120
  super(method)
1138
1121
 
1139
1122
  self.class.error(method.reply_text)
1140
- self.class.release_channel_id(@id)
1141
1123
  end
1142
-
1124
+
1143
1125
  # Overrides AMQ::Client::Channel version to also release the channel id
1144
1126
  #
1145
1127
  # @private
@@ -22,7 +22,7 @@ module AMQP
22
22
  # @see AMQP.connect
23
23
  # @api plugin
24
24
  #
25
- # @see http://rubyamqp.info/articles/connecting_to_broker/ Connecting to The Broker documentation guide
25
+ # @see http://bit.ly/ks8MXK Connecting to The Broker documentation guide
26
26
  def self.connect(connection_string_or_options = {}, options = {}, &block)
27
27
  opts = case connection_string_or_options
28
28
  when String then
@@ -82,7 +82,7 @@ module AMQP
82
82
  #
83
83
  # @raise [ArgumentError] When connection URI schema is not amqp or amqps, or the path contains multiple segments
84
84
  #
85
- # @see http://rubyamqp.info/articles/connecting_to_broker/ Connecting to The Broker documentation guide
85
+ # @see http://bit.ly/ks8MXK Connecting to The Broker documentation guide
86
86
  # @api public
87
87
  def self.parse_connection_uri(connection_string)
88
88
  AMQ::Client::Settings.parse_amqp_url(connection_string)
@@ -7,15 +7,15 @@ if RUBY_VERSION =~ /^1.8.7/
7
7
  # looks like PATCHLEVEL was added after 1.8.7-p249 release :( MK.
8
8
  if (conf["PATCHLEVEL"] && conf["PATCHLEVEL"] == "249") || (conf["libdir"] =~ /1.8.7-p249/)
9
9
  raise <<-MESSAGE
10
- IMPORTANT: amqp gem 0.8.0+ does not support Ruby 1.8.7-p249 (this exact patch level. p174 and p334 are supported!)
10
+ IMPORTANT: amqp gem 0.8.0+ does not support Ruby 1.8.7-p249 (this exact patch level. p174, p334 and later patch levels are supported!)
11
11
  because of a nasty Ruby bug (http://bit.ly/iONBmH). Refer to http://groups.google.com/group/ruby-amqp/browse_thread/thread/37d6dcc1aea1c102
12
12
  for more information, especially if you want to verify whether a particular Ruby patch level or version or build suffers from
13
13
  this issue.
14
14
 
15
- To reiterate: 1.8.7-p174 and 1.8.7-p334 are supported. The fix has been committed to MRI in December 2009. It's
15
+ To reiterate: 1.8.7-p174, p334 and later patch levels are supported, see http://travis-ci.org/ruby-amqp/amqp. The fix was committed to MRI in December 2009. It's
16
16
  a good idea to upgrade, although downgrading to p174 is an option, too.
17
17
 
18
- To learn more (including the 0.8.x migration guide) at http://bit.ly/amqp-gem-docs and https://github.com/ruby-amqp.
18
+ To learn more (including the 0.8.x migration guide) at http://bit.ly/rubyamqp and https://github.com/ruby-amqp.
19
19
  MESSAGE
20
20
  end
21
- end
21
+ end
@@ -192,7 +192,6 @@ module AMQP
192
192
  # @option connection_options_or_string [String] :username ("guest") Username to use. Also can be specified as :user.
193
193
  # @option connection_options_or_string [String] :password ("guest") Password to use. Also can be specified as :pass.
194
194
  # @option connection_options_or_string [Hash] :ssl TLS (SSL) parameters to use.
195
- # @option connection_options_or_string [Fixnum] :heartbeat (0) Connection heartbeat, in seconds. 0 means no heartbeat. Can also be configured server-side starting with RabbitMQ 3.0.
196
195
  # @option connection_options_or_string [#call] :on_tcp_connection_failure A callable object that will be run if connection to server fails
197
196
  # @option connection_options_or_string [#call] :on_possible_authentication_failure A callable object that will be run if authentication fails (see Authentication failure section)
198
197
  #
@@ -139,7 +139,7 @@ module AMQP
139
139
  # @return [Consumer] self
140
140
  #
141
141
  # @api public
142
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.8.3.13.)
142
+ # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.13.)
143
143
  def acknowledge(delivery_tag)
144
144
  super(delivery_tag)
145
145
  end # acknowledge(delivery_tag)
@@ -148,7 +148,7 @@ module AMQP
148
148
  # @return [Consumer] self
149
149
  #
150
150
  # @api public
151
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.8.3.14.)
151
+ # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.8.3.14.)
152
152
  def reject(delivery_tag, requeue = true)
153
153
  super(delivery_tag, requeue)
154
154
  end # reject(delivery_tag, requeue = true)
@@ -43,17 +43,8 @@ module AMQP
43
43
  def initialize(settings)
44
44
  @settings = settings
45
45
 
46
- super("AMQP broker closed TCP connection before authentication succeeded: this usually means authentication failure due to misconfiguration. Settings are #{filtered_settings.inspect}")
46
+ super("AMQP broker closed TCP connection before authentication succeeded: this usually means authentication failure due to misconfiguration. Settings are #{settings.inspect}")
47
47
  end # initialize(settings)
48
-
49
- def filtered_settings
50
- filtered_settings = settings.dup
51
- [:pass, :password].each do |sensitve_setting|
52
- filtered_settings[sensitve_setting] &&= '[filtered]'
53
- end
54
-
55
- filtered_settings
56
- end
57
48
  end # PossibleAuthenticationFailureError
58
49
 
59
50
 
@@ -134,9 +134,9 @@ module AMQP
134
134
  # @see Channel#topic
135
135
  # @see Channel#headers
136
136
  # @see Queue
137
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.1)
138
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.5)
139
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3)
137
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.1.1)
138
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.1.5)
139
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3)
140
140
  class Exchange < AMQ::Client::Exchange
141
141
 
142
142
  #
@@ -162,7 +162,7 @@ module AMQP
162
162
  # AMQP::Exchange.default(channel).publish("make clean", routing_key => "tasks")
163
163
  #
164
164
  # @see Exchange
165
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.2.4)
165
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.1.2.4)
166
166
  # @note Do not confuse default exchange with amq.direct: amq.direct is a pre-defined direct
167
167
  # exchange that doesn't have any special routing semantics.
168
168
  # @return [Exchange] An instance that corresponds to the default exchange (of type direct).
@@ -292,7 +292,7 @@ module AMQP
292
292
  # @see Channel#topic
293
293
  # @see Channel#headers
294
294
  # @see Queue
295
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 3.1.3)
295
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 3.1.3)
296
296
  #
297
297
  # @return [Exchange]
298
298
  # @api public
@@ -116,7 +116,7 @@ module AMQP
116
116
  # persistence.
117
117
  #
118
118
  #
119
- # @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.1)
119
+ # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.1.1)
120
120
  # @see AMQP::Exchange
121
121
  class Queue < AMQ::Client::Queue
122
122
 
@@ -221,11 +221,7 @@ module AMQP
221
221
  #
222
222
  # @api public
223
223
  def once_declared(&block)
224
- @declaration_deferrable.callback do
225
- # guards against cases when deferred operations
226
- # don't complete before the channel is closed
227
- block.call if @channel.open?
228
- end
224
+ @declaration_deferrable.callback(&block)
229
225
  end # once_declared(&block)
230
226
 
231
227
 
@@ -285,8 +281,14 @@ module AMQP
285
281
  # @api public
286
282
  # @see Queue#unbind
287
283
  def bind(exchange, opts = {}, &block)
288
- @channel.once_open do
289
- self.once_name_is_available do
284
+ if self.server_named?
285
+ @channel.once_open do
286
+ @declaration_deferrable.callback do
287
+ super(exchange, (opts[:key] || opts[:routing_key] || AMQ::Protocol::EMPTY_STRING), (opts[:nowait] || block.nil?), opts[:arguments], &block)
288
+ end
289
+ end
290
+ else
291
+ @channel.once_open do
290
292
  super(exchange, (opts[:key] || opts[:routing_key] || AMQ::Protocol::EMPTY_STRING), (opts[:nowait] || block.nil?), opts[:arguments], &block)
291
293
  end
292
294
  end
@@ -355,9 +357,7 @@ module AMQP
355
357
  # @see Queue#bind
356
358
  def unbind(exchange, opts = {}, &block)
357
359
  @channel.once_open do
358
- self.once_name_is_available do
359
- super(exchange, (opts[:key] || opts[:routing_key] || AMQ::Protocol::EMPTY_STRING), opts[:arguments], &block)
360
- end
360
+ super(exchange, (opts[:key] || opts[:routing_key] || AMQ::Protocol::EMPTY_STRING), opts[:arguments], &block)
361
361
  end
362
362
  end
363
363
 
@@ -391,9 +391,7 @@ module AMQP
391
391
  # @see Queue#unbind
392
392
  def delete(opts = {}, &block)
393
393
  @channel.once_open do
394
- self.once_name_is_available do
395
- super(opts.fetch(:if_unused, false), opts.fetch(:if_empty, false), opts.fetch(:nowait, false), &block)
396
- end
394
+ super(opts.fetch(:if_unused, false), opts.fetch(:if_empty, false), opts.fetch(:nowait, false), &block)
397
395
  end
398
396
 
399
397
  # backwards compatibility
@@ -418,9 +416,7 @@ module AMQP
418
416
  # @see Queue#unbind
419
417
  def purge(opts = {}, &block)
420
418
  @channel.once_open do
421
- self.once_declared do
422
- super(opts.fetch(:nowait, false), &block)
423
- end
419
+ super(opts.fetch(:nowait, false), &block)
424
420
  end
425
421
 
426
422
  # backwards compatibility
@@ -481,17 +477,11 @@ module AMQP
481
477
  }
482
478
 
483
479
  @channel.once_open do
484
- self.once_name_is_available do
485
- # see AMQ::Client::Queue#get in amq-client
486
- self.get(!opts.fetch(:ack, false), &shim)
487
- end
480
+ # see AMQ::Client::Queue#get in amq-client
481
+ self.get(!opts.fetch(:ack, false), &shim)
488
482
  end
489
483
  else
490
- @channel.once_open do
491
- self.once_name_is_available do
492
- self.get(!opts.fetch(:ack, false))
493
- end
494
- end
484
+ @channel.once_open { self.get(!opts.fetch(:ack, false)) }
495
485
  end
496
486
  end
497
487
 
@@ -729,9 +719,7 @@ module AMQP
729
719
  opts[:nowait] = false if (@on_confirm_subscribe = opts[:confirm])
730
720
 
731
721
  @channel.once_open do
732
- self.once_name_is_available do
733
- # guards against a pathological case race condition when a channel
734
- # is opened and closed before delayed operations are completed.
722
+ self.once_declared do
735
723
  self.consume(!opts[:ack], opts[:exclusive], (opts[:nowait] || block.nil?), opts[:no_local], nil, &opts[:confirm])
736
724
 
737
725
  self.on_delivery(&block)
@@ -797,7 +785,7 @@ module AMQP
797
785
  # @api public
798
786
  def unsubscribe(opts = {}, &block)
799
787
  @channel.once_open do
800
- self.once_name_is_available do
788
+ self.once_declared do
801
789
  if @default_consumer
802
790
  @default_consumer.cancel(opts.fetch(:nowait, true), &block); @default_consumer = nil
803
791
  end
@@ -824,14 +812,12 @@ module AMQP
824
812
  shim = Proc.new { |q, declare_ok| block.call(declare_ok.message_count, declare_ok.consumer_count) }
825
813
 
826
814
  @channel.once_open do
827
- self.once_name_is_available do
828
- # we do not use self.declare here to avoid caching of @passive since that will cause unexpected side-effects during automatic
829
- # recovery process. MK.
830
- @connection.send_frame(AMQ::Protocol::Queue::Declare.encode(@channel.id, @name, true, @opts[:durable], @opts[:exclusive], @opts[:auto_delete], false, @opts[:arguments]))
815
+ # we do not use self.declare here to avoid caching of @passive since that will cause unexpected side-effects during automatic
816
+ # recovery process. MK.
817
+ @connection.send_frame(AMQ::Protocol::Queue::Declare.encode(@channel.id, @name, true, @opts[:durable], @opts[:exclusive], @opts[:auto_delete], false, @opts[:arguments]))
831
818
 
832
- self.append_callback(:declare, &shim)
833
- @channel.queues_awaiting_declare_ok.push(self)
834
- end
819
+ self.append_callback(:declare, &shim)
820
+ @channel.queues_awaiting_declare_ok.push(self)
835
821
  end
836
822
 
837
823
  self
@@ -897,16 +883,6 @@ module AMQP
897
883
  { :queue => name, :nowait => (block.nil? && !name.empty?) }.merge(opts)
898
884
  end
899
885
 
900
- def once_name_is_available(&block)
901
- if server_named?
902
- self.once_declared do
903
- block.call
904
- end
905
- else
906
- block.call
907
- end
908
- end
909
-
910
886
  private
911
887
 
912
888
  # Default direct exchange that we use to publish messages directly to this queue.