Module: Marconi

Extended by:
Marconi
Included in:
Marconi
Defined in:
lib/marconi.rb,
lib/marconi/config.rb,
lib/marconi/envelope.rb,
lib/marconi/exchange.rb,
lib/marconi/receiver.rb,
lib/marconi/smart_xml.rb,
lib/marconi/broadcaster.rb,
lib/marconi/guid_generator.rb

Defined Under Namespace

Modules: Broadcaster, GUIDGenerator, Receiver, SmartXML Classes: Config, Envelope, Exchange

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backup_queue_class_nameObject

Returns the value of attribute backup_queue_class_name.



6
7
8
# File 'lib/marconi.rb', line 6

def backup_queue_class_name
  @backup_queue_class_name
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/marconi.rb', line 6

def logger
  @logger
end

Instance Method Details

#application_nameObject



34
35
36
# File 'lib/marconi.rb', line 34

def application_name
  config.name
end

#backup_queue_classObject

this uses eval to get the class from its name because otherwise rails class reloading in dev will screw everything up



14
15
16
# File 'lib/marconi.rb', line 14

def backup_queue_class
  eval(backup_queue_class_name)
end

#configObject



30
31
32
# File 'lib/marconi.rb', line 30

def config
  @config ||= Config.new
end

#errorObject



26
27
28
# File 'lib/marconi.rb', line 26

def error
  @error ||= exchange('marconi.events.error')
end

#exchange(name) ⇒ Object



73
74
75
76
# File 'lib/marconi.rb', line 73

def exchange(name)
  @registry ||= {}
  @registry[name] ||= Exchange.new(name)
end

#inboundObject



18
19
20
# File 'lib/marconi.rb', line 18

def inbound
  @inbound ||= exchange('marconi.events.inbound')
end

#init(config_file, env) ⇒ Object



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

def init(config_file, env)
  @config = Config.new(config_file, env)
end

#listenObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/marconi.rb', line 42

def listen
  config.listeners.each do |class_name|
    fork do

      # this is to ditch any exit handlers.  Minitest in ruby 1.9
      # for some reason sets itself to run an empty suite at exit.
      at_exit { exit! }

      # Change the process name as it appears in ps/top so the proc 
      # is easy to identify
      $0 = "ruby #{$0} Marconi.listen [#{class_name}]"

      class_name.constantize.listen
    end
  end

  Process.waitall
rescue Interrupt
  Process.kill("-INT",0) # interrupt the whole process group
end

#log(message) ⇒ Object



78
79
80
# File 'lib/marconi.rb', line 78

def log(message)
  logger.info(message) if logger
end

#outboundObject



22
23
24
# File 'lib/marconi.rb', line 22

def outbound
  @outbound ||= exchange('marconi.events.outbound')
end

#run_recovery_loopObject



63
64
65
66
67
68
69
70
71
# File 'lib/marconi.rb', line 63

def run_recovery_loop
  if backup_queue_class
    backup_queue_class.find_each do |bc|
      if exchange(bc.exchange_name).publish(bc.body, :topic => bc.topic, :recovering => true)
        bc.destroy
      end
    end
  end
end

#short_application_nameObject



38
39
40
# File 'lib/marconi.rb', line 38

def short_application_name
  config.short_name
end