Class: RServiceBus2::AppResource

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

Overview

Wrapper base class for resources used by applications, allowing rservicebus to configure the resource - dependency injection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, uri) ⇒ AppResource

Resources are attached, 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



26
27
28
29
30
31
32
# File 'lib/rservicebus2/appresource.rb', line 26

def initialize(host, uri)
  @host = host
  @uri = uri
  # Do a connect / disconnect loop on startup to validate the connection
  _connect
  finished
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/rservicebus2/appresource.rb', line 7

def connection
  @connection
end

Instance Method Details

#_connectObject



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

def _connect
  @connection = connect(@uri)
  RServiceBus2.rlog "#{self.class.name}. Connected to, #{@uri}"
end

#beginObject

Transaction Semantics



54
55
# File 'lib/rservicebus2/appresource.rb', line 54

def begin
end

#commitObject

Transaction Semantics



58
59
# File 'lib/rservicebus2/appresource.rb', line 58

def commit
end

#connect(_uri) ⇒ Object

The method which actually connects to the resource.



10
11
12
# File 'lib/rservicebus2/appresource.rb', line 10

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

#finishedObject

A notification that ocurs after getResource, to allow cleanup



35
36
37
# File 'lib/rservicebus2/appresource.rb', line 35

def finished
  @connection.close
end

#get_resourceObject



19
20
21
# File 'lib/rservicebus2/appresource.rb', line 19

def get_resource
  @connection
end

#reconnectObject

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

healthy


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rservicebus2/appresource.rb', line 41

def reconnect
  begin
    finished
  rescue StandardError => e
    puts '** AppResource. An error was raised while closing connection
          to, ' + @uri
    puts 'Message: ' + e.message
    puts e.backtrace
  end
  _connect
end

#rollbackObject

Transaction Semantics



62
63
# File 'lib/rservicebus2/appresource.rb', line 62

def rollback
end