Class: BunnyExchanges::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/bunny_exchanges/manager.rb

Overview

Class keeps all configured exchanges through the same connection and channel.

Instance Method Summary collapse

Constructor Details

#initialize(config = BunnyExchanges.configuration) ⇒ Manager

Constructor.

Parameters:



12
13
14
15
16
# File 'lib/bunny_exchanges/manager.rb', line 12

def initialize config = BunnyExchanges.configuration
  @config    = config
  @exchanges = {}
  @channels  = {}
end

Instance Method Details

#get(action, connection_name) ⇒ Bunny::Exchange

Gets or builds the required exchange.

Parameters:

  • the (Symbol, Symbol)

    action name and the connection name

Returns:

  • (Bunny::Exchange)

    the required bunny exchange.

Raises:

  • (BunnyExchanges::Manager::UndefinedExchange)

    when the exchange is not defined.



23
24
25
26
27
28
29
# File 'lib/bunny_exchanges/manager.rb', line 23

def get action, connection_name
  exchanges[action.to_sym] ||= begin
    name, options = params_for(action)

    channel_for(connection_name).exchange(name, options)
  end
end