module DramaQueen::Producer

A producer is an object that has content to provide on a topic. When it decides it has content to publish on that topic, it simply passes that info on to all of the +consumer+s that have +subscribe+d to the topic. Actually, it doesn’t have to pass any info on–it can simply act like a ping to the subscribers; this is up to how you want to use them.

Public Instance Methods

publish(routing_key, *args) click to toggle source

@param routing_key @param args @return [Boolean] true if anything was published; false if not.

# File lib/drama_queen/producer.rb, line 17
def publish(routing_key, *args)
  exchange = DramaQueen.exchange_for(routing_key)
  exchange ||= DramaQueen::Exchange.new(routing_key)

  all_exchanges = [exchange] + exchange.related_exchanges
  subscription_count = 0

  all_exchanges.each do |exchange|
    subscription_count += exchange.subscribers.size
    exchange.notify_with(*args)
  end

  !subscription_count.zero?
end