arvicco-amqp 0.6.11 → 0.6.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/HISTORY +8 -0
  2. data/README.md +9 -3
  3. data/VERSION +1 -1
  4. data/lib/amqp/spec.rb +2 -2
  5. data/lib/mq.rb +37 -22
  6. metadata +4 -4
data/HISTORY CHANGED
@@ -17,3 +17,11 @@
17
17
  == 0.6.11 / 2010-11-04
18
18
 
19
19
  * AMQP class behavior specified
20
+
21
+ == 0.6.12 / 2010-11-04
22
+
23
+ * MQ class methods specified
24
+
25
+ == 0.6.13 / 2010-11-05
26
+
27
+ * Secondary MQ instance methods specified
data/README.md CHANGED
@@ -9,8 +9,13 @@ This library was tested primarily with RabbitMQ, although it should be compatibl
9
9
  server implementing the [AMQP 0-8 spec](http://www.amqp.org/confluence/download/attachments/720900/amqp0-8.pdf).
10
10
 
11
11
 
12
- This fork of AMQP contains following improvements:
13
- --------------------------------------------------
12
+ This fork of AMQP
13
+ =================
14
+
15
+ Intention is to describe AMQP lib behavior using RSpec, with reasonable level of completeness.
16
+ Given a solid spec suite, it will be easier to expand the library going forward.
17
+
18
+ Some improvements that are currently merged in, but not yet fully specified:
14
19
 
15
20
  * Support for setting extended headers in MQ::Exchange#publish. Particularly useful for :reply_to for RPC.
16
21
  * Multibyte character support (Ruby 1.9) in MQ::Exchange#publish.
@@ -18,7 +23,8 @@ This fork of AMQP contains following improvements:
18
23
  * MQ::Queue only wraps headers with new MQ::Headers if they are not nil. This allows pops to tell more easily when they've requested a message from an empty queue. See (https://github.com/tmm1/amqp/issues#issue/22)
19
24
  * Support for receiving Headers with zero-size data packets. Such contents with no body frames are totally legit if indicated header size is zero.
20
25
 
21
- TODO: * Support for AMQP::Protocol::Basic::Return method. See (https://github.com/tmm1/amqp/issues#issue/1).
26
+ Some improvements that are planned:
27
+ * Support for AMQP::Protocol::Basic::Return method. See (https://github.com/tmm1/amqp/issues#issue/1).
22
28
 
23
29
  Getting started
24
30
  ===============
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.11
1
+ 0.6.13
@@ -17,14 +17,14 @@ module AMQP
17
17
  end
18
18
 
19
19
  def self.Frame id
20
- (@_base_frames ||= {})[id] ||= Class.new(Frame) do
20
+ (@_base_frames ||= {})[id] ||= Class.new(Frame) {
21
21
  class_eval %[
22
22
  def self.inherited klass
23
23
  klass.const_set(:ID, #{id})
24
24
  Frame.types[#{id}] = klass
25
25
  end
26
26
  ]
27
- end
27
+ }
28
28
  end
29
29
 
30
30
  class Method < Frame( 1 ); end
data/lib/mq.rb CHANGED
@@ -148,6 +148,7 @@ class MQ
148
148
  end
149
149
 
150
150
  attr_reader :channel, :connection
151
+ alias :conn :connection
151
152
 
152
153
  # May raise a MQ::Error exception when the frame payload contains a
153
154
  # Protocol::Channel::Close object.
@@ -243,6 +244,9 @@ class MQ
243
244
  end
244
245
  end
245
246
 
247
+ # Sends each argument through @connection, setting its *ticket* property to the @ticket
248
+ # received in most recent Protocol::Access::RequestOk. This operation is Mutex-synchronized.
249
+ #
246
250
  def send *args
247
251
  conn.callback { |c|
248
252
  (@_send_mutex ||= Mutex.new).synchronize do
@@ -677,10 +681,11 @@ class MQ
677
681
  # method it will raise a channel or connection exception.
678
682
  #
679
683
  def queue name, opts = {}
684
+ #noinspection RubyArgCount
680
685
  queues[name] ||= Queue.new(self, name, opts)
681
686
  end
682
687
 
683
- # Takes a channel, queue and optional object.
688
+ # Takes a queue name and optional object.
684
689
  #
685
690
  # The optional object may be a class name, module name or object
686
691
  # instance. When given a class or module name, the object is instantiated
@@ -720,6 +725,9 @@ class MQ
720
725
  rpcs[name] ||= RPC.new(self, name, obj)
721
726
  end
722
727
 
728
+ # Schedules the request to close the channel to be sent. Actual closing of
729
+ # the channels happens when Protocol::Channel::CloseOk is received from broker.
730
+ #
723
731
  def close
724
732
  if @deferred_status == :succeeded
725
733
  send Protocol::Channel::Close.new(:reply_code => 200,
@@ -732,6 +740,7 @@ class MQ
732
740
  end
733
741
 
734
742
  # Define a message and callback block to be executed on all errors.
743
+ #
735
744
  def self.error msg = nil, &blk
736
745
  if blk
737
746
  @error_callback = blk
@@ -740,16 +749,19 @@ class MQ
740
749
  end
741
750
  end
742
751
 
743
- def prefetch(size)
744
- @prefetch_size = size
745
- send Protocol::Basic::Qos.new(:prefetch_size => 0, :prefetch_count => size, :global => false)
752
+ # Asks the broker to set prefetch_count (size of the prefetch buffer) that the broker
753
+ # will maintain for outstanding unacknowledged messages on a this channel. This is
754
+ # Applications typically set the prefetch count to 1, which means the processing speed
755
+ # of the consumer exerts complete backpressure on the flow of messages in that channel.
756
+ #
757
+ def prefetch(count)
758
+ @prefetch_count = count
759
+ send Protocol::Basic::Qos.new(:prefetch_size => 0, :prefetch_count => count, :global => false)
746
760
  self
747
761
  end
748
762
 
749
- # Asks the broker to redeliver all unacknowledged messages on this
750
- # channel.
751
- #
752
- # * requeue (default false)
763
+ # Asks the broker to redeliver all unacknowledged messages on this channel.
764
+ # * :requeue - (default false)
753
765
  # If this parameter is false, the message will be redelivered to the original recipient.
754
766
  # If this flag is true, the server will attempt to requeue the message, potentially then
755
767
  # delivering it to an alternative subscriber.
@@ -773,6 +785,10 @@ class MQ
773
785
  @queues ||= {}
774
786
  end
775
787
 
788
+ # Yields a (Mutex-synchronized) FIFO queue of consumers that issued
789
+ # Protocol::Basic::Get requests (that is, called Queue#pop)
790
+ #
791
+ # Not typically called by client code.
776
792
  def get_queue
777
793
  if block_given?
778
794
  (@get_queue_mutex ||= Mutex.new).synchronize {
@@ -795,6 +811,8 @@ class MQ
795
811
  @consumers ||= {}
796
812
  end
797
813
 
814
+ # Resets and reinitializes the channel and its queues/exchanges
815
+ #
798
816
  def reset
799
817
  @deferred_status = nil
800
818
  @channel = nil
@@ -810,11 +828,13 @@ class MQ
810
828
  @queues = {}
811
829
  qus.each { |_, q| q.reset } if qus
812
830
 
813
- prefetch(@prefetch_size) if @prefetch_size
831
+ prefetch(@prefetch_count) if @prefetch_count
814
832
  end
815
833
 
834
+ # Tests connection status of associated AMQP connection
835
+ #
816
836
  def connected?
817
- connection.connected?
837
+ @connection.connected?
818
838
  end
819
839
 
820
840
  private
@@ -830,18 +850,20 @@ class MQ
830
850
  def log *args
831
851
  return unless MQ.logging
832
852
  pp args
833
- puts
853
+ puts ''
834
854
  end
835
-
836
- attr_reader :connection
837
- alias :conn :connection
838
855
  end
839
856
 
840
857
  #-- convenience wrapper (read: HACK) for thread-local MQ object
841
858
 
842
859
  class MQ
860
+ # unique identifier
861
+ def MQ.id
862
+ Thread.current[:mq_id] ||= "#{`hostname`.strip}-#{Process.pid}-#{Thread.current.object_id}"
863
+ end
864
+
843
865
  def MQ.default
844
- #-- XXX clear this when connection is closed
866
+ # TODO: clear this when connection is closed
845
867
  Thread.current[:mq] ||= MQ.new
846
868
  end
847
869
 
@@ -851,10 +873,3 @@ class MQ
851
873
  MQ.default.__send__(meth, *args, &blk)
852
874
  end
853
875
  end
854
-
855
- class MQ
856
- # unique identifier
857
- def MQ.id
858
- Thread.current[:mq_id] ||= "#{`hostname`.strip}-#{Process.pid}-#{Thread.current.object_id}"
859
- end
860
- end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arvicco-amqp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 11
10
- version: 0.6.11
9
+ - 13
10
+ version: 0.6.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aman Gupta
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-04 00:00:00 +03:00
19
+ date: 2010-11-05 00:00:00 +03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency