Module: DaemonObjects::AmqpSupport

Defined in:
lib/daemon_objects/amqp/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



2
3
4
# File 'lib/daemon_objects/amqp/runner.rb', line 2

def endpoint
  @endpoint
end

#prefetchObject

Returns the value of attribute prefetch.



2
3
4
# File 'lib/daemon_objects/amqp/runner.rb', line 2

def prefetch
  @prefetch
end

#queueObject

Returns the value of attribute queue.



2
3
4
# File 'lib/daemon_objects/amqp/runner.rb', line 2

def queue
  @queue
end

#worker_classObject

Returns the value of attribute worker_class.



2
3
4
# File 'lib/daemon_objects/amqp/runner.rb', line 2

def worker_class
  @worker_class
end

Instance Method Details

#argumentsObject



4
5
6
# File 'lib/daemon_objects/amqp/runner.rb', line 4

def arguments
  @arguments ||= {}
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/daemon_objects/amqp/runner.rb', line 8

def run
  logger.info "Preparing to start the AMQP watcher."

  AMQP.start(endpoint) do |connection, open_ok|
    logger.info "Starting up the AMQP watcher."

    channel  = AMQP::Channel.new(connection)
    channel.prefetch(1) if prefetch

    worker   = worker_class.new(
      channel, 
      get_consumer, 
      {
        :queue_name => queue,
        :logger     => logger,
        :arguments  => arguments
      })

    worker.start

    logger.info "AMQP worker started"

    Signal.trap("INT") do
      logger.info "Received signal 'INT'.  Exiting process"
      connection.close { EventMachine.stop } 
    end
  end
end