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, #initialize

Constructor Details

This class inherits a constructor from Qup::Adapter::Redis::Connection

Instance Method Details

#publish(message) ⇒ Object

Internal: Publish a Message to all the Subscribers

message - the Object to send to all subscribers

Returns nothing



48
49
50
51
52
# File 'lib/qup/adapter/redis/topic.rb', line 48

def publish( message )
  subscribers.each do |subscriber|
    @client.lpush subscriber, message
  end
end

#publisherObject

Internal: Creates a Publisher for the Topic

Returns a new Publisher



17
18
19
# File 'lib/qup/adapter/redis/topic.rb', line 17

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

#subscriber(name) ⇒ Object

Internal: Create and register 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



29
30
31
32
33
34
# File 'lib/qup/adapter/redis/topic.rb', line 29

def subscriber(name)
  subscriber_name = "#{@name}.#{name}"
  @client.sadd @name, subscriber_name
  queue = ::Qup::Adapter::Redis::Queue.new(@uri, subscriber_name, @name)
  ::Qup::Subscriber.new( self, queue )
end

#subscriber_countObject

Internal: Return the number of Subscribers to this Topic

Returns integer



39
40
41
# File 'lib/qup/adapter/redis/topic.rb', line 39

def subscriber_count
  subscribers.size
end