Class: HotBunnies::Queue
- Inherits:
-
Object
show all
- Defined in:
- lib/hot_bunnies/queue.rb
Defined Under Namespace
Modules: Subscriber
Classes: BlockingSubscriber, Headers, Subscription
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(channel, name, options = {}) ⇒ Queue
Returns a new instance of Queue.
7
8
9
10
11
12
|
# File 'lib/hot_bunnies/queue.rb', line 7
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.
5
6
7
|
# File 'lib/hot_bunnies/queue.rb', line 5
def channel
@channel
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/hot_bunnies/queue.rb', line 5
def name
@name
end
|
Instance Method Details
#bind(exchange, options = {}) ⇒ Object
14
15
16
17
|
# File 'lib/hot_bunnies/queue.rb', line 14
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
24
25
26
|
# File 'lib/hot_bunnies/queue.rb', line 24
def delete
@channel.queue_delete(@name)
end
|
#get(options = {}) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/hot_bunnies/queue.rb', line 32
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
28
29
30
|
# File 'lib/hot_bunnies/queue.rb', line 28
def purge
@channel.queue_purge(@name)
end
|
#status ⇒ Object
46
47
48
49
|
# File 'lib/hot_bunnies/queue.rb', line 46
def status
response = @channel.queue_declare_passive(@name)
[response.message_count, response.consumer_count]
end
|
#subscribe(options = {}, &block) ⇒ Object
40
41
42
43
44
|
# File 'lib/hot_bunnies/queue.rb', line 40
def subscribe(options={}, &block)
subscription = Subscription.new(@channel, @name, options)
subscription.each(options, &block) if block
subscription
end
|
#unbind(exchange, options = {}) ⇒ Object
19
20
21
22
|
# File 'lib/hot_bunnies/queue.rb', line 19
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
|