Class: Carrot::AMQP::Queue
- Inherits:
-
Object
- Object
- Carrot::AMQP::Queue
- Defined in:
- lib/amqp/queue.rb
Instance Attribute Summary collapse
-
#delivery_tag ⇒ Object
Returns the value of attribute delivery_tag.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #ack ⇒ Object
- #bind(exchange, opts = {}) ⇒ Object
- #consumer_count ⇒ Object
- #delete(opts = {}) ⇒ Object
-
#initialize(server, name, opts = {}) ⇒ Queue
constructor
A new instance of Queue.
- #message_count ⇒ Object
- #pop(opts = {}) ⇒ Object
- #publish(data, opts = {}) ⇒ Object
- #status(opts = {}, &blk) ⇒ Object
- #unbind(exchange, opts = {}) ⇒ Object
Constructor Details
#initialize(server, name, opts = {}) ⇒ Queue
6 7 8 9 10 11 12 13 |
# File 'lib/amqp/queue.rb', line 6 def initialize(server, name, opts = {}) @server = server @opts = opts @name = name server.send_frame( Protocol::Queue::Declare.new({ :queue => name, :nowait => true }.merge(opts)) ) end |
Instance Attribute Details
#delivery_tag ⇒ Object
Returns the value of attribute delivery_tag.
4 5 6 |
# File 'lib/amqp/queue.rb', line 4 def delivery_tag @delivery_tag end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/amqp/queue.rb', line 3 def name @name end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
3 4 5 |
# File 'lib/amqp/queue.rb', line 3 def server @server end |
Instance Method Details
#ack ⇒ Object
32 33 34 35 36 |
# File 'lib/amqp/queue.rb', line 32 def ack server.send_frame( Protocol::Basic::Ack.new(:delivery_tag => delivery_tag) ) end |
#bind(exchange, opts = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/amqp/queue.rb', line 58 def bind(exchange, opts = {}) exchange = exchange.respond_to?(:name) ? exchange.name : exchange bindings[exchange] = opts server.send_frame( Protocol::Queue::Bind.new({ :queue => name, :exchange => exchange, :routing_key => opts.delete(:key), :nowait => true }.merge(opts)) ) end |
#consumer_count ⇒ Object
46 47 48 |
# File 'lib/amqp/queue.rb', line 46 def consumer_count status.last end |
#delete(opts = {}) ⇒ Object
77 78 79 80 81 |
# File 'lib/amqp/queue.rb', line 77 def delete(opts = {}) server.send_frame( Protocol::Queue::Delete.new({ :queue => name, :nowait => true }.merge(opts)) ) end |
#message_count ⇒ Object
42 43 44 |
# File 'lib/amqp/queue.rb', line 42 def status.first end |
#pop(opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/amqp/queue.rb', line 15 def pop(opts = {}) self.delivery_tag = nil server.send_frame( Protocol::Basic::Get.new({ :queue => name, :consumer_tag => name, :no_ack => !opts.delete(:ack), :nowait => true }.merge(opts)) ) method = server.next_method return unless method.is_a?(Protocol::Basic::GetOk) self.delivery_tag = method.delivery_tag header = server.next_payload msg = server.next_payload raise 'unexpected length' if msg.length < header.size msg end |
#publish(data, opts = {}) ⇒ Object
38 39 40 |
# File 'lib/amqp/queue.rb', line 38 def publish(data, opts = {}) exchange.publish(data, opts) end |
#status(opts = {}, &blk) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/amqp/queue.rb', line 50 def status(opts = {}, &blk) server.send_frame( Protocol::Queue::Declare.new({ :queue => name, :passive => true }.merge(opts)) ) method = server.next_method [method., method.consumer_count] end |
#unbind(exchange, opts = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/amqp/queue.rb', line 66 def unbind(exchange, opts = {}) exchange = exchange.respond_to?(:name) ? exchange.name : exchange bindings.delete(exchange) server.send_frame( Protocol::Queue::Unbind.new({ :queue => name, :exchange => exchange, :routing_key => opts.delete(:key), :nowait => true }.merge(opts) ) ) end |