Class: Bifrost::Bus

Inherits:
Object
  • Object
show all
Defined in:
lib/bifrost/bus.rb

Overview

This type represents the Bifrost as a managed entity NOTE: Warning, this object should never use shared state as it is referenced initialize each worker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBus

Returns a new instance of Bus.



10
11
12
13
14
15
# File 'lib/bifrost/bus.rb', line 10

def initialize
  Azure.sb_namespace = ENV['AZURE_BUS_NAMESPACE']
  host = "https://#{Azure.sb_namespace}.servicebus.windows.net"
  signer = Azure::ServiceBus::Auth::SharedAccessSigner.new(key, secret)
  @interface ||= Azure::ServiceBus::ServiceBusService.new(host, signer: signer)
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



8
9
10
# File 'lib/bifrost/bus.rb', line 8

def interface
  @interface
end

Instance Method Details

#create_topic(name) ⇒ Object

To encapsulate the underlying bus object we provide a custom interface for the methods of the Azure smb we use



19
20
21
# File 'lib/bifrost/bus.rb', line 19

def create_topic(name)
  @interface.create_topic(name)
end

#delete_topic(name) ⇒ Object



23
24
25
# File 'lib/bifrost/bus.rb', line 23

def delete_topic(name)
  @interface.delete_topic(name)
end

#topic_exists?(topic) ⇒ Boolean

Tells us if the topic has already been defined

Returns:

  • (Boolean)


35
36
37
# File 'lib/bifrost/bus.rb', line 35

def topic_exists?(topic)
  topics.include?(topic)
end

#topicsObject

This method returns a list of topics currently defined on the Bifrost



28
29
30
31
32
# File 'lib/bifrost/bus.rb', line 28

def topics
  @interface.list_topics.map do |t|
    Topic.new(t.name)
  end
end