Class: Ragnar::SimpleQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/ragnar/simple_queue.rb

Overview

Simple publishing via a wrapper around bunny

Class Method Summary collapse

Class Method Details

.optionsObject



8
9
10
11
12
13
14
# File 'lib/ragnar/simple_queue.rb', line 8

def self.options
  @options ||= {
    :host => Ragnar::Config.host,
    :port => Ragnar::Config.port,
    :logging => false
  }
end

.publish(message, route, exchange, opts = {}) ⇒ Object

Note this method does not bind a queue to an exchange, therefore it’s required that the queue/exchange are already bound before calling this method



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ragnar/simple_queue.rb', line 19

def self.publish(message, route, exchange, opts={})
  # delete the exchange type from the options or set it to topic
  exchange_type = opts.delete(:exchange_type) { 'topic' }
  @publish_mutex ||= ::Mutex.new

  @publish_mutex.synchronize do
    ::Bunny.run(options) do |bunny|
      exchange = bunny.exchange(exchange, :type => exchange_type)
      exchange.publish(message, opts.merge(:key => route))
    end
  end
end