Class: Qup::Adapter::Redis::Topic
- Inherits:
-
Connection
- Object
- Connection
- Qup::Adapter::Redis::Topic
- Includes:
- TopicAPI
- Defined in:
- lib/qup/adapter/redis/topic.rb
Overview
Internal: The Qup implementation for a Redis Topic
Based on the API requirements, this is not implemented with Redis pub/sub, rather it guarantees durability of all published messages by using sub-queues internally to deliver messages to subscribers.
Instance Attribute Summary
Attributes inherited from Connection
Instance Method Summary collapse
-
#initialize(uri, name) ⇒ Topic
constructor
Internal: create a new 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 Connection
Constructor Details
#initialize(uri, name) ⇒ Topic
Internal: create a new Topic
uri - the connection uri for the Redis Client name - the String name of the Topic
Returns a new Topic.
20 21 22 23 |
# File 'lib/qup/adapter/redis/topic.rb', line 20 def initialize(uri, name) super @subscribers = Hash.new end |
Instance Method Details
#publish(message) ⇒ Object
Internal: Publish a Message to all the Subscribers
message - the Object to send to all subscribers
Returns nothing
56 57 58 59 60 |
# File 'lib/qup/adapter/redis/topic.rb', line 56 def publish( ) @subscribers.values.each do |subscriber| subscriber.produce end end |
#publisher ⇒ Object
Internal: Creates a Publisher for the Topic
Returns a new Publisher
28 29 30 |
# File 'lib/qup/adapter/redis/topic.rb', line 28 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.
Returns a Subscriber
40 41 42 |
# File 'lib/qup/adapter/redis/topic.rb', line 40 def subscriber(name) ::Qup::Subscriber.new( self, subscriber_queue_for(name) ) end |
#subscriber_count ⇒ Object
Internal: Return the number of Subscribers to this Topic
Returns integer
47 48 49 |
# File 'lib/qup/adapter/redis/topic.rb', line 47 def subscriber_count @subscribers.size end |