amqp 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,12 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'amqp'
3
- s.version = '0.6.5'
4
- s.date = '2009-10-27'
3
+ s.version = '0.6.6'
4
+ s.date = '2009-12-29'
5
5
  s.summary = 'AMQP client implementation in Ruby/EventMachine'
6
6
  s.email = "amqp@tmm1.net"
7
7
  s.homepage = "http://amqp.rubyforge.org/"
8
- s.description = "AMQP client implementation in Ruby/EventMachine"
8
+ s.rubyforge_project = 'amqp'
9
+ s.description = "An implementation of the AMQP protocol in Ruby/EventMachine for writing clients to the RabbitMQ message broker"
9
10
  s.has_rdoc = true
10
11
  s.rdoc_options = '--include=examples'
11
12
 
data/lib/mq.rb CHANGED
@@ -199,7 +199,7 @@ class MQ
199
199
  end
200
200
 
201
201
  when Protocol::Queue::DeclareOk
202
- queues[ method.queue ].recieve_status method
202
+ queues[ method.queue ].receive_status method
203
203
 
204
204
  when Protocol::Basic::Deliver, Protocol::Basic::GetOk
205
205
  @method = method
@@ -230,6 +230,13 @@ class MQ
230
230
  c.channels.delete @channel
231
231
  c.close if c.channels.empty?
232
232
  }
233
+
234
+ when Protocol::Basic::ConsumeOk
235
+ if @consumer = consumers[ method.consumer_tag ]
236
+ @consumer.confirm_subscribe
237
+ else
238
+ MQ.error "Basic.ConsumeOk for invalid consumer tag: #{method.consumer_tag}"
239
+ end
233
240
  end
234
241
  end
235
242
  end
@@ -734,6 +741,20 @@ class MQ
734
741
 
735
742
  def prefetch(size)
736
743
  send Protocol::Basic::Qos.new(:prefetch_size => 0, :prefetch_count => size, :global => false)
744
+ self
745
+ end
746
+
747
+ # Asks the broker to redeliver all unacknowledged messages on this
748
+ # channel.
749
+ #
750
+ # * requeue (default false)
751
+ # If this parameter is false, the message will be redelivered to the original recipient.
752
+ # If this flag is true, the server will attempt to requeue the message, potentially then
753
+ # delivering it to an alternative subscriber.
754
+ #
755
+ def recover requeue = false
756
+ send Protocol::Basic::Recover.new(:requeue => requeue)
757
+ self
737
758
  end
738
759
 
739
760
  # Returns a hash of all the exchange proxy objects.
@@ -194,11 +194,13 @@ class MQ
194
194
  @mq.exchanges[@name = name] ||= self
195
195
  @key = opts[:key]
196
196
 
197
- @mq.callback{
198
- @mq.send Protocol::Exchange::Declare.new({ :exchange => name,
199
- :type => type,
200
- :nowait => true }.merge(opts))
201
- } unless name == "amq.#{type}" or name == ''
197
+ unless name == "amq.#{type}" or name == '' or opts[:no_declare]
198
+ @mq.callback{
199
+ @mq.send Protocol::Exchange::Declare.new({ :exchange => name,
200
+ :type => type,
201
+ :nowait => true }.merge(opts))
202
+ }
203
+ end
202
204
  end
203
205
  attr_reader :name, :type, :key
204
206
 
@@ -247,13 +249,13 @@ class MQ
247
249
  out = []
248
250
 
249
251
  out << Protocol::Basic::Publish.new({ :exchange => name,
250
- :routing_key => opts.delete(:key) || @key }.merge(opts))
252
+ :routing_key => opts[:key] || @key }.merge(opts))
251
253
 
252
254
  data = data.to_s
253
255
 
254
256
  out << Protocol::Header.new(Protocol::Basic,
255
257
  data.length, { :content_type => 'application/octet-stream',
256
- :delivery_mode => (opts.delete(:persistent) ? 2 : 1),
258
+ :delivery_mode => (opts[:persistent] ? 2 : 1),
257
259
  :priority => 0 }.merge(opts))
258
260
 
259
261
  out << Frame::Body.new(data)
@@ -113,7 +113,7 @@ class MQ
113
113
  @mq.callback{
114
114
  @mq.send Protocol::Queue::Bind.new({ :queue => name,
115
115
  :exchange => exchange,
116
- :routing_key => opts.delete(:key),
116
+ :routing_key => opts[:key],
117
117
  :nowait => true }.merge(opts))
118
118
  }
119
119
  self
@@ -140,7 +140,7 @@ class MQ
140
140
  @mq.callback{
141
141
  @mq.send Protocol::Queue::Unbind.new({ :queue => name,
142
142
  :exchange => exchange,
143
- :routing_key => opts.delete(:key),
143
+ :routing_key => opts[:key],
144
144
  :nowait => true }.merge(opts))
145
145
  }
146
146
  self
@@ -175,6 +175,16 @@ class MQ
175
175
  nil
176
176
  end
177
177
 
178
+ # Purge all messages from the queue.
179
+ #
180
+ def purge opts = {}
181
+ @mq.callback{
182
+ @mq.send Protocol::Queue::Purge.new({ :queue => name,
183
+ :nowait => true }.merge(opts))
184
+ }
185
+ nil
186
+ end
187
+
178
188
  # This method provides a direct access to the messages in a queue
179
189
  # using a synchronous dialogue that is designed for specific types of
180
190
  # application where synchronous functionality is more important than
@@ -240,7 +250,7 @@ class MQ
240
250
  q.push(self)
241
251
  @mq.send Protocol::Basic::Get.new({ :queue => name,
242
252
  :consumer_tag => name,
243
- :no_ack => !opts.delete(:ack),
253
+ :no_ack => !opts[:ack],
244
254
  :nowait => true }.merge(opts))
245
255
  }
246
256
  }
@@ -296,6 +306,12 @@ class MQ
296
306
  # not wait for a reply method. If the server could not complete the
297
307
  # method it will raise a channel or connection exception.
298
308
  #
309
+ # * :confirm => proc (default nil)
310
+ # If set, this proc will be called when the server confirms subscription
311
+ # to the queue with a ConsumeOk message. Setting this option will
312
+ # automatically set :nowait => false. This is required for the server
313
+ # to send a confirmation.
314
+ #
299
315
  def subscribe opts = {}, &blk
300
316
  @consumer_tag = "#{name}-#{Kernel.rand(999_999_999_999)}"
301
317
  @mq.consumers[@consumer_tag] = self
@@ -304,11 +320,12 @@ class MQ
304
320
 
305
321
  @on_msg = blk
306
322
  @on_msg_opts = opts
323
+ opts[:nowait] = false if (@on_confirm_subscribe = opts[:confirm])
307
324
 
308
325
  @mq.callback{
309
326
  @mq.send Protocol::Basic::Consume.new({ :queue => name,
310
327
  :consumer_tag => @consumer_tag,
311
- :no_ack => !opts.delete(:ack),
328
+ :no_ack => !opts[:ack],
312
329
  :nowait => true }.merge(opts))
313
330
  }
314
331
  self
@@ -336,7 +353,6 @@ class MQ
336
353
  # method it will raise a channel or connection exception.
337
354
  #
338
355
  def unsubscribe opts = {}, &blk
339
- @on_msg = nil
340
356
  @on_cancel = blk
341
357
  @mq.callback{
342
358
  @mq.send Protocol::Basic::Cancel.new({ :consumer_tag => @consumer_tag }.merge(opts))
@@ -391,7 +407,7 @@ class MQ
391
407
  self
392
408
  end
393
409
 
394
- def recieve_status declare_ok
410
+ def receive_status declare_ok
395
411
  if @on_status
396
412
  m, c = declare_ok.message_count, declare_ok.consumer_count
397
413
  @on_status.call *(@on_status.arity == 1 ? [m] : [m, c])
@@ -399,6 +415,11 @@ class MQ
399
415
  end
400
416
  end
401
417
 
418
+ def confirm_subscribe
419
+ @on_confirm_subscribe.call if @on_confirm_subscribe
420
+ @on_confirm_subscribe = nil
421
+ end
422
+
402
423
  def cancelled
403
424
  @on_cancel.call if @on_cancel
404
425
  @on_cancel = @on_msg = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aman Gupta
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 -07:00
12
+ date: 2009-12-29 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.12.4
24
24
  version:
25
- description: AMQP client implementation in Ruby/EventMachine
25
+ description: An implementation of the AMQP protocol in Ruby/EventMachine for writing clients to the RabbitMQ message broker
26
26
  email: amqp@tmm1.net
27
27
  executables: []
28
28
 
@@ -114,8 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version:
115
115
  requirements: []
116
116
 
117
- rubyforge_project:
118
- rubygems_version: 1.3.4
117
+ rubyforge_project: amqp
118
+ rubygems_version: 1.3.5
119
119
  signing_key:
120
120
  specification_version: 3
121
121
  summary: AMQP client implementation in Ruby/EventMachine