rservicebus2 0.2.4 → 0.2.9
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/agent.rb +5 -2
- data/lib/rservicebus2/appresource.rb +8 -9
- data/lib/rservicebus2/appresource/awsdynamodb.rb +4 -6
- data/lib/rservicebus2/appresource/awss3.rb +16 -0
- data/lib/rservicebus2/appresource/awssqs.rb +25 -0
- data/lib/rservicebus2/appresource_configure.rb +14 -4
- data/lib/rservicebus2/audit.rb +4 -2
- data/lib/rservicebus2/circuitbreaker.rb +4 -2
- data/lib/rservicebus2/config.rb +10 -10
- data/lib/rservicebus2/cron_manager.rb +6 -1
- data/lib/rservicebus2/endpointmapping.rb +22 -14
- data/lib/rservicebus2/errormessage.rb +2 -1
- data/lib/rservicebus2/handler_loader.rb +35 -28
- data/lib/rservicebus2/handler_manager.rb +30 -24
- data/lib/rservicebus2/helper_functions.rb +7 -3
- data/lib/rservicebus2/host.rb +59 -120
- data/lib/rservicebus2/monitor/awss3.rb +51 -0
- data/lib/rservicebus2/monitor/awssqs.rb +32 -0
- data/lib/rservicebus2/monitor_configure.rb +8 -2
- data/lib/rservicebus2/resource_manager.rb +14 -19
- data/lib/rservicebus2/saga/manager.rb +2 -2
- metadata +21 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cf46f6455ed14f25642855bd4839b0c910447bb07007bdb2dba0c9a65b7f4d0
|
4
|
+
data.tar.gz: 5ef71ec901e2d142d731d2dd8be176b297116ef8b6b07ab182c295496f1dfd85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35999f1a63cf911f2dc2d2d9580dc3afd26f70203db43bf7c58ee079606bb318246e292ffd382ceadfe4747d37a826a0784b3407d611c1957d61b7ea266aef05
|
7
|
+
data.tar.gz: c19a66ce0e83b4c2ae617ed0e8b9827f91cf31c9820e7f0e8ba5f405f83792b097e5ed0bd9769faf331bd15c4bdfeaf9748cea40677c29e050f4f3d1d6e58815
|
data/lib/rservicebus2/agent.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
class QueueNotFoundForMsg < StandardError
|
3
5
|
end
|
@@ -22,9 +24,9 @@ module RServiceBus2
|
|
22
24
|
# @param [Object] messageObj The msg to be sent
|
23
25
|
# @param [String] queueName the name of the queue to be send the msg to
|
24
26
|
# @param [String] returnAddress the name of a queue to send replies to
|
25
|
-
# rubocop:disable Metrics/
|
27
|
+
# rubocop:disable Metrics/MethodLength
|
26
28
|
def send_msg(message_obj, queue_name, return_address = nil)
|
27
|
-
|
29
|
+
raise QueueNotFoundForMsg, message_obj.class.name if queue_name.nil?
|
28
30
|
|
29
31
|
msg = RServiceBus2::Message.new(message_obj, return_address)
|
30
32
|
if queue_name.index('@').nil?
|
@@ -40,6 +42,7 @@ module RServiceBus2
|
|
40
42
|
|
41
43
|
@mq.send(q, serialized_object)
|
42
44
|
end
|
45
|
+
# rubocop:enable Metrics/MethodLength
|
43
46
|
|
44
47
|
# Gives an agent the means to receive a reply
|
45
48
|
#
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module RServiceBus2
|
@@ -8,7 +10,7 @@ module RServiceBus2
|
|
8
10
|
|
9
11
|
# The method which actually connects to the resource.
|
10
12
|
def connect(_uri)
|
11
|
-
|
13
|
+
raise 'Method, connect, needs to be implemented for resource'
|
12
14
|
end
|
13
15
|
|
14
16
|
def _connect
|
@@ -16,7 +18,7 @@ module RServiceBus2
|
|
16
18
|
RServiceBus2.rlog "#{self.class.name}. Connected to, #{@uri}"
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
21
|
+
def resource
|
20
22
|
@connection
|
21
23
|
end
|
22
24
|
|
@@ -44,22 +46,19 @@ module RServiceBus2
|
|
44
46
|
rescue StandardError => e
|
45
47
|
puts '** AppResource. An error was raised while closing connection
|
46
48
|
to, ' + @uri
|
47
|
-
puts
|
49
|
+
puts "Message: #{e.message}"
|
48
50
|
puts e.backtrace
|
49
51
|
end
|
50
52
|
_connect
|
51
53
|
end
|
52
54
|
|
53
55
|
# Transaction Semantics
|
54
|
-
def begin
|
55
|
-
end
|
56
|
+
def begin; end
|
56
57
|
|
57
58
|
# Transaction Semantics
|
58
|
-
def commit
|
59
|
-
end
|
59
|
+
def commit; end
|
60
60
|
|
61
61
|
# Transaction Semantics
|
62
|
-
def rollback
|
63
|
-
end
|
62
|
+
def rollback; end
|
64
63
|
end
|
65
64
|
end
|
@@ -1,18 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'aws-sdk-dynamodb'
|
2
4
|
|
3
5
|
module RServiceBus2
|
4
6
|
# AppResourceAWSDynamoDb
|
5
7
|
class AppResourceAWSDynamoDb < AppResource
|
6
|
-
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
7
8
|
def connect(uri)
|
8
9
|
region = uri.host
|
9
10
|
|
10
|
-
|
11
|
-
puts "aws #{aws}"
|
12
|
-
aws
|
11
|
+
Aws::DynamoDB::Client.new(region: region)
|
13
12
|
end
|
14
13
|
|
15
|
-
def finished
|
16
|
-
end
|
14
|
+
def finished; end
|
17
15
|
end
|
18
16
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'aws-sdk-s3'
|
2
|
+
|
3
|
+
module RServiceBus2
|
4
|
+
# AppResourceAWSDynamoDb
|
5
|
+
class AppResourceAWSS3 < AppResource
|
6
|
+
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
7
|
+
def connect(uri)
|
8
|
+
region = uri.host
|
9
|
+
|
10
|
+
Aws::S3::Client.new(region: region)
|
11
|
+
end
|
12
|
+
|
13
|
+
def finished
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'aws-sdk-sqs'
|
2
|
+
require 'aws-sdk-sts'
|
3
|
+
|
4
|
+
module RServiceBus2
|
5
|
+
# AppResourceAWSDynamoDb
|
6
|
+
class AppResourceAWSSQS < AppResource
|
7
|
+
def connect(uri)
|
8
|
+
queue_name = uri.path.sub('/', '')
|
9
|
+
|
10
|
+
region = uri.host
|
11
|
+
|
12
|
+
sts_client = Aws::STS::Client.new(region: region)
|
13
|
+
caller_identity_account = sts_client.get_caller_identity.account
|
14
|
+
|
15
|
+
queue_url = "https://sqs.#{region}.amazonaws.com/" \
|
16
|
+
"#{caller_identity_account}/#{queue_name}"
|
17
|
+
{
|
18
|
+
client: Aws::SQS::Client.new(region: region),
|
19
|
+
url: queue_url
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def finished; end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module RServiceBus2
|
4
6
|
# Configure AppResources for an rservicebus host
|
5
7
|
class ConfigureAppResource
|
6
|
-
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength,CyclomaticComplexity
|
8
|
+
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
7
9
|
def get_resources(env, host, state_manager, saga_storage)
|
8
|
-
# rm = resource_manager
|
9
10
|
rm = ResourceManager.new(state_manager, saga_storage)
|
11
|
+
# rubocop:disable Metrics/BlockLength
|
10
12
|
env.each do |k, v|
|
11
13
|
if v.is_a?(String) && k.start_with?('RSBFDB2_')
|
12
14
|
uri = URI.parse(v)
|
@@ -15,8 +17,8 @@ module RServiceBus2
|
|
15
17
|
k = k.sub('RSBFDB2_', '')
|
16
18
|
rm.add k, AppResourceFluidDb2.new(host, uri)
|
17
19
|
elsif v.is_a?(String) &&
|
18
|
-
(k.start_with?('RSBFDB_') || v.
|
19
|
-
v = v['fluiddb'.length..-1] if v.
|
20
|
+
(k.start_with?('RSBFDB_') || v.start_with?('fluiddb'))
|
21
|
+
v = v['fluiddb'.length..-1] if v.start_with?('fluiddb')
|
20
22
|
uri = URI.parse(v)
|
21
23
|
require 'rservicebus2/appresource/fluiddb'
|
22
24
|
|
@@ -34,14 +36,22 @@ module RServiceBus2
|
|
34
36
|
when 'awsdynamodb'
|
35
37
|
require 'rservicebus2/appresource/awsdynamodb'
|
36
38
|
rm.add k.sub('RSB_', ''), AppResourceAWSDynamoDb.new(host, uri)
|
39
|
+
when 'awss3'
|
40
|
+
require 'rservicebus2/appresource/awss3'
|
41
|
+
rm.add k.sub('RSB_', ''), AppResourceAWSS3.new(host, uri)
|
42
|
+
when 'awssqs'
|
43
|
+
require 'rservicebus2/appresource/awssqs'
|
44
|
+
rm.add k.sub('RSB_', ''), AppResourceAWSSQS.new(host, uri)
|
37
45
|
else
|
38
46
|
abort("Scheme, #{uri.scheme}, not recognised when configuring
|
39
47
|
app resource, #{k}=#{v}")
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
51
|
+
# rubocop:enable Metrics/BlockLength
|
43
52
|
|
44
53
|
rm
|
45
54
|
end
|
55
|
+
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
46
56
|
end
|
47
57
|
end
|
data/lib/rservicebus2/audit.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Audit Class
|
3
5
|
class Audit
|
4
|
-
def initialize(
|
5
|
-
@mq =
|
6
|
+
def initialize(message_queue)
|
7
|
+
@mq = message_queue
|
6
8
|
audit_queue_name = RServiceBus2.get_value('AUDIT_QUEUE_NAME')
|
7
9
|
if audit_queue_name.nil?
|
8
10
|
@sent_messages_to = RServiceBus2.get_value('sent_messages_to')
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
class MessageArrivedWhileCricuitBroken < StandardError
|
3
5
|
end
|
@@ -42,7 +44,7 @@ module RServiceBus2
|
|
42
44
|
message_arrived
|
43
45
|
|
44
46
|
## logFirstFailure
|
45
|
-
if @number_of_failures
|
47
|
+
if @number_of_failures.zero?
|
46
48
|
@number_of_failures = 1
|
47
49
|
@time_of_first_failure = Time.now
|
48
50
|
@time_to_break = @time_of_first_failure + @seconds_to_break
|
@@ -68,7 +70,7 @@ module RServiceBus2
|
|
68
70
|
def message_arrived
|
69
71
|
reset if !@time_to_break.nil? && Time.now > @time_to_break
|
70
72
|
|
71
|
-
|
73
|
+
raise MessageArrivedWhileCricuitBroken if @broken == true
|
72
74
|
end
|
73
75
|
|
74
76
|
def break_circuit
|
data/lib/rservicebus2/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Marshals configuration information for an rservicebus host
|
3
5
|
class Config
|
@@ -19,7 +21,7 @@ module RServiceBus2
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def get_value(name, default = nil)
|
22
|
-
value =
|
24
|
+
value = ENV[name].nil? || ENV[name] == '' ? default : ENV[name]
|
23
25
|
log "Env value: #{name}: #{value}"
|
24
26
|
value
|
25
27
|
end
|
@@ -131,21 +133,19 @@ module RServiceBus2
|
|
131
133
|
# Note. trailing slashs will be stripped
|
132
134
|
# Expected format: <path 1>;<path 2>
|
133
135
|
def load_working_dir_list
|
134
|
-
puts "Config.load_working_dir_list.1"
|
135
|
-
puts "Config.load_working_dir_list.2 #{@contract_list}"
|
136
136
|
path_list = get_value('WORKING_DIR', './')
|
137
137
|
return self if path_list.nil?
|
138
138
|
|
139
139
|
path_list.split(';').each do |path|
|
140
140
|
path = path.strip.chomp('/')
|
141
|
-
unless Dir.exist?(
|
141
|
+
unless Dir.exist?(path.to_s)
|
142
142
|
puts 'Error while processing working directory list'
|
143
143
|
puts "*** path, #{path}, does not exist"
|
144
144
|
abort
|
145
145
|
end
|
146
146
|
@handler_path_list << "#{path}/messagehandler" if Dir.exist?("#{path}/messagehandler")
|
147
147
|
@saga_path_list << "#{path}/saga" if Dir.exist?("#{path}/saga")
|
148
|
-
@contract_list << "#{path}/contract.rb" if File.exist?(
|
148
|
+
@contract_list << "#{path}/contract.rb" if File.exist?("#{path}/contract.rb")
|
149
149
|
@lib_list << "#{path}/lib" if File.exist?("#{path}/lib")
|
150
150
|
end
|
151
151
|
self
|
@@ -154,14 +154,14 @@ module RServiceBus2
|
|
154
154
|
|
155
155
|
# Class
|
156
156
|
class ConfigFromEnv < Config
|
157
|
-
def initialize
|
158
|
-
end
|
157
|
+
def initialize; end;
|
159
158
|
end
|
160
159
|
|
161
160
|
# Class
|
162
161
|
class ConfigFromSetter < Config
|
163
|
-
attr_writer :
|
164
|
-
|
165
|
-
|
162
|
+
attr_writer :app_name, :message_endpoint_mappings, :handler_path_list, :error_queue_name, \
|
163
|
+
:max_retries, :forward_received_messages_to, :beanstalk_host
|
164
|
+
|
165
|
+
def initialize; end;
|
166
166
|
end
|
167
167
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'parse-cron'
|
2
4
|
|
3
5
|
module RServiceBus2
|
@@ -27,7 +29,8 @@ module RServiceBus2
|
|
27
29
|
@msg_names.each do |n|
|
28
30
|
list << n if Globber.new(name) =~ n
|
29
31
|
end
|
30
|
-
|
32
|
+
raise NoMatchingMsgForCron, name if list.empty?
|
33
|
+
|
31
34
|
list
|
32
35
|
end
|
33
36
|
|
@@ -44,6 +47,7 @@ module RServiceBus2
|
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
50
|
+
# rubocop:disable Metrics/MethodLength
|
47
51
|
def initialize(host, msg_names = [])
|
48
52
|
@bus = host
|
49
53
|
@msg_names = msg_names
|
@@ -61,6 +65,7 @@ module RServiceBus2
|
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
68
|
+
# rubocop:enable Metrics/MethodLength
|
64
69
|
|
65
70
|
def run
|
66
71
|
now = Time.now
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Marshals data for message end points
|
3
5
|
# Expected format: <msg mame 1>:<end point 1>;<msg mame 2>:<end point 2>
|
@@ -6,16 +8,18 @@ module RServiceBus2
|
|
6
8
|
RServiceBus2.get_value(name)
|
7
9
|
end
|
8
10
|
|
9
|
-
def log(string, _ver
|
11
|
+
def log(string, _ver: false)
|
10
12
|
RServiceBus2.log(string)
|
11
13
|
end
|
12
14
|
|
15
|
+
# rubocop:disable Metrics/AbcSize
|
16
|
+
# rubocop:disable Metrics/MethodLength
|
13
17
|
def configure_mapping(mapping)
|
14
18
|
match = mapping.match(/(.+):(.+)/)
|
15
19
|
if match.nil?
|
16
|
-
log 'Mapping string provided is invalid'
|
17
|
-
|
18
|
-
|
20
|
+
log 'Mapping string provided is invalid\n' \
|
21
|
+
"The entire mapping string is: #{mapping}\n" \
|
22
|
+
"*** Could not find ':' in mapping entry, #{line}\n"
|
19
23
|
exit
|
20
24
|
end
|
21
25
|
|
@@ -23,16 +27,19 @@ module RServiceBus2
|
|
23
27
|
@endpoints[match[1]] = match[2]
|
24
28
|
|
25
29
|
@queue_name_list.each do |q|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
next unless q != match[2] && q.downcase == match[2].downcase
|
31
|
+
|
32
|
+
log('*** Two queues specified with only case sensitive difference.')
|
33
|
+
log("*** #{q} != #{match[2]}")
|
34
|
+
log('*** If you meant these queues to be the same, please match case
|
35
|
+
and restart the bus.')
|
32
36
|
end
|
33
37
|
@queue_name_list << match[2]
|
34
38
|
end
|
39
|
+
# rubocop:enable Metrics/AbcSize
|
40
|
+
# rubocop:enable Metrics/MethodLength
|
35
41
|
|
42
|
+
# rubocop:disable Metrics/MethodLength
|
36
43
|
def configure(local_queue_name = nil)
|
37
44
|
log('EndpointMapping.Configure')
|
38
45
|
|
@@ -40,9 +47,9 @@ module RServiceBus2
|
|
40
47
|
@queue_name_list << local_queue_name unless local_queue_name.nil?
|
41
48
|
|
42
49
|
unless get_value('MESSAGE_ENDPOINT_MAPPING').nil?
|
43
|
-
log
|
44
|
-
|
45
|
-
on the end"
|
50
|
+
log '*** MESSAGE_ENDPOINT_MAPPING environment variable was detected\n' \
|
51
|
+
"*** You may have intended MESSAGE_ENDPOINT_MAPPINGS, note the 'S'
|
52
|
+
on the end"
|
46
53
|
end
|
47
54
|
|
48
55
|
mappings = get_value('MESSAGE_ENDPOINT_MAPPINGS')
|
@@ -54,6 +61,7 @@ module RServiceBus2
|
|
54
61
|
|
55
62
|
self
|
56
63
|
end
|
64
|
+
# rubocop:enable Metrics/MethodLength
|
57
65
|
|
58
66
|
def initialize
|
59
67
|
@endpoints = {}
|
@@ -65,7 +73,7 @@ module RServiceBus2
|
|
65
73
|
nil
|
66
74
|
end
|
67
75
|
|
68
|
-
def
|
76
|
+
def subscription_endpoints
|
69
77
|
@endpoints.keys.select { |el| el.end_with?('Event') }
|
70
78
|
end
|
71
79
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Given a directory, this class is responsible for finding
|
3
5
|
# msgnames,
|
4
6
|
# handlernames, and
|
5
7
|
# loading handlers
|
6
8
|
class HandlerLoader
|
7
|
-
attr_reader :handlerList
|
9
|
+
# attr_reader :handlerList - 8 May 2021
|
8
10
|
|
9
11
|
# Constructor
|
10
12
|
#
|
@@ -22,12 +24,11 @@ module RServiceBus2
|
|
22
24
|
# Cleans the given path to ensure it can be used for as a parameter for the require statement.
|
23
25
|
# @param [String] file_path the path to be cleaned
|
24
26
|
def get_require_path(file_path)
|
25
|
-
file_path =
|
27
|
+
file_path = "./#{file_path}" unless file_path.start_with?('/')
|
26
28
|
|
27
29
|
return file_path.sub('.rb', '') if File.exist?(file_path)
|
28
30
|
|
29
|
-
abort(
|
30
|
-
doesn't exist")
|
31
|
+
abort("Filepath, #{file_path}, given for messagehandler require doesn't exist")
|
31
32
|
end
|
32
33
|
|
33
34
|
# Instantiate the handler named in handlerName from the file name in
|
@@ -38,6 +39,7 @@ module RServiceBus2
|
|
38
39
|
# @param [String] handler_name name of the handler to instantiate
|
39
40
|
# @param [String] file_path the path to the file to be loaded
|
40
41
|
# @return [RServiceBus2::Handler] the loader
|
42
|
+
# rubocop:disable Metrics/MethodLength
|
41
43
|
def load_handler_from_file(handler_name, file_path)
|
42
44
|
require_path = get_require_path(file_path)
|
43
45
|
|
@@ -45,22 +47,22 @@ module RServiceBus2
|
|
45
47
|
begin
|
46
48
|
handler = Object.const_get(handler_name).new
|
47
49
|
rescue StandardError => e
|
48
|
-
puts
|
49
|
-
|
50
|
-
|
51
|
-
handler_name
|
52
|
-
puts '( In case its not that )'
|
50
|
+
puts "Expected class name: #{handler_name}, not found after require: #{require_path}\n" \
|
51
|
+
"**** Check in #{file_path} that the class is named: #{handler_name}\n" \
|
52
|
+
'( In case its not that )'
|
53
53
|
raise e
|
54
54
|
end
|
55
55
|
|
56
56
|
handler
|
57
57
|
end
|
58
|
+
# rubocop:enable Metrics/MethodLength
|
58
59
|
|
59
60
|
# Wrapper function
|
60
61
|
#
|
61
62
|
# @param [String] file_path
|
62
63
|
# @param [String] handler_name
|
63
64
|
# @returns [RServiceBus2::Handler] handler
|
65
|
+
# rubocop:disable Metrics/MethodLength
|
64
66
|
def load_handler(msg_name, file_path, handler_name)
|
65
67
|
if @list_of_loaded_paths.key?(file_path)
|
66
68
|
RServiceBus2.log "Not reloading, #{file_path}"
|
@@ -68,29 +70,30 @@ module RServiceBus2
|
|
68
70
|
end
|
69
71
|
|
70
72
|
begin
|
71
|
-
RServiceBus2.rlog
|
72
|
-
RServiceBus2.rlog
|
73
|
+
RServiceBus2.rlog "file_path: #{file_path}"
|
74
|
+
RServiceBus2.rlog "handler_name: #{handler_name}"
|
73
75
|
|
74
76
|
handler = load_handler_from_file(handler_name, file_path)
|
75
|
-
RServiceBus2.log
|
77
|
+
RServiceBus2.log "Loaded Handler: #{handler_name}"
|
76
78
|
|
77
79
|
@handler_manager.add_handler(msg_name, handler)
|
78
80
|
|
79
81
|
@list_of_loaded_paths[file_path] = 1
|
80
82
|
rescue StandardError => e
|
81
|
-
puts
|
83
|
+
puts "Exception loading handler from file: #{file_path}"
|
82
84
|
puts e.message
|
83
85
|
puts e.backtrace[0]
|
84
86
|
abort
|
85
87
|
end
|
86
88
|
end
|
89
|
+
# rubocop:enable Metrics/MethodLength
|
87
90
|
|
88
91
|
# This method is overloaded for unit tests
|
89
92
|
#
|
90
93
|
# @param [String] path directory to check
|
91
94
|
# @return [Array] a list of paths to files found in the given path
|
92
95
|
def get_list_of_files_for_dir(path)
|
93
|
-
list = Dir[path
|
96
|
+
list = Dir["#{path}/*"]
|
94
97
|
RServiceBus2.rlog "HandlerLoader.getListOfFilesForDir. path: #{path},
|
95
98
|
list: #{list}"
|
96
99
|
list
|
@@ -105,14 +108,14 @@ module RServiceBus2
|
|
105
108
|
def load_handlers_from_second_level_path(msg_name, base_dir)
|
106
109
|
get_list_of_files_for_dir(base_dir).each do |file_path|
|
107
110
|
next if file_path.end_with?('.')
|
111
|
+
next unless !File.directory?(file_path) && File.extname(file_path) == '.rb'
|
108
112
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
+
file_name = File.basename(file_path).sub('.rb', '')
|
114
|
+
# Classify
|
115
|
+
handler_name = "message_handler_#{msg_name}_#{file_name}"
|
116
|
+
.gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
|
113
117
|
|
114
|
-
|
115
|
-
end
|
118
|
+
load_handler(msg_name, file_path, handler_name)
|
116
119
|
end
|
117
120
|
|
118
121
|
self
|
@@ -130,22 +133,26 @@ module RServiceBus2
|
|
130
133
|
# Load top level handlers from the given directory
|
131
134
|
#
|
132
135
|
# @param [String] baseDir directory to check - should not have trailing slash
|
136
|
+
# rubocop:disable Metrics/MethodLength
|
133
137
|
def load_handlers_from_top_level_path(base_dir)
|
134
138
|
RServiceBus2.rlog "HandlerLoader.loadHandlersFromTopLevelPath. baseDir: #{base_dir}"
|
135
139
|
get_list_of_files_for_dir(base_dir).each do |file_path|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
140
|
+
next if file_path.end_with?('.')
|
141
|
+
|
142
|
+
msg_name = get_msg_name(file_path)
|
143
|
+
if File.directory?(file_path)
|
144
|
+
load_handlers_from_second_level_path(msg_name, file_path)
|
145
|
+
else
|
146
|
+
# Classify
|
147
|
+
handler_name = "message_handler_#{msg_name}"
|
148
|
+
.gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
|
149
|
+
load_handler(msg_name, file_path, handler_name)
|
144
150
|
end
|
145
151
|
end
|
146
152
|
|
147
153
|
self
|
148
154
|
end
|
155
|
+
# rubocop:enable Metrics/MethodLength
|
149
156
|
|
150
157
|
# Entry point for loading handlers
|
151
158
|
#
|