Class: HotBunnies::Queue
- Inherits:
-
Object
show all
- Defined in:
- lib/hot_bunnies/queue.rb
Defined Under Namespace
Classes: AsyncCallbackConsumer, BaseConsumer, BlockingCallbackConsumer, CallbackConsumer, Headers, Subscription
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(channel, name, options = {}) ⇒ Queue
Returns a new instance of Queue.
17
18
19
20
21
22
|
# File 'lib/hot_bunnies/queue.rb', line 17
def initialize(channel, name, options={})
@channel = channel
@name = name
@options = {:durable => false, :exclusive => false, :auto_delete => false, :passive => false, :arguments => Hash.new}.merge(options)
declare!
end
|
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
15
16
17
|
# File 'lib/hot_bunnies/queue.rb', line 15
def channel
@channel
end
|
#name ⇒ Object
Returns the value of attribute name.
15
16
17
|
# File 'lib/hot_bunnies/queue.rb', line 15
def name
@name
end
|
Instance Method Details
#bind(exchange, options = {}) ⇒ Object
24
25
26
27
|
# File 'lib/hot_bunnies/queue.rb', line 24
def bind(exchange, options={})
exchange_name = if exchange.respond_to?(:name) then exchange.name else exchange.to_s end
@channel.queue_bind(@name, exchange_name, options.fetch(:routing_key, ''), options[:arguments])
end
|
#delete ⇒ Object
34
35
36
|
# File 'lib/hot_bunnies/queue.rb', line 34
def delete
@channel.queue_delete(@name)
end
|
#get(options = {}) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/hot_bunnies/queue.rb', line 42
def get(options={})
response = @channel.basic_get(@name, !options.fetch(:ack, false))
if response
then [Headers.new(@channel, nil, response.envelope, response.props), String.from_java_bytes(response.body)]
else nil
end
end
|
#purge ⇒ Object
38
39
40
|
# File 'lib/hot_bunnies/queue.rb', line 38
def purge
@channel.queue_purge(@name)
end
|
#status ⇒ Object
56
57
58
59
|
# File 'lib/hot_bunnies/queue.rb', line 56
def status
response = @channel.queue_declare_passive(@name)
[response.message_count, response.consumer_count]
end
|
#subscribe(options = {}, &block) ⇒ Object
50
51
52
53
54
|
# File 'lib/hot_bunnies/queue.rb', line 50
def subscribe(options={}, &block)
subscription = Subscription.new(@channel, @name, options)
subscription.each(options, &block) if block
subscription
end
|
#unbind(exchange, options = {}) ⇒ Object
29
30
31
32
|
# File 'lib/hot_bunnies/queue.rb', line 29
def unbind(exchange, options={})
exchange_name = if exchange.respond_to?(:name) then exchange.name else exchange.to_s end
@channel.queue_unbind(@name, exchange_name, options.fetch(:routing_key, ''))
end
|