Class: Mumukit::Nuntius::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/nuntius/connection.rb

Class Method Summary collapse

Class Method Details

.configObject



4
5
6
7
# File 'lib/mumukit/nuntius/connection.rb', line 4

def config
  @config ||= YAML.load_interpolated(File.expand_path '../../../../config/rabbit.yml', __FILE__).
      with_indifferent_access[ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development']
end

.connected?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/mumukit/nuntius/connection.rb', line 21

def connected?
  @connection.present?
end

.establish_connectionObject



16
17
18
19
# File 'lib/mumukit/nuntius/connection.rb', line 16

def establish_connection
  raise 'Nuntius connection already established' if connected?
  @connection = Bunny.new(host: config[:host], port: config[:port], user: config[:user], password: config[:password])
end

.start_channel(exchange_name) ⇒ Object



9
10
11
12
13
14
# File 'lib/mumukit/nuntius/connection.rb', line 9

def start_channel(exchange_name)
  raise 'Nuntius connection isn\'t established' unless connected?
  channel = @connection.start.create_channel
  exchange = channel.fanout(exchange_name)
  [channel, exchange]
end