Sha256: c822aa6f10d2a40e88c1e6b9da36dd4ec2c4484c0e7c0cb80e415bb30bdb3331

Contents?: true

Size: 799 Bytes

Versions: 19

Compression:

Stored size: 799 Bytes

Contents

require 'bunny'
require 'yajl'

class AmqpQueueDecorator
  def initialize queue
    @queue = queue
  end

  def pop
    m = @queue.pop
    p = m[:payload]
    p == :queue_empty ? nil : p
  end
end

class AmqpExchangeDecorator
  def initialize exchange
    @exchange = exchange
  end

  def publish msg
    serialized_msg = Yajl::Encoder.encode(msg)
    @exchange.publish serialized_msg
  end
end

class AmqpService
  def initialize connection_config
    @connection_config = connection_config.merge(:spec => "09")
  end

  def start_worker file_queue_name, reply_exchange_name
    Bunny.run @connection_config do |b|
      queue = b.queue file_queue_name
      exchange = b.exchange reply_exchange_name
      yield AmqpQueueDecorator.new(queue), AmqpExchangeDecorator.new(exchange)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
gorgon-0.5.0.rc1 lib/gorgon/amqp_service.rb
gorgon-0.4.5 lib/gorgon/amqp_service.rb
gorgon-0.4.5.rc1 lib/gorgon/amqp_service.rb
gorgon-0.4.4 lib/gorgon/amqp_service.rb
gorgon-0.4.3 lib/gorgon/amqp_service.rb
gorgon-0.4.2 lib/gorgon/amqp_service.rb
gorgon-0.4.1 lib/gorgon/amqp_service.rb
gorgon-0.4.1.rc1 lib/gorgon/amqp_service.rb
gorgon-0.4.0 lib/gorgon/amqp_service.rb
gorgon-0.4.0.rc2 lib/gorgon/amqp_service.rb
gorgon-0.4.0.rc1 lib/gorgon/amqp_service.rb
gorgon-0.3.2 lib/gorgon/amqp_service.rb
gorgon-0.3.1 lib/gorgon/amqp_service.rb
gorgon-0.3.0 lib/gorgon/amqp_service.rb
gorgon-0.2.0 lib/gorgon/amqp_service.rb
gorgon-0.1.1 lib/gorgon/amqp_service.rb
gorgon-0.1.0 lib/gorgon/amqp_service.rb
gorgon-0.0.2 lib/gorgon/amqp_service.rb
gorgon-0.0.1 lib/gorgon/amqp_service.rb