Class: SimpleMessaging::MessageQueue::Rabbit
- Inherits:
-
SimpleMessaging::MessageQueue
- Object
- SimpleMessaging::MessageQueue
- SimpleMessaging::MessageQueue::Rabbit
- Defined in:
- lib/simple_messaging/message_queue/rabbit.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #delete ⇒ Object
- #enqueue(message) ⇒ Object
-
#initialize(name) ⇒ Rabbit
constructor
A new instance of Rabbit.
- #poll(&block) ⇒ Object
- #pop(&block) ⇒ Object
Methods inherited from SimpleMessaging::MessageQueue
driver_name, driver_name=, instance, unregister_queue
Constructor Details
#initialize(name) ⇒ Rabbit
Returns a new instance of Rabbit.
9 10 11 12 13 14 15 16 |
# File 'lib/simple_messaging/message_queue/rabbit.rb', line 9 def initialize(name) @@em_thread ||= Thread.new { EventMachine.run } @@connection ||= AMQP.connect(rabbit_configs) @channel = AMQP::Channel.new(@@connection) @exchange = @channel.default_exchange @queue = @channel.queue(queue_name(name)) @name = name end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
7 8 9 |
# File 'lib/simple_messaging/message_queue/rabbit.rb', line 7 def channel @channel end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/simple_messaging/message_queue/rabbit.rb', line 7 def name @name end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
7 8 9 |
# File 'lib/simple_messaging/message_queue/rabbit.rb', line 7 def queue @queue end |
Instance Method Details
#delete ⇒ Object
37 38 39 40 |
# File 'lib/simple_messaging/message_queue/rabbit.rb', line 37 def delete MessageQueue.unregister_queue(name) @queue.delete end |
#enqueue(message) ⇒ Object
18 19 20 21 22 |
# File 'lib/simple_messaging/message_queue/rabbit.rb', line 18 def enqueue() @exchange.publish , :routing_key => @queue.name, :app_id => app_id end |
#poll(&block) ⇒ Object
24 25 26 27 28 |
# File 'lib/simple_messaging/message_queue/rabbit.rb', line 24 def poll(&block) @queue.subscribe do |, payload| yield payload end end |
#pop(&block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/simple_messaging/message_queue/rabbit.rb', line 30 def pop(&block) @queue.subscribe do |, payload| yield payload break end end |