class Bifrost::Topic

Topics are central to the pub/sub system in the Bifrost. All messages must be delivered to a topic. The topic is responsible for forwarding the message to registered subscribers

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
Calls superclass method Bifrost::Entity::new
# File lib/bifrost/topic.rb, line 11
def initialize(name)
  @name ||= name
  super()
end

Public Instance Methods

==(other) click to toggle source
# File lib/bifrost/topic.rb, line 73
def ==(other)
  name == other.name && self.class == other.class
end
add_subscriber(subscriber) click to toggle source

A new subscriber can be added to a topic

# File lib/bifrost/topic.rb, line 44
def add_subscriber(subscriber)
  if exists?
    begin
      @bus.interface.create_subscription(name, subscriber.name)
    rescue Azure::Core::Http::HTTPError => e
      return false if e.status_code == 409
      raise e
    end
    true
  else
    false
  end
end
delete() click to toggle source

If a topic is defined, we can remove the definition

# File lib/bifrost/topic.rb, line 27
def delete
  if exists?
    @bus.delete_topic(name)
    true
  else
    false
  end
end
exists?() click to toggle source

Topics are self aware, and know if they exist or not, but only with the help of the almighty bus

# File lib/bifrost/topic.rb, line 79
def exists?
  @bus.topic_exists?(self)
end
remove_subscriber(subscriber) click to toggle source

A topic subscriber can be removed from the topic if it exists

# File lib/bifrost/topic.rb, line 59
def remove_subscriber(subscriber)
  if exists?
    begin
      @bus.interface.delete_subscription(name, subscriber.name)
    rescue Azure::Core::Http::HTTPError => e
      return false if e.status_code == 404
      raise e
    end
    true
  else
    false
  end
end
save() click to toggle source

If a topic has not been defined we can save it, so it becomes defined

# File lib/bifrost/topic.rb, line 17
def save
  if exists?
    false
  else
    @bus.create_topic(name)
    true
  end
end
subscribers() click to toggle source

This method returns a list of subscribers currently defined on the topic

# File lib/bifrost/topic.rb, line 37
def subscribers
  @bus.interface.list_subscriptions(name).map do |s|
    Subscriber.new(s.name)
  end
end
to_s() click to toggle source
# File lib/bifrost/topic.rb, line 83
def to_s
  name
end