Class: Qup::Adapter::Kestrel::Topic
- Inherits:
-
Destination
- Object
- Destination
- Qup::Adapter::Kestrel::Topic
- 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
Instance Method Summary collapse
-
#destroy ⇒ Object
Internal: Destroy the topic.
-
#publish(message) ⇒ Object
Internal: Publish a Message to all the Subscribers.
-
#publisher ⇒ Object
Internal : Creates a Publisher for the Topic.
-
#subscriber(name) ⇒ Object
Internal: Create a subscriber for the Topic.
-
#subscriber_count ⇒ Object
Internal: Return the number of Subscribers to this Topic.
Methods included from TopicAPI
Methods inherited from Destination
Constructor Details
This class inherits a constructor from Qup::Adapter::Kestrel::Destination
Instance Method Details
#destroy ⇒ Object
Internal: Destroy the topic
Returns nothing
38 39 40 41 42 43 |
# File 'lib/qup/adapter/kestrel/topic.rb', line 38 def destroy subscribers.each do |name, sub| sub.destroy end @client.delete( @name ) end |
#publish(message) ⇒ Object
Internal: Publish a Message to all the Subscribers
message - the Object to send to all subscribers
Returns nothing
64 65 66 |
# File 'lib/qup/adapter/kestrel/topic.rb', line 64 def publish( ) @client.set( @name, ) # do not expire the message end |
#publisher ⇒ Object
Internal : Creates a Publisher for the Topic
Returns a new Publisher
16 17 18 |
# File 'lib/qup/adapter/kestrel/topic.rb', line 16 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
31 32 33 |
# File 'lib/qup/adapter/kestrel/topic.rb', line 31 def subscriber( name ) ::Qup::Subscriber.new( self, subscriber_queue( name ) ) end |
#subscriber_count ⇒ Object
Internal: Return the number of Subscribers to this Topic
We want the sub portion of the json document that is in the ‘counters’ section. The keys in the ‘counters’ section that represent queue counters are all prefixed with ‘q/<queue_name>/<stat>’. To count the number of subscribers to this topic, we just count the uniqe <queue_name> elements that start with this queue’s name and followed by a ‘+’
Returns integer
55 56 57 |
# File 'lib/qup/adapter/kestrel/topic.rb', line 55 def subscriber_count subscriber_names.size end |