Class: Qup::Consumer

Inherits:
Object
  • Object
show all
Defined in:
lib/qup/consumer.rb

Overview

Public: Consumes items for a queue

A Consumer is created from a Queue and consumes messages from the queue.

Direct Known Subclasses

Subscriber

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Consumer

Public: Create a new Consumer

queue - the Queue this producer is for

Returns a new Consumer



13
14
15
# File 'lib/qup/consumer.rb', line 13

def initialize( queue )
  @queue = queue
end

Instance Method Details

#acknowledge(message) ⇒ Object

Public: Acknowledge a consumed message

message - The message you are acknowledging

A consumed message must be acknowledge so the back end system can be assured that the message has been a fully processed.

Returns nothing.



38
39
40
# File 'lib/qup/consumer.rb', line 38

def acknowledge( message )
  @queue.acknowledge( message )
end

#consume(&block) ⇒ Object

Public: Consume a message for the queue

Yields the message

Most of the time you will want to call this message with a block as the Message will be auto-acknowledged. If you do not consume messages with a block, then you are required to acknowledge the messages on your own.

Returns a Message



26
27
28
# File 'lib/qup/consumer.rb', line 26

def consume(&block)
  @queue.consume(&block)
end

#depthObject

Public: Return how many messages are on the queue for this consumer

Returns an integer



45
46
47
# File 'lib/qup/consumer.rb', line 45

def depth
  @queue.depth
end