rservicebus2 0.2.10 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rservicebus2.rb +6 -4
- data/lib/rservicebus2/appresource/awss3.rb +3 -3
- data/lib/rservicebus2/appresource/awssqs.rb +2 -0
- data/lib/rservicebus2/appresource/dir.rb +3 -0
- data/lib/rservicebus2/appresource/file.rb +2 -0
- data/lib/rservicebus2/appresource/fluiddb.rb +3 -0
- data/lib/rservicebus2/appresource/fluiddb2.rb +3 -1
- data/lib/rservicebus2/config.rb +38 -29
- data/lib/rservicebus2/endpointmapping.rb +2 -4
- data/lib/rservicebus2/handler_manager.rb +1 -1
- data/lib/rservicebus2/helper_functions.rb +14 -13
- data/lib/rservicebus2/host.rb +1 -1
- data/lib/rservicebus2/message.rb +2 -0
- data/lib/rservicebus2/message/statisticoutput.rb +2 -0
- data/lib/rservicebus2/message/subscription.rb +2 -0
- data/lib/rservicebus2/message/verboseoutput.rb +2 -0
- data/lib/rservicebus2/monitor.rb +7 -7
- data/lib/rservicebus2/monitor/awss3.rb +3 -1
- data/lib/rservicebus2/monitor/awssqs.rb +9 -7
- data/lib/rservicebus2/monitor/dir.rb +24 -22
- data/lib/rservicebus2/monitor/dirnotifier.rb +3 -0
- data/lib/rservicebus2/monitor/message.rb +2 -0
- data/lib/rservicebus2/monitor/xmldir.rb +2 -0
- data/lib/rservicebus2/monitor_configure.rb +46 -36
- data/lib/rservicebus2/mq.rb +27 -30
- data/lib/rservicebus2/saga_loader.rb +27 -24
- data/lib/rservicebus2/saga_storage.rb +5 -4
- data/lib/rservicebus2/sendat_storage/file.rb +0 -1
- data/lib/rservicebus2/state_manager.rb +3 -3
- data/lib/rservicebus2/state_storage.rb +7 -6
- data/lib/rservicebus2/statistic_manager.rb +7 -3
- data/lib/rservicebus2/subscription_manager.rb +7 -5
- data/lib/rservicebus2/subscription_storage.rb +6 -5
- data/lib/rservicebus2/subscription_storage/file.rb +5 -18
- data/lib/rservicebus2/subscription_storage_configure.rb +2 -0
- data/lib/rservicebus2/transporter.rb +63 -52
- metadata +2 -3
- data/lib/rservicebus2/stats.rb +0 -68
@@ -1,38 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cgi'
|
2
4
|
require 'zip/zip'
|
3
5
|
require 'zlib'
|
4
6
|
|
5
7
|
module RServiceBus2
|
6
8
|
# Monitor Directory for files
|
9
|
+
|
7
10
|
# rubocop:disable Metrics/ClassLength
|
8
11
|
class MonitorDir < Monitor
|
9
|
-
def
|
12
|
+
def input_dir(uri)
|
10
13
|
# Pass the path through the Dir object to check syntax on startup
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
and create it as a directory."
|
28
|
-
puts "***** eg, rm #{uri.path} && mkdir #{uri.path}"
|
29
|
-
abort
|
30
|
-
end
|
14
|
+
return Dir.new(uri.path) if File.writable?(uri.path)
|
15
|
+
|
16
|
+
puts "***** Directory is not writable, #{uri.path}.\n" \
|
17
|
+
"***** Make the directory, #{uri.path}, writable and try again."
|
18
|
+
abort
|
19
|
+
rescue Errno::ENOENT
|
20
|
+
puts "***** Directory does not exist, #{uri.path}.\n" \
|
21
|
+
"***** Create the directory, #{uri.path}, and try again.\n" \
|
22
|
+
"***** eg, mkdir #{uri.path}"
|
23
|
+
abort
|
24
|
+
rescue Errno::ENOTDIR
|
25
|
+
puts "***** The specified path does not point to a directory, #{uri.path}.\n" \
|
26
|
+
"***** Either repoint path to a directory, or remove, #{uri.path}, and create it as a directory.\n" \
|
27
|
+
"***** eg, rm #{uri.path} && mkdir #{uri.path}"
|
28
|
+
abort
|
29
|
+
end
|
31
30
|
|
32
|
-
|
31
|
+
def connect(uri)
|
32
|
+
@path = input_dir(uri).path
|
33
33
|
@input_filter = []
|
34
34
|
|
35
35
|
return if uri.query.nil?
|
36
|
+
|
36
37
|
parts = CGI.parse(uri.query)
|
37
38
|
@querystringparts = parts
|
38
39
|
if parts.key?('archive')
|
@@ -141,4 +142,5 @@ module RServiceBus2
|
|
141
142
|
end
|
142
143
|
end
|
143
144
|
end
|
145
|
+
# rubocop:enable Metrics/ClassLength
|
144
146
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cgi'
|
2
4
|
require 'fileutils'
|
3
5
|
require 'pathname'
|
@@ -6,6 +8,7 @@ module RServiceBus2
|
|
6
8
|
# Monitor for Directory
|
7
9
|
class MonitorDirNotifier < Monitor
|
8
10
|
attr_reader :path, :processing_folder, :filter
|
11
|
+
|
9
12
|
def connect(uri)
|
10
13
|
# Pass the path through the Dir object to check syntax on startup
|
11
14
|
begin
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rservicebus2/monitor'
|
2
4
|
require 'rservicebus2/monitor/message'
|
3
5
|
|
@@ -16,56 +18,64 @@ module RServiceBus2
|
|
16
18
|
@resource_list = {}
|
17
19
|
end
|
18
20
|
|
21
|
+
def conditionally_set_app_resource(monitor, key, val)
|
22
|
+
monitor.instance_variable_set("@#{key}", val.resource)
|
23
|
+
@resource_list[monitor.class.name] = [] if @resource_list[monitor.class.name].nil?
|
24
|
+
@resource_list[monitor.class.name] << val
|
25
|
+
@host.log "App resource attribute, #{key}, set for: #{monitor.class.name}"
|
26
|
+
end
|
27
|
+
|
19
28
|
# Assigns appropriate resources to writable attributes in the handler that
|
20
29
|
# match keys in the resource hash
|
21
30
|
# @param [RServiceBus2::Handler] handler
|
22
|
-
def
|
31
|
+
def conditionally_set_app_resources(monitor)
|
23
32
|
RServiceBus2.rlog "Checking app resources for: #{monitor.class.name}"
|
24
|
-
RServiceBus2.rlog "If your attribute is not getting set, check that it is
|
25
|
-
in the 'attr_accessor' list"
|
33
|
+
RServiceBus2.rlog "If your attribute is not getting set, check that it is in the 'attr_accessor' list"
|
26
34
|
@resource_manager.all.each do |k, v|
|
27
35
|
next unless monitor.class.method_defined?(k)
|
28
36
|
|
29
|
-
monitor
|
30
|
-
@resource_list[monitor.class.name] = [] if
|
31
|
-
@resource_list[monitor.class.name].nil?
|
32
|
-
@resource_list[monitor.class.name] << v
|
33
|
-
@host.log "App resource attribute, #{k}, set for: " +
|
34
|
-
monitor.class.name
|
37
|
+
conditionally_set_app_resource(monitor, k, v)
|
35
38
|
end
|
36
39
|
self
|
37
40
|
end
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
# rubocop:disable Metrics/MethodLength
|
43
|
+
def load_monitor(key, val)
|
44
|
+
name = key.sub('RSBOB_', '')
|
45
|
+
uri = URI.parse(val)
|
46
|
+
monitor = nil
|
47
|
+
case uri.scheme
|
48
|
+
when 'dir'
|
49
|
+
require 'rservicebus2/monitor/dir'
|
50
|
+
monitor = MonitorDir.new(@host, name, uri)
|
51
|
+
when 'awss3'
|
52
|
+
require 'rservicebus2/monitor/awss3'
|
53
|
+
monitor = MonitorAWSS3.new(@host, name, uri)
|
54
|
+
when 'awssqs'
|
55
|
+
require 'rservicebus2/monitor/awssqs'
|
56
|
+
monitor = MonitorAWSSQS.new(@host, name, uri)
|
57
|
+
when 'dirnotifier'
|
58
|
+
require 'rservicebus2/monitor/dirnotifier'
|
59
|
+
monitor = MonitorDirNotifier.new(@host, name, uri)
|
60
|
+
else
|
61
|
+
abort("Scheme, #{uri.scheme}, not recognised when configuring
|
62
|
+
Monitor, #{key}=#{val}")
|
63
|
+
end
|
64
|
+
monitor
|
65
|
+
end
|
66
|
+
# rubocop:enable Metrics/MethodLength
|
67
|
+
|
68
|
+
def monitors(env)
|
69
|
+
list = []
|
41
70
|
|
42
71
|
env.each do |k, v|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
when 'dir'
|
49
|
-
require 'rservicebus2/monitor/dir'
|
50
|
-
monitor = MonitorDir.new(@host, name, uri)
|
51
|
-
when 'awss3'
|
52
|
-
require 'rservicebus2/monitor/awss3'
|
53
|
-
monitor = MonitorAWSS3.new(@host, name, uri)
|
54
|
-
when 'awssqs'
|
55
|
-
require 'rservicebus2/monitor/awssqs'
|
56
|
-
monitor = MonitorAWSSQS.new(@host, name, uri)
|
57
|
-
when 'dirnotifier'
|
58
|
-
require 'rservicebus2/monitor/dirnotifier'
|
59
|
-
monitor = MonitorDirNotifier.new(@host, name, uri)
|
60
|
-
else
|
61
|
-
abort("Scheme, #{uri.scheme}, not recognised when configuring
|
62
|
-
Monitor, #{k}=#{v}")
|
63
|
-
end
|
64
|
-
set_app_resources(monitor)
|
65
|
-
monitors << monitor
|
66
|
-
end
|
72
|
+
next unless v.is_a?(String) && k.start_with?('RSBOB_')
|
73
|
+
|
74
|
+
monitor = load_monitor(k, v)
|
75
|
+
conditionally_set_app_resources(monitor)
|
76
|
+
list << monitor
|
67
77
|
end
|
68
|
-
|
78
|
+
list
|
69
79
|
end
|
70
80
|
end
|
71
81
|
end
|
data/lib/rservicebus2/mq.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module RServiceBus2
|
@@ -10,6 +12,7 @@ module RServiceBus2
|
|
10
12
|
class MQ
|
11
13
|
attr_reader :local_queue_name
|
12
14
|
|
15
|
+
# rubocop:disable Metrics/MethodLength
|
13
16
|
def self.get
|
14
17
|
mq_string = RServiceBus2.get_value('RSBMQ', 'beanstalk://localhost')
|
15
18
|
uri = URI.parse(mq_string)
|
@@ -34,31 +37,26 @@ module RServiceBus2
|
|
34
37
|
|
35
38
|
mq
|
36
39
|
end
|
40
|
+
# rubocop:enable Metrics/MethodLength
|
37
41
|
|
38
42
|
# Resources are attached, and are be specified using the URI syntax
|
39
43
|
# @param [URI] uri the type and location of queue,
|
40
44
|
# eg beanstalk://127.0.0.1/foo
|
41
45
|
# @param [Integer] timeout the amount of time to wait for a msg to arrive
|
46
|
+
|
47
|
+
# rubocop:disable Metrics/MethodLength
|
42
48
|
def initialize(uri)
|
43
|
-
|
44
|
-
@uri = uri
|
45
|
-
else
|
46
|
-
puts 'uri must be a valid URI'
|
47
|
-
abort
|
48
|
-
end
|
49
|
+
abort 'Paramter to mq must be a valid URI' unless uri.is_a? URI
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@local_queue_name[0] = ''
|
55
|
-
end
|
51
|
+
@uri = uri
|
52
|
+
@local_queue_name = uri.path
|
53
|
+
@local_queue_name[0] = '' if @local_queue_name[0] == '/'
|
54
|
+
@local_queue_name = RServiceBus2.get_value('APPNAME', 'RServiceBus') if @local_queue_name == ''
|
56
55
|
|
57
56
|
if @local_queue_name == ''
|
58
|
-
puts
|
59
|
-
|
60
|
-
|
61
|
-
puts '*** the structure is scheme://host[:port]/queuename'
|
57
|
+
puts 'Queue name must be supplied ' \
|
58
|
+
"*** uri, #{uri}, needs to contain a queue name" \
|
59
|
+
'*** the structure is scheme://host[:port]/queuename'
|
62
60
|
abort
|
63
61
|
end
|
64
62
|
|
@@ -66,42 +64,41 @@ module RServiceBus2
|
|
66
64
|
connect(uri.host, uri.port)
|
67
65
|
subscribe(@local_queue_name)
|
68
66
|
end
|
67
|
+
# rubocop:enable Metrics/MethodLength
|
69
68
|
|
70
69
|
# Connect to the broker
|
71
70
|
# @param [String] host machine runnig the mq
|
72
71
|
# @param [String] port port the mq is running on
|
73
72
|
def connect(_host, _port)
|
74
|
-
|
73
|
+
raise 'Method, connect, needs to be implemented'
|
75
74
|
end
|
76
75
|
|
77
76
|
# Connect to the receiving queue
|
78
77
|
# @param [String] queuename name of the receiving queue
|
79
78
|
def subscribe(_queuename)
|
80
|
-
|
79
|
+
raise 'Method, subscribe, needs to be implemented'
|
81
80
|
end
|
82
81
|
|
83
82
|
# Get next msg from queue
|
84
83
|
def pop
|
85
|
-
|
84
|
+
raise 'Method, pop, needs to be implemented'
|
86
85
|
end
|
87
86
|
|
88
87
|
# "Commit" the pop
|
89
88
|
def ack
|
90
|
-
|
89
|
+
raise 'Method, ack, needs to be implemented'
|
91
90
|
end
|
92
91
|
|
93
92
|
# At least called in the Host rescue block, to ensure all network links are
|
94
93
|
# healthy
|
95
94
|
# @param [String] queue_name name of the queue to which the msg should be sent
|
96
95
|
# @param [String] msg msg to be sent
|
97
|
-
def send(
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
96
|
+
def send(_queue_name, _msg)
|
97
|
+
@connection.close
|
98
|
+
rescue StandardError => e
|
99
|
+
puts "AppResource. An error was raised while closing connection to, #{@uri}"
|
100
|
+
puts "Error: #{e.message}"
|
101
|
+
puts "Backtrace: #{e.backtrace}"
|
102
|
+
end
|
103
|
+
end
|
107
104
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Given a directory, this class is responsible loading Sagas
|
3
5
|
class SagaLoader
|
@@ -17,11 +19,11 @@ module RServiceBus2
|
|
17
19
|
# require statement.
|
18
20
|
# @param [String] file_path the path to be cleaned
|
19
21
|
def get_require_path(file_path)
|
20
|
-
file_path =
|
22
|
+
file_path = "./#{file_path}" unless file_path.start_with?('/')
|
21
23
|
|
22
24
|
return file_path.sub('.rb', '') if File.exist?(file_path)
|
23
25
|
|
24
|
-
abort(
|
26
|
+
abort("Filepath, #{file_path}, given for Saga require doesn't exist")
|
25
27
|
end
|
26
28
|
|
27
29
|
# Instantiate the saga named in sagaName from the file name in file_path
|
@@ -32,6 +34,8 @@ module RServiceBus2
|
|
32
34
|
# @param [String] sagaName name of the saga to instantiate
|
33
35
|
# @param [String] file_path the path to the file to be loaded
|
34
36
|
# @return [RServiceBus2::Saga] the loader
|
37
|
+
|
38
|
+
# rubocop:disable Metrics/MethodLength
|
35
39
|
def load_saga_from_file(saga_name, file_path)
|
36
40
|
require_path = get_require_path(file_path)
|
37
41
|
|
@@ -39,52 +43,51 @@ module RServiceBus2
|
|
39
43
|
begin
|
40
44
|
saga = Object.const_get(saga_name)
|
41
45
|
rescue StandardError => e
|
42
|
-
puts
|
43
|
-
|
44
|
-
|
45
|
-
saga_name
|
46
|
-
puts '( In case its not that )'
|
46
|
+
puts "Expected class name: #{saga_name}, not found after require: #{require_path}" \
|
47
|
+
"**** Check in #{file_path} that the class is named: #{saga_name}" \
|
48
|
+
'( In case its not that )'
|
47
49
|
raise e
|
48
50
|
end
|
49
51
|
saga
|
50
52
|
end
|
53
|
+
# rubocop:enable Metrics/MethodLength
|
51
54
|
|
52
55
|
# Wrapper function
|
53
56
|
# @param [String] file_path
|
54
57
|
# @param [String] sagaName
|
55
58
|
# @returns [RServiceBus2::Saga] saga
|
59
|
+
|
60
|
+
# rubocop:disable Metrics/MethodLength
|
56
61
|
def load_saga(file_path, saga_name)
|
57
62
|
if @list_of_loaded_paths.key?(file_path)
|
58
63
|
RServiceBus2.log "Not reloading, #{file_path}"
|
59
64
|
return
|
60
65
|
end
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
RServiceBus2.rlog 'saga_name: ' + saga_name
|
67
|
+
RServiceBus2.rlog "file_path: #{file_path}"
|
68
|
+
RServiceBus2.rlog "saga_name: #{saga_name}"
|
65
69
|
|
66
|
-
|
67
|
-
|
70
|
+
saga = load_saga_from_file(saga_name, file_path)
|
71
|
+
RServiceBus2.log "Loaded Saga: #{saga_name}"
|
68
72
|
|
69
|
-
|
73
|
+
@saga_manager.register_saga(saga)
|
70
74
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
75
|
+
@list_of_loaded_paths[file_path] = 1
|
76
|
+
rescue StandardError => e
|
77
|
+
puts "Exception loading saga from file: #{file_path}"
|
78
|
+
puts e.message
|
79
|
+
puts e.backtrace[0]
|
80
|
+
abort
|
78
81
|
end
|
82
|
+
# rubocop:enable Metrics/MethodLength
|
79
83
|
|
80
84
|
# This method is overloaded for unit tests
|
81
85
|
# @param [String] path directory to check
|
82
86
|
# @return [Array] a list of paths to files found in the given path
|
83
87
|
def get_list_of_files_for_dir(path)
|
84
|
-
list = Dir[path
|
88
|
+
list = Dir["#{path}/*"]
|
85
89
|
|
86
|
-
RServiceBus2.rlog "SagaLoader.getListOfFilesForDir. path: #{path},
|
87
|
-
list: #{list}"
|
90
|
+
RServiceBus2.rlog "SagaLoader.getListOfFilesForDir. path: #{path}, list: #{list}"
|
88
91
|
|
89
92
|
list
|
90
93
|
end
|
@@ -97,7 +100,7 @@ module RServiceBus2
|
|
97
100
|
|
98
101
|
saga_name = base_name.sub(ext_name, '')
|
99
102
|
|
100
|
-
"saga_#{saga_name}".gsub(/(?<=_|^)(\w)/){
|
103
|
+
"saga_#{saga_name}".gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
|
101
104
|
end
|
102
105
|
|
103
106
|
# Entry point for loading Sagas
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Saga Storage
|
3
5
|
class SagaStorage
|
@@ -5,13 +7,12 @@ module RServiceBus2
|
|
5
7
|
case uri.scheme
|
6
8
|
when 'dir'
|
7
9
|
require 'rservicebus2/saga_storage/dir'
|
8
|
-
|
10
|
+
SagaStorageDir.new(uri)
|
9
11
|
when 'inmem'
|
10
12
|
require 'rservicebus2/saga_storage/inmemory'
|
11
|
-
|
13
|
+
SagaStorageInMemory.new(uri)
|
12
14
|
else
|
13
|
-
abort("Scheme, #{uri.scheme}, not recognised when configuring
|
14
|
-
SagaStorage, #{uri}")
|
15
|
+
abort("Scheme, #{uri.scheme}, not recognised when configuring SagaStorage, #{uri}")
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|