Class: Qup::Adapter::Redis::Topic

Inherits:
Connection show all
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

#name

Instance Method Summary collapse

Methods included from TopicAPI

#destroy, #name

Methods inherited from Connection

#destroy

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( message )
  @subscribers.values.each do |subscriber|
    subscriber.produce message
  end
end

#publisherObject

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_countObject

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