Module: DramaQueen::Producer

Defined in:
lib/drama_queen/producer.rb

Overview

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 consumers that have subscribed 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.

Instance Method Summary collapse

Instance Method Details

#publish(routing_key, *args) ⇒ Boolean

Returns true if anything was published; false if not.

Parameters:

  • routing_key
  • args

Returns:

  • (Boolean)

    true if anything was published; false if not.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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