Module: Qup::TopicAPI

Included in:
Adapter::Kestrel::Topic, Adapter::Maildir::Topic, Adapter::Redis::Topic
Defined in:
lib/qup/topic_api.rb

Overview

Public: A TopicAPI for use in a publish-subscribe Messaging

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

This API MUST be implemented in each Adapter

Example:

session = Qup::Session.new( uri )
topic = session.topic( 'news' )

pub = topic.publisher

sub1 = topic.subscriber( 'sub1' )
sub2 = topic.subscriber( 'sub2' )

pub.publish( 'some news' )

message1 = sub1.consume
message2 = sub2.consume

Instance Method Summary collapse

Instance Method Details

#destroyObject

Public: destroy the Topic if possible

This will remove the Topic from the system if possible

Returns nothing.



68
69
70
71
72
# File 'lib/qup/topic_api.rb', line 68

def destroy
  super
rescue NoMethodError
  raise NotImplementedError, "please implement 'destroy'"
end

#nameObject

Public: the name of the Topic

Returns the String name



56
57
58
59
60
# File 'lib/qup/topic_api.rb', line 56

def name
  super
rescue NoMethodError
  raise NotImplementedError, "please implement 'name'"
end

#publish(message) ⇒ Object

Internal: Publish a Message to all the Subscribers

message - the Object to send to all subscribers

Returns nothing

Raises:

  • (NotImplementedError)


88
89
90
# File 'lib/qup/topic_api.rb', line 88

def publish( message )
  raise NotImplementedError, "please implement 'publish'"
end

#publisherObject

Public: Creates a Publisher for the Topic

Returns a new Publisher

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/qup/topic_api.rb', line 32

def publisher
  raise NotImplementedError, "please implement 'publisher'"
end

#subscriber(name) ⇒ Object

Public: 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

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/qup/topic_api.rb', line 48

def subscriber( name )
  raise NotImplementedError, "please implement 'subscriber'"
end

#subscriber_countObject

Public: Return the number of Subscribers to this Topic

Returns integer

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/qup/topic_api.rb', line 78

def subscriber_count
  raise NotImplementedError, "please implement 'subscriber_count'"
end