Class: Qup::Adapter::Kestrel::Topic

Inherits:
Destination show all
Includes:
TopicAPI
Defined in:
lib/qup/adapter/kestrel/topic.rb

Overview

Internal: The Topic implementation for the Kestrel Adapter

The topic delivers each Message that it is give to each and every Subscriber

Instance Attribute Summary

Attributes inherited from Destination

#name

Instance Method Summary collapse

Methods included from TopicAPI

#destroy, #name

Methods inherited from Destination

#destroy, #initialize, #ping

Constructor Details

This class inherits a constructor from Qup::Adapter::Kestrel::Destination

Instance Method Details

#publish(message) ⇒ Object

Internal: Publish a Message to all the Subscribers

message - the Object to send to all subscribers

Returns nothing



51
52
53
# File 'lib/qup/adapter/kestrel/topic.rb', line 51

def publish( message )
  @client.set( @name, message )
end

#publisherObject

Internal : Creates a Publisher for the Topic

Returns a new Publisher



14
15
16
# File 'lib/qup/adapter/kestrel/topic.rb', line 14

def publisher
  ::Qup::Publisher.new( self )
end

#subscriber(name) ⇒ Object

Internal: Create a subscriber for the Topic

name - the String name of the subscriber

Creating a subscriber creates a new Subscriber that will receive a copy of every message that is published to the Topic.

Subscribers are unique by name, two subscribers with the same name will act as individual Consumers on a queue of their name.

Returns a Subscriber



29
30
31
# File 'lib/qup/adapter/kestrel/topic.rb', line 29

def subscriber( name )
  ::Qup::Subscriber.new( self, subscriber_queue( name ) )
end

#subscriber_countObject

Internal: Return the number of Subscribers to this Topic

Returns integer



37
38
39
40
41
42
43
44
# File 'lib/qup/adapter/kestrel/topic.rb', line 37

def subscriber_count
  c = 0
  @client.stats['queues'].keys.each do |k|
    next if k =~ /errors$/
    c += 1 if k =~ /^#{@name}\+/
  end
  return c
end