Module: AutoReconfiguration::AMQP

Defined in:
lib/cf-autoconfig/messaging/amqp.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
# File 'lib/cf-autoconfig/messaging/amqp.rb', line 7

def self.included( base )
  base.send( :alias_method, :original_connect, :connect)
  base.send( :alias_method, :connect, :connect_with_cf )
end

Instance Method Details

#connect_with_cf(connection_options_or_string = {}, other_options = {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cf-autoconfig/messaging/amqp.rb', line 12

def connect_with_cf(connection_options_or_string = {}, other_options = {}, &block)
  service_names = CFRuntime::CloudApp.service_names_of_type('rabbitmq')
  if service_names.length == 1
    puts "Auto-reconfiguring AMQP."
    case connection_options_or_string
      when String then
        cfoptions = {}
      else
        cfoptions = connection_options_or_string
      end
    original_connect(CFRuntime::AMQPClient.options_for_svc(service_names[0],cfoptions),
      other_options, &block)
  else
    puts "Found #{service_names.length} rabbitmq services. Skipping auto-reconfiguration."
    original_connect(connection_options_or_string, other_options, &block)
  end
end