Class: Mumukit::Nuntius::Connection
- Inherits:
-
Object
- Object
- Mumukit::Nuntius::Connection
- Defined in:
- lib/mumukit/nuntius/connection.rb
Class Method Summary collapse
- .config ⇒ Object
- .connected? ⇒ Boolean
- .establish_connection ⇒ Object
- .start_channel(exchange_name) ⇒ Object
Class Method Details
.config ⇒ Object
4 5 6 7 |
# File 'lib/mumukit/nuntius/connection.rb', line 4 def config @config ||= YAML.load_interpolated(File. '../../../../config/rabbit.yml', __FILE__). with_indifferent_access[ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'] end |
.connected? ⇒ Boolean
21 22 23 |
# File 'lib/mumukit/nuntius/connection.rb', line 21 def connected? @connection.present? end |
.establish_connection ⇒ Object
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 |