Class: Workling::Invokers::AmqpSingleSubscriber

Inherits:
Base
  • Object
show all
Defined in:
lib/workling/invokers/amqp_single_subscriber.rb

Instance Attribute Summary

Attributes inherited from Base

#reset_time, #sleep_time

Instance Method Summary collapse

Methods inherited from Base

#logger, #run

Constructor Details

#initialize(routing, client_class) ⇒ AmqpSingleSubscriber

Returns a new instance of AmqpSingleSubscriber.



10
11
12
# File 'lib/workling/invokers/amqp_single_subscriber.rb', line 10

def initialize(routing, client_class)
  super
end

Instance Method Details

#listenObject

Starts EM loop and sets up subscription callback for the worker Create the queue and bind to exchange using the routing key



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/workling/invokers/amqp_single_subscriber.rb', line 18

def listen
  EM.run do
    connect do
      queue_name = @routing.queue_for
      routing_key = @routing.routing_key_for

      # temp stuff to hook the queues and exchanges up
      # wildcard routing - # (match all)
      exch = MQ.topic
      q = MQ.queue(queue_name)
      q.bind(exch, :key => routing_key)

      @client.subscribe(queue_name) do |args|
        run(queue_name, args)
      end
    end
  end
end

#stopObject



37
38
39
# File 'lib/workling/invokers/amqp_single_subscriber.rb', line 37

def stop
  EM.stop if EM.reactor_running?
end