bunny 0.8.0 → 0.9.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/.gitignore +7 -1
  2. data/.travis.yml +14 -4
  3. data/ChangeLog.md +72 -0
  4. data/Gemfile +17 -11
  5. data/README.md +82 -0
  6. data/bunny.gemspec +6 -13
  7. data/examples/connection/heartbeat.rb +17 -0
  8. data/lib/bunny.rb +40 -56
  9. data/lib/bunny/channel.rb +615 -19
  10. data/lib/bunny/channel_id_allocator.rb +59 -0
  11. data/lib/bunny/compatibility.rb +24 -0
  12. data/lib/bunny/concurrent/condition.rb +63 -0
  13. data/lib/bunny/consumer.rb +42 -26
  14. data/lib/bunny/consumer_tag_generator.rb +22 -0
  15. data/lib/bunny/consumer_work_pool.rb +67 -0
  16. data/lib/bunny/exceptions.rb +128 -0
  17. data/lib/bunny/exchange.rb +131 -136
  18. data/lib/bunny/framing.rb +53 -0
  19. data/lib/bunny/heartbeat_sender.rb +59 -0
  20. data/lib/bunny/main_loop.rb +70 -0
  21. data/lib/bunny/message_metadata.rb +126 -0
  22. data/lib/bunny/queue.rb +102 -275
  23. data/lib/bunny/session.rb +478 -0
  24. data/lib/bunny/socket.rb +44 -0
  25. data/lib/bunny/system_timer.rb +9 -9
  26. data/lib/bunny/transport.rb +179 -0
  27. data/lib/bunny/version.rb +1 -1
  28. data/spec/compatibility/queue_declare_spec.rb +40 -0
  29. data/spec/higher_level_api/integration/basic_ack_spec.rb +54 -0
  30. data/spec/higher_level_api/integration/basic_consume_spec.rb +51 -0
  31. data/spec/higher_level_api/integration/basic_get_spec.rb +47 -0
  32. data/spec/higher_level_api/integration/basic_nack_spec.rb +39 -0
  33. data/spec/higher_level_api/integration/basic_publish_spec.rb +105 -0
  34. data/spec/higher_level_api/integration/basic_qos_spec.rb +32 -0
  35. data/spec/higher_level_api/integration/basic_recover_spec.rb +18 -0
  36. data/spec/higher_level_api/integration/basic_reject_spec.rb +53 -0
  37. data/spec/higher_level_api/integration/basic_return_spec.rb +33 -0
  38. data/spec/higher_level_api/integration/channel_close_spec.rb +29 -0
  39. data/spec/higher_level_api/integration/channel_flow_spec.rb +24 -0
  40. data/spec/higher_level_api/integration/channel_open_spec.rb +57 -0
  41. data/spec/higher_level_api/integration/channel_open_stress_spec.rb +22 -0
  42. data/spec/higher_level_api/integration/confirm_select_spec.rb +19 -0
  43. data/spec/higher_level_api/integration/connection_spec.rb +340 -0
  44. data/spec/higher_level_api/integration/exchange_bind_spec.rb +31 -0
  45. data/spec/higher_level_api/integration/exchange_declare_spec.rb +183 -0
  46. data/spec/higher_level_api/integration/exchange_delete_spec.rb +37 -0
  47. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +40 -0
  48. data/spec/higher_level_api/integration/queue_bind_spec.rb +109 -0
  49. data/spec/higher_level_api/integration/queue_declare_spec.rb +129 -0
  50. data/spec/higher_level_api/integration/queue_delete_spec.rb +38 -0
  51. data/spec/higher_level_api/integration/queue_purge_spec.rb +30 -0
  52. data/spec/higher_level_api/integration/queue_unbind_spec.rb +33 -0
  53. data/spec/higher_level_api/integration/tx_commit_spec.rb +21 -0
  54. data/spec/higher_level_api/integration/tx_rollback_spec.rb +21 -0
  55. data/spec/lower_level_api/integration/basic_cancel_spec.rb +57 -0
  56. data/spec/lower_level_api/integration/basic_consume_spec.rb +100 -0
  57. data/spec/spec_helper.rb +64 -0
  58. data/spec/unit/bunny_spec.rb +15 -0
  59. data/spec/unit/concurrent/condition_spec.rb +66 -0
  60. metadata +135 -93
  61. data/CHANGELOG +0 -21
  62. data/README.textile +0 -76
  63. data/Rakefile +0 -14
  64. data/examples/simple.rb +0 -32
  65. data/examples/simple_ack.rb +0 -35
  66. data/examples/simple_consumer.rb +0 -55
  67. data/examples/simple_fanout.rb +0 -41
  68. data/examples/simple_headers.rb +0 -42
  69. data/examples/simple_publisher.rb +0 -29
  70. data/examples/simple_topic.rb +0 -61
  71. data/ext/amqp-0.9.1.json +0 -389
  72. data/ext/config.yml +0 -4
  73. data/ext/qparser.rb +0 -426
  74. data/lib/bunny/client.rb +0 -370
  75. data/lib/bunny/subscription.rb +0 -92
  76. data/lib/qrack/amq-client-url.rb +0 -165
  77. data/lib/qrack/channel.rb +0 -20
  78. data/lib/qrack/client.rb +0 -247
  79. data/lib/qrack/errors.rb +0 -5
  80. data/lib/qrack/protocol/protocol.rb +0 -135
  81. data/lib/qrack/protocol/spec.rb +0 -525
  82. data/lib/qrack/qrack.rb +0 -20
  83. data/lib/qrack/queue.rb +0 -40
  84. data/lib/qrack/subscription.rb +0 -152
  85. data/lib/qrack/transport/buffer.rb +0 -305
  86. data/lib/qrack/transport/frame.rb +0 -102
  87. data/spec/spec_09/amqp_url_spec.rb +0 -19
  88. data/spec/spec_09/bunny_spec.rb +0 -76
  89. data/spec/spec_09/connection_spec.rb +0 -34
  90. data/spec/spec_09/exchange_spec.rb +0 -173
  91. data/spec/spec_09/queue_spec.rb +0 -240
@@ -0,0 +1,126 @@
1
+ module Bunny
2
+ # Combines message delivery metadata and message metadata behind a single Hash-like
3
+ # immutable data structure that mimics AMQP::Header in amqp gem.
4
+ class MessageMetadata
5
+
6
+ #
7
+ # Behaviors
8
+ #
9
+
10
+ include Enumerable
11
+
12
+ #
13
+ # API
14
+ #
15
+
16
+ def initialize(basic_deliver, properties)
17
+ h = {
18
+ :consumer_tag => basic_deliver.consumer_tag,
19
+ :delivery_tag => basic_deliver.delivery_tag,
20
+ :redelivered => basic_deliver.redelivered,
21
+ :exchange => basic_deliver.exchange,
22
+ :routing_key => basic_deliver.routing_key
23
+ }
24
+
25
+ @basic_deliver = basic_deliver
26
+ @properties = properties
27
+ @combined = properties.merge(h)
28
+ end
29
+
30
+ def each(*args, &block)
31
+ @combined.each(*args, &block)
32
+ end
33
+
34
+ def [](k)
35
+ @combined[k]
36
+ end
37
+
38
+ def to_hash
39
+ @combined
40
+ end
41
+
42
+ def to_s
43
+ to_hash.to_s
44
+ end
45
+
46
+ def inspect
47
+ to_hash.inspect
48
+ end
49
+
50
+ def consumer_tag
51
+ @basic_deliver.consumer_tag
52
+ end
53
+
54
+ def deliver_tag
55
+ @basic_deliver.deliver_tag
56
+ end
57
+
58
+ def redelivered
59
+ @basic_deliver.redelivered
60
+ end
61
+
62
+ def exchange
63
+ @basic_deliver.exchange
64
+ end
65
+
66
+ def routing_key
67
+ @basic_deliver.routing_key
68
+ end
69
+
70
+ def content_type
71
+ @properties[:content_type]
72
+ end
73
+
74
+ def content_encoding
75
+ @properties[:content_encoding]
76
+ end
77
+
78
+ def headers
79
+ @properties[:headers]
80
+ end
81
+
82
+ def delivery_mode
83
+ @properties[:delivery_mode]
84
+ end
85
+
86
+ def priority
87
+ @properties[:priority]
88
+ end
89
+
90
+ def correlation_id
91
+ @properties[:correlation_id]
92
+ end
93
+
94
+ def reply_to
95
+ @properties[:reply_to]
96
+ end
97
+
98
+ def expiration
99
+ @properties[:expiration]
100
+ end
101
+
102
+ def message_id
103
+ @properties[:message_id]
104
+ end
105
+
106
+ def timestamp
107
+ @properties[:timestamp]
108
+ end
109
+
110
+ def type
111
+ @properties[:type]
112
+ end
113
+
114
+ def user_id
115
+ @properties[:user_id]
116
+ end
117
+
118
+ def app_id
119
+ @properties[:app_id]
120
+ end
121
+
122
+ def cluster_id
123
+ @properties[:cluster_id]
124
+ end
125
+ end
126
+ end
@@ -1,328 +1,155 @@
1
- # encoding: utf-8
1
+ require "bunny/compatibility"
2
2
 
3
3
  module Bunny
4
+ class Queue
4
5
 
5
- # Queues store and forward messages. Queues can be configured in the server or created at runtime.
6
- # Queues must be attached to at least one exchange in order to receive messages from publishers.
7
- class Queue < Qrack::Queue
8
- def initialize(client, name, opts = {})
9
- # check connection to server
10
- raise Bunny::ConnectionError, 'Not connected to server' if client.status == :not_connected
11
-
12
- @client = client
13
- @opts = opts
14
- @delivery_tag = nil
15
-
16
- # Queues without a given name are named by the server and are generally
17
- # bound to the process that created them.
18
- if !name
19
- opts = {
20
- :passive => false,
21
- :durable => false,
22
- :exclusive => true,
23
- :auto_delete => true,
24
- :deprecated_ticket => 0
25
- }.merge(opts)
26
- end
27
-
28
- # ignore the :nowait option if passed, otherwise program will hang waiting for a
29
- # response that will not be sent by the server
30
- opts.delete(:nowait)
31
-
32
- opts = { :queue => name || '', :nowait => false, :deprecated_ticket => 0 }.merge(opts)
33
-
34
- client.send_frame(Qrack::Protocol::Queue::Declare.new(opts))
35
-
36
- method = client.next_method
37
-
38
- client.check_response(method, Qrack::Protocol::Queue::DeclareOk, "Error declaring queue #{name}")
39
-
40
- @name = method.queue
41
- client.queues[@name] = self
42
- end
43
-
44
- # @return [Bunny::Consumer] Default consumer associated with this queue (if any), or nil
45
- # @note Default consumer is the one registered with the convenience {Bunny::Queue#subscribe} method. It has no special properties of any kind.
46
- # @see Queue#subscribe
47
- # @see Bunny::Consumer
48
- # @api public
49
- def default_consumer
50
- @default_consumer
51
- end
52
-
53
- # @return [Class]
54
- # @private
55
- def self.consumer_class
56
- # Bunny::Consumer
57
- Bunny::Subscription
58
- end # self.consumer_class
59
-
60
- # Acknowledges one or more messages delivered via the _Deliver_ or _Get_-_Ok_ methods. The client can
61
- # ask to confirm a single message or a set of messages up to and including a specific message.
62
- #
63
- # @option opts [String] :delivery_tag
64
- #
65
- # @option opts [Boolean] :multiple (false)
66
- # If set to @true@, the delivery tag is treated as "up to and including",
67
- # so that the client can acknowledge multiple messages with a single method.
68
- # If set to @false@, the delivery tag refers to a single message.
69
- # If the multiple field is @true@, and the delivery tag is zero,
70
- # tells the server to acknowledge all outstanding messages.
71
- def ack(opts = {})
72
- # Set delivery tag
73
- if delivery_tag.nil? and opts[:delivery_tag].nil?
74
- raise Bunny::AcknowledgementError, "No delivery tag received"
75
- else
76
- self.delivery_tag = opts[:delivery_tag] if delivery_tag.nil?
77
- end
78
-
79
- opts = {:delivery_tag => delivery_tag, :multiple => false}.merge(opts)
80
-
81
- client.send_frame(Qrack::Protocol::Basic::Ack.new(opts))
6
+ include Bunny::Compatibility
82
7
 
83
- # reset delivery tag
84
- self.delivery_tag = nil
85
- end
86
8
 
87
- # Binds a queue to an exchange. Until a queue is bound it won't receive
88
- # any messages. Queues are bound to the direct exchange '' by default.
89
- # If error occurs, a {Bunny::ProtocolError} is raised.
90
- #
91
- # @option opts [String] :key
92
- # Specifies the routing key for the binding. The routing key is used
93
- # for routing messages depending on the exchange configuration.
94
9
  #
95
- # @option opts [Boolean] :nowait (false)
96
- # Ignored by Bunny, always @false@.
10
+ # API
97
11
  #
98
- # @return [Symbol] @:bind_ok@ if successful.
99
- def bind(exchange, opts = {})
100
- exchange = exchange.respond_to?(:name) ? exchange.name : exchange
101
12
 
102
- # ignore the :nowait option if passed, otherwise program will hang waiting for a
103
- # response that will not be sent by the server
104
- opts.delete(:nowait)
13
+ attr_reader :channel, :name, :options
105
14
 
106
- opts = {
107
- :queue => name,
108
- :exchange => exchange,
109
- :routing_key => opts.delete(:key),
110
- :nowait => false,
111
- :deprecated_ticket => 0
112
- }.merge(opts)
15
+ def initialize(channel_or_connection, name = AMQ::Protocol::EMPTY_STRING, opts = {})
16
+ # old Bunny versions pass a connection here. In that case,
17
+ # we just use default channel from it. MK.
18
+ @channel = channel_from(channel_or_connection)
19
+ @name = name
20
+ @options = self.class.add_default_options(name, opts)
21
+ @consumers = Hash.new
113
22
 
114
- client.send_frame(Qrack::Protocol::Queue::Bind.new(opts))
23
+ @durable = @options[:durable]
24
+ @exclusive = @options[:exclusive]
25
+ @server_named = @name.empty?
26
+ @auto_delete = @options[:auto_delete]
27
+ @arguments = @options[:arguments]
115
28
 
116
- method = client.next_method
29
+ @default_consumer = nil
117
30
 
118
- client.check_response(method, Qrack::Protocol::Queue::BindOk, "Error binding queue: #{name} to exchange: #{exchange}")
31
+ declare! unless opts[:no_declare]
119
32
 
120
- # return message
121
- :bind_ok
33
+ @channel.register_queue(self)
122
34
  end
123
35
 
124
- # Requests that a queue is deleted from broker/server. When a queue is deleted any pending messages
125
- # are sent to a dead-letter queue if this is defined in the server configuration. Removes reference
126
- # from queues if successful. If an error occurs raises @Bunny::ProtocolError@.
127
- #
128
- # @option opts [Boolean] :if_unused (false)
129
- # If set to @true@, the server will only delete the queue if it has no consumers.
130
- # If the queue has consumers the server does not delete it but raises a channel exception instead.
131
- #
132
- # @option opts [Boolean] :if_empty (false)
133
- # If set to @true@, the server will only delete the queue if it has no messages.
134
- # If the queue is not empty the server raises a channel exception.
135
- #
136
- # @option opts [Boolean] :nowait (false)
137
- # Ignored by Bunny, always @false@.
138
- #
139
- # @return [Symbol] @:delete_ok@ if successful
140
- def delete(opts = {})
141
- # ignore the :nowait option if passed, otherwise program will hang waiting for a
142
- # response that will not be sent by the server
143
- opts.delete(:nowait)
36
+ # @return [Boolean] true if this queue was declared as durable (will survive broker restart).
37
+ # @api public
38
+ def durable?
39
+ @durable
40
+ end # durable?
144
41
 
145
- opts = { :queue => name, :nowait => false, :deprecated_ticket => 0 }.merge(opts)
42
+ # @return [Boolean] true if this queue was declared as exclusive (limited to just one consumer)
43
+ # @api public
44
+ def exclusive?
45
+ @exclusive
46
+ end # exclusive?
146
47
 
147
- client.send_frame(Qrack::Protocol::Queue::Delete.new(opts))
48
+ # @return [Boolean] true if this queue was declared as automatically deleted (deleted as soon as last consumer unbinds).
49
+ # @api public
50
+ def auto_delete?
51
+ @auto_delete
52
+ end # auto_delete?
148
53
 
149
- method = client.next_method
54
+ # @return [Boolean] true if this queue was declared as server named.
55
+ # @api public
56
+ def server_named?
57
+ @server_named
58
+ end # server_named?
150
59
 
151
- client.check_response(method, Qrack::Protocol::Queue::DeleteOk, "Error deleting queue #{name}")
60
+ def arguments
61
+ @arguments
62
+ end
152
63
 
153
- client.queues.delete(name)
154
64
 
155
- # return confirmation
156
- :delete_ok
65
+ def bind(exchange, opts = {})
66
+ @channel.queue_bind(@name, exchange, opts)
157
67
  end
158
68
 
159
- # Gets a message from a queue in a synchronous way. If error occurs, raises _Bunny_::_ProtocolError_.
160
- #
161
- # @option opts [Boolean] :ack (false)
162
- # If set to @false@, the server does not expect an acknowledgement message
163
- # from the client. If set to @true@, the server expects an acknowledgement
164
- # message from the client and will re-queue the message if it does not receive
165
- # one within a time specified by the server.
166
- #
167
- # @return [Hash] Hash with @:header@, @:payload@ and @:delivery_details@ keys. @:delivery_details@ is a hash @:consumer_tag@, @:delivery_tag@, @:redelivered@, @:exchange@ and @:routing_key@. If the queue is empty the returned hash will contain: @{:header => nil, :payload => :queue_empty, :delivery_details => nil}@. N.B. If a block is provided then the hash will be passed into the block and the return value will be nil.
168
- def pop(opts = {}, &blk)
169
- opts = {
170
- :queue => name,
171
- :consumer_tag => name,
172
- :no_ack => !opts[:ack],
173
- :nowait => true,
174
- :deprecated_ticket => 0
175
- }.merge(opts)
176
-
177
- client.send_frame(Qrack::Protocol::Basic::Get.new(opts))
178
-
179
- method = client.next_method
180
-
181
- if method.is_a?(Qrack::Protocol::Basic::GetEmpty) then
182
- queue_empty = true
183
- elsif !method.is_a?(Qrack::Protocol::Basic::GetOk)
184
- raise Bunny::ProtocolError, "Error getting message from queue #{name}"
185
- end
186
-
187
- if !queue_empty
188
- # get delivery tag to use for acknowledge
189
- self.delivery_tag = method.delivery_tag if opts[:ack]
69
+ def unbind(exchange, opts = {})
70
+ @channel.queue_unbind(@name, exchange, opts)
71
+ end
190
72
 
191
- header = client.next_payload
73
+ def subscribe(opts = {:consumer_tag => "", :ack => false, :exclusive => false}, &block)
74
+ @channel.basic_consume(@name, opts.fetch(:consumer_tag, ""), !opts[:ack], opts[:exclusive], opts[:arguments], &block)
192
75
 
193
- # If maximum frame size is smaller than message payload body then message
194
- # will have a message header and several message bodies
195
- msg = ''
196
- while msg.length < header.size
197
- msg << client.next_payload
198
- end
76
+ # joins current thread with the consumers pool
77
+ @channel.work_pool.join
78
+ end
199
79
 
200
- msg_hash = {:header => header, :payload => msg, :delivery_details => method.arguments}
80
+ def pop(opts = {:ack => true}, &block)
81
+ delivery_info, properties, content = @channel.basic_get(@name, opts)
201
82
 
83
+ if block
84
+ block.call(delivery_info, properties, content)
202
85
  else
203
- msg_hash = {:header => nil, :payload => :queue_empty, :delivery_details => nil}
86
+ [delivery_info, properties, content]
204
87
  end
205
-
206
- # Pass message hash to block or return message hash
207
- blk ? blk.call(msg_hash) : msg_hash
208
88
  end
89
+ alias get pop
209
90
 
210
- # Removes all messages from a queue. It does not cancel consumers. Purged messages are deleted
211
- # without any formal "undo" mechanism. If an error occurs raises {Bunny::ProtocolError}.
212
- #
213
- # @option opts [Boolean] :nowait (false)
214
- # Ignored by Bunny, always @false@.
215
- #
216
- # @return [Symbol] @:purge_ok@ if successful
217
- def purge(opts = {})
218
- # ignore the :nowait option if passed, otherwise program will hang waiting for a
219
- # response that will not be sent by the server
220
- opts.delete(:nowait)
221
-
222
- opts = { :queue => name, :nowait => false, :deprecated_ticket => 0 }.merge(opts)
223
-
224
- client.send_frame(Qrack::Protocol::Queue::Purge.new(opts))
225
91
 
226
- method = client.next_method
227
-
228
- client.check_response(method, Qrack::Protocol::Queue::PurgeOk, "Error purging queue #{name}")
92
+ # Deletes the queue
93
+ # @api public
94
+ def delete(opts = {})
95
+ @channel.queue_delete(@name, opts)
96
+ end
229
97
 
230
- # return confirmation
231
- :purge_ok
98
+ def purge(opts = {})
99
+ @channel.queue_purge(@name, opts)
232
100
  end
233
101
 
234
- # @return [Hash] Hash with keys @:message_count@ and @consumer_count@.
235
102
  def status
236
- opts = { :queue => name, :passive => true, :deprecated_ticket => 0 }
237
- client.send_frame(Qrack::Protocol::Queue::Declare.new(opts))
238
-
239
- method = client.next_method
240
- {:message_count => method.message_count, :consumer_count => method.consumer_count}
103
+ queue_declare_ok = @channel.queue_declare(@name, @options.merge(:passive => true))
104
+ {:message_count => queue_declare_ok.message_count,
105
+ :consumer_count => queue_declare_ok.consumer_count}
241
106
  end
242
107
 
243
- def subscribe(opts = {}, &blk)
244
- raise RuntimeError.new("This queue already has default consumer. Please instantiate Bunny::Consumer directly and call its #consume method to register additional consumers.") if @default_consumer && ! opts[:consumer_tag]
245
-
246
- # Create a subscription.
247
- @default_consumer = self.class.consumer_class.new(client, self, opts)
248
- @default_consumer.consume(&blk)
108
+ def message_count
109
+ s = self.status
110
+ s[:message_count]
249
111
  end
250
112
 
251
- # Removes a queue binding from an exchange. If error occurs, a _Bunny_::_ProtocolError_ is raised.
252
- #
253
- # @option opts [String] :key
254
- # Specifies the routing key for the binding.
255
- #
256
- # @option opts [Boolean] :nowait (false)
257
- # Ignored by Bunny, always @false@.
258
- #
259
- # @return [Symbol] @:unbind_ok@ if successful.
260
- def unbind(exchange, opts = {})
261
- exchange = exchange.respond_to?(:name) ? exchange.name : exchange
262
-
263
- # ignore the :nowait option if passed, otherwise program will hang waiting for a
264
- # response that will not be sent by the server
265
- opts.delete(:nowait)
266
-
267
- opts = {
268
- :queue => name,
269
- :exchange => exchange,
270
- :routing_key => opts.delete(:key),
271
- :nowait => false,
272
- :deprecated_ticket => 0
273
- }.merge(opts)
274
-
275
- client.send_frame(Qrack::Protocol::Queue::Unbind.new(opts))
276
-
277
- method = client.next_method
113
+ def consumer_count
114
+ s = self.status
115
+ s[:consumer_count]
116
+ end
278
117
 
279
- client.check_response(method, Qrack::Protocol::Queue::UnbindOk, "Error unbinding queue #{name}")
280
118
 
281
- # return message
282
- :unbind_ok
283
- end
284
119
 
285
- # Cancels a consumer. This does not affect already delivered messages, but it does mean
286
- # the server will not send any more messages for that consumer.
287
120
  #
288
- # @option opts [String] :consumer_tag
289
- # Specifies the identifier for the consumer.
121
+ # Implementation
290
122
  #
291
- # @option opts [Boolean] :nowait (false)
292
- # Ignored by Bunny, always @false@.
293
- #
294
- # @option opts [Boolean] :nowait (false)
295
- # Ignored by Bunny, always @false@.
296
- #
297
- # @return [Symbol] @:unsubscribe_ok@ if successful
298
- def unsubscribe(opts = {})
299
- # Default consumer_tag from subscription if not passed in
300
- consumer_tag = @default_consumer ? @default_consumer.consumer_tag : opts[:consumer_tag]
301
-
302
- # Must have consumer tag to tell server what to unsubscribe
303
- raise Bunny::UnsubscribeError,
304
- "No consumer tag received" if !consumer_tag
305
-
306
- # Cancel consumer
307
- client.send_frame(Qrack::Protocol::Basic::Cancel.new(:consumer_tag => consumer_tag, :nowait => false))
308
-
309
- # Reset subscription
310
- @default_consumer = nil
311
-
312
- method = client.next_method
313
-
314
- client.check_response(method, Qrack::Protocol::Basic::CancelOk, "Error unsubscribing from queue #{name}, got #{method.class}")
315
123
 
316
- # Return confirmation
317
- :unsubscribe_ok
124
+ # @private
125
+ def declare!
126
+ queue_declare_ok = @channel.queue_declare(@name, @options)
127
+ @name = queue_declare_ok.queue
318
128
  end
319
129
 
320
- private
130
+ protected
321
131
 
322
- def exchange
323
- @exchange ||= Bunny::Exchange.new(client, '', :type => :direct, :key => name, :reserved_1 => 0, :reserved_2 => false, :reserved_3 => false)
132
+ # @private
133
+ def self.add_default_options(name, opts, block)
134
+ { :queue => name, :nowait => (block.nil? && !name.empty?) }.merge(opts)
324
135
  end
325
136
 
137
+ # @private
138
+ def self.add_default_options(name, opts)
139
+ # :nowait is always false for Bunny
140
+ h = { :queue => name, :nowait => false }.merge(opts)
141
+
142
+ if name.empty?
143
+ {
144
+ :passive => false,
145
+ :durable => false,
146
+ :exclusive => false,
147
+ :auto_delete => false,
148
+ :arguments => nil
149
+ }.merge(h)
150
+ else
151
+ h
152
+ end
153
+ end
326
154
  end
327
-
328
155
  end