Class: RServiceBus2::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus2/monitor.rb

Overview

Monitor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bus, name, uri) ⇒ Monitor

Resources are attached resources, and can be specified using the URI syntax.

Parameters:

  • uri (String)

    a location for the resource to which we will attach, eg redis://127.0.0.1/foo



28
29
30
31
32
33
34
35
36
# File 'lib/rservicebus2/monitor.rb', line 28

def initialize(bus, name, uri)
  @bus = bus
  new_anonymous_class = Class.new(MonitorMessage)
  Object.const_set(name, new_anonymous_class)
  @msg_type = Object.const_get(name)

  @uri = uri
  _connect
end

Instance Attribute Details

#busObject

Returns the value of attribute bus.



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

def bus
  @bus
end

Instance Method Details

#_connectObject



18
19
20
21
22
# File 'lib/rservicebus2/monitor.rb', line 18

def _connect
  @connection = connect(@uri)
  @bus.log "#{self.class.name}. Connected to, #{@uri}" if
    ENV['QUIET'].nil?
end

#connect(_uri) ⇒ Object

The method which actually connects to the resource.



9
10
11
# File 'lib/rservicebus2/monitor.rb', line 9

def connect(_uri)
  raise 'Method, connect, needs to be implemented for resource'
end

#finishedObject

A notification that allows cleanup



39
40
41
# File 'lib/rservicebus2/monitor.rb', line 39

def finished
  RServiceBus2.rlog "#{self.class.name}. Default Finished"
end

#lookObject

The method which actually connects to the resource.



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

def look
  raise 'Method, Look, needs to be implemented for the Monitor'
end

#reconnectObject

At least called in the Host rescue block, to ensure all network links

are healthy


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rservicebus2/monitor.rb', line 45

def reconnect
  begin
    finished
  rescue StandardError => e
    puts "** Monitor. An error was raised while closing connection to, #{@uri}"
    puts "Message: #{e.message}"
    puts e.backtrace
  end

  _connect
end

#send(payload, uri) ⇒ Object



57
58
59
60
61
# File 'lib/rservicebus2/monitor.rb', line 57

def send(payload, uri)
  msg = @msg_type.new(payload, uri)

  @bus.send(msg)
end