Sha256: 3781d3ce2485095755502da6ce55031cc484c8f647f665321fbe2bf2a127926c

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

require "rubygems"
require "amqp"
require_relative "configurator"
require_relative "consumer"

module RabbitHutch
  @exchange_name = "amq.rabbitmq.trace"
  
  class Worker
    
    def initialize(channel, config, consumers)
      @channel = channel
      @channel.on_error(&method(:handle_channel_exception))
      @consumer = Consumer.new(consumers)
      @exchange_name = config.application['exchangename']
      @queue_name = config.application['queuename']
    end
  
    # begin listening for all topics in publish.#
    def start
      @exchange = @channel.topic(@exchange_name, :durable => true, :auto_delete => false, :internal => true)
      @queue = @channel.queue(@queue_name, :durable => true, :auto_delete => false)
      @queue.bind(@exchange, :routing_key => 'publish.#')
      @queue.subscribe(&@consumer.method(:handle_message))
    end
  
    def handle_channel_exception(channel, channel_close)
      puts "Oops... a channel-level exception: code = #{channel_close.reply_code}, message = #{channel_close.reply_text}"
    end
    
  end
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
dafiti-rabbit-hutch-0.1.12 lib/worker.rb
dafiti-rabbit-hutch-0.1.11 lib/worker.rb
dafiti-rabbit-hutch-0.1.10 lib/worker.rb
dafiti-rabbit-hutch-0.1.9 lib/worker.rb
dafiti-rabbit-hutch-0.1.5 lib/worker.rb
dafiti-rabbit-hutch-0.1.4 lib/worker.rb
dafiti-rabbit-hutch-0.1.1 lib/worker.rb
dafiti-rabbit-hutch-0.1.0 lib/worker.rb
rabbithutch-0.1.5 lib/worker.rb
rabbithutch-0.1.2 lib/worker.rb