rservicebus2 0.2.8 → 0.2.13
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 -5
- data/lib/rservicebus2/agent.rb +7 -4
- data/lib/rservicebus2/appresource.rb +1 -1
- 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/appresource_configure.rb +8 -4
- data/lib/rservicebus2/audit.rb +4 -2
- data/lib/rservicebus2/config.rb +39 -27
- data/lib/rservicebus2/endpointmapping.rb +2 -4
- data/lib/rservicebus2/errormessage.rb +1 -1
- data/lib/rservicebus2/handler_manager.rb +1 -1
- data/lib/rservicebus2/helper_functions.rb +19 -14
- data/lib/rservicebus2/host.rb +62 -123
- data/lib/rservicebus2/message.rb +11 -19
- 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 +25 -23
- data/lib/rservicebus2/monitor/dirnotifier.rb +4 -1
- 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/mq/beanstalk.rb +5 -1
- data/lib/rservicebus2/saga/data.rb +1 -1
- data/lib/rservicebus2/saga/manager.rb +1 -1
- data/lib/rservicebus2/saga_loader.rb +27 -24
- data/lib/rservicebus2/saga_storage.rb +5 -4
- data/lib/rservicebus2/sendat_manager.rb +5 -3
- data/lib/rservicebus2/sendat_storage.rb +5 -3
- data/lib/rservicebus2/sendat_storage/file.rb +6 -2
- data/lib/rservicebus2/sendat_storage/inmemory.rb +2 -0
- data/lib/rservicebus2/state_manager.rb +5 -4
- 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
@@ -76,7 +76,7 @@ module RServiceBus2
|
|
76
76
|
return if @resource_list_by_saga_name[saga.class.name].nil?
|
77
77
|
|
78
78
|
@resource_list_by_saga_name[saga.class.name].each do |k, v|
|
79
|
-
saga.instance_variable_set("@#{k}", @resource_manager.get(k).
|
79
|
+
saga.instance_variable_set("@#{k}", @resource_manager.get(k).resource)
|
80
80
|
RServiceBus2.rlog "App resource attribute, #{k}, set for: " + saga.class.name
|
81
81
|
end
|
82
82
|
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
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rservicebus2/sendat_storage'
|
2
4
|
|
3
5
|
module RServiceBus2
|
@@ -16,9 +18,9 @@ module RServiceBus2
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def process
|
19
|
-
now =
|
20
|
-
@sendat_storage.
|
21
|
-
next if row['timestamp']
|
21
|
+
now = Time.now
|
22
|
+
@sendat_storage.all.each_with_index do |row, idx|
|
23
|
+
next if now <= row['timestamp']
|
22
24
|
|
23
25
|
@bus._send_needs_wrapping(row['msg'], row['queue_name'],
|
24
26
|
row['correlation_id'])
|
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module RServiceBus2
|
3
4
|
# Send At Storage
|
4
5
|
class SendAtStorage
|
6
|
+
# rubocop:disable Metrics/MethodLength
|
5
7
|
def self.get(uri)
|
6
8
|
case uri.scheme
|
7
9
|
when 'file'
|
8
10
|
require 'rservicebus2/sendat_storage/file'
|
9
|
-
|
11
|
+
SendAtStorageFile.new(uri)
|
10
12
|
when 'inmem'
|
11
13
|
require 'rservicebus2/sendat_storage/inmemory'
|
12
|
-
|
14
|
+
SendAtStorageInMemory.new(uri)
|
13
15
|
else
|
14
16
|
abort("Scheme, #{uri.scheme}, not recognised when configuring
|
15
17
|
SendAtStorage, #{uri}")
|
16
18
|
end
|
17
19
|
end
|
18
|
-
|
20
|
+
# rubocop:enable Metrics/MethodLength
|
19
21
|
end
|
20
22
|
end
|
@@ -1,8 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Send at storage file
|
3
5
|
class SendAtStorageFile
|
4
6
|
def initialize(uri)
|
7
|
+
RServiceBus2.log "SendAtStorageFile configured: #{uri.path}"
|
5
8
|
@list = load(uri.path)
|
9
|
+
@path = uri.path
|
6
10
|
end
|
7
11
|
|
8
12
|
def load(path)
|
@@ -20,7 +24,7 @@ module RServiceBus2
|
|
20
24
|
save
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
27
|
+
def all
|
24
28
|
@list
|
25
29
|
end
|
26
30
|
|
@@ -31,7 +35,7 @@ module RServiceBus2
|
|
31
35
|
|
32
36
|
def save
|
33
37
|
content = YAML.dump(@list)
|
34
|
-
File.open(@
|
38
|
+
File.open(@path, 'w') { |f| f.write(content) }
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rservicebus2/state_storage'
|
2
4
|
|
3
5
|
module RServiceBus2
|
4
|
-
|
5
6
|
# State Manager
|
6
7
|
class StateManager
|
7
8
|
def required
|
@@ -16,15 +17,15 @@ module RServiceBus2
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def begin
|
19
|
-
@state_storage
|
20
|
+
@state_storage&.begin
|
20
21
|
end
|
21
22
|
|
22
23
|
def get(handler)
|
23
|
-
@state_storage
|
24
|
+
@state_storage&.get(handler)
|
24
25
|
end
|
25
26
|
|
26
27
|
def commit
|
27
|
-
@state_storage
|
28
|
+
@state_storage&.commit
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
@@ -1,17 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# State Storage
|
3
5
|
class StateStorage
|
4
6
|
def self.get(uri)
|
5
7
|
case uri.scheme
|
6
8
|
when 'dir'
|
7
|
-
require 'rservicebus2/state_storage/dir
|
8
|
-
|
9
|
+
require 'rservicebus2/state_storage/dir'
|
10
|
+
StateStorageDir.new(uri)
|
9
11
|
when 'inmem'
|
10
|
-
require 'rservicebus2/state_storage/inmemory
|
11
|
-
|
12
|
+
require 'rservicebus2/state_storage/inmemory'
|
13
|
+
StateStorageInMemory.new(uri)
|
12
14
|
else
|
13
|
-
abort("Scheme, #{uri.scheme}, not recognised when configuring
|
14
|
-
StateStorage, #{uri}")
|
15
|
+
abort("Scheme, #{uri.scheme}, not recognised when configuring StateStorage, #{uri}")
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Used to collect various run time stats for runtime reporting
|
3
5
|
class StatisticManager
|
4
6
|
attr_accessor :output
|
5
7
|
|
8
|
+
# rubocop:disable Metrics/MethodLength
|
6
9
|
def initialize(host)
|
7
10
|
@host = host
|
8
11
|
@hash = {}
|
@@ -20,6 +23,7 @@ module RServiceBus2
|
|
20
23
|
RServiceBus2.get_value('STAT_OUTPUT_COUNTDOWN', '1').to_i
|
21
24
|
@stat_output_countdown = 0
|
22
25
|
end
|
26
|
+
# rubocop:enable Metrics/MethodLength
|
23
27
|
|
24
28
|
def inc_total_processed
|
25
29
|
@total_processed += 1
|
@@ -51,7 +55,7 @@ module RServiceBus2
|
|
51
55
|
@total_by_message_type[class_name] += 1
|
52
56
|
end
|
53
57
|
|
54
|
-
def
|
58
|
+
def internal_formatted_reporting
|
55
59
|
return unless @written == false
|
56
60
|
|
57
61
|
@written = true
|
@@ -63,7 +67,7 @@ module RServiceBus2
|
|
63
67
|
types
|
64
68
|
end
|
65
69
|
|
66
|
-
def
|
70
|
+
def formatted_reporting
|
67
71
|
"T:#{@total_processed};" \
|
68
72
|
"E:#{@total_errored};" \
|
69
73
|
"S:#{@total_sent};" \
|
@@ -72,7 +76,7 @@ module RServiceBus2
|
|
72
76
|
end
|
73
77
|
|
74
78
|
def report
|
75
|
-
@host.log(
|
79
|
+
@host.log(formatted_reporting) if @output
|
76
80
|
end
|
77
81
|
|
78
82
|
def tick
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Subscription Manager
|
3
5
|
class SubscriptionManager
|
4
6
|
def initialize(subscription_storage)
|
5
7
|
@subscription_storage = subscription_storage
|
6
|
-
@subscriptions = @subscription_storage.
|
8
|
+
@subscriptions = @subscription_storage.all
|
7
9
|
end
|
8
10
|
|
9
11
|
# Get subscriptions for given eventName
|
@@ -11,7 +13,8 @@ module RServiceBus2
|
|
11
13
|
subscriptions = @subscriptions[event_name]
|
12
14
|
if subscriptions.nil?
|
13
15
|
RServiceBus2.log "No subscribers for event, #{event_name}"
|
14
|
-
RServiceBus2.log
|
16
|
+
RServiceBus2.log 'If there should be, ensure you have the appropriate evironment variable set, ' \
|
17
|
+
"eg MESSAGE_ENDPOINT_MAPPINGS=#{event_name}:<Queue Name>"
|
15
18
|
return []
|
16
19
|
end
|
17
20
|
|
@@ -19,13 +22,12 @@ module RServiceBus2
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def add(event_name, queue_name)
|
22
|
-
RServiceBus2.log
|
23
|
-
event_name + ', to, ' + queue_name
|
25
|
+
RServiceBus2.log "Adding subscription for, #{event_name}, to, #{queue_name}"
|
24
26
|
@subscriptions = @subscription_storage.add(event_name, queue_name)
|
25
27
|
end
|
26
28
|
|
27
29
|
def remove(_event_name, _queue_name)
|
28
|
-
|
30
|
+
raise 'Method, remove, needs to be implemented for this subscription storage'
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module RServiceBus2
|
@@ -14,8 +16,8 @@ module RServiceBus2
|
|
14
16
|
end
|
15
17
|
|
16
18
|
# Get a list of all subscription, as an Array
|
17
|
-
def
|
18
|
-
|
19
|
+
def all
|
20
|
+
raise 'Method, all, needs to be implemented for SubscriptionStorage'
|
19
21
|
end
|
20
22
|
|
21
23
|
# Add a new subscription
|
@@ -23,7 +25,7 @@ module RServiceBus2
|
|
23
25
|
# has asked for notification
|
24
26
|
# @param [String] queue_name the queue to which the event should be sent
|
25
27
|
def add(_event_name, _queue_name)
|
26
|
-
|
28
|
+
raise 'Method, add, needs to be implemented for this subscription storage'
|
27
29
|
end
|
28
30
|
|
29
31
|
# Remove an existing subscription
|
@@ -32,8 +34,7 @@ module RServiceBus2
|
|
32
34
|
# has asked for notification
|
33
35
|
# @param [String] queue_name the queue to which the event should be sent
|
34
36
|
def remove(_event_name, _queue_name)
|
35
|
-
|
36
|
-
storage'
|
37
|
+
raise 'Method, remove, needs to be implemented for this subscription storage'
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -1,15 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RServiceBus2
|
2
4
|
# Implementation of Subscription Storage to Redis
|
3
5
|
class SubscriptionStorageFile < SubscriptionStorage
|
4
|
-
|
5
|
-
#
|
6
|
-
# @param [String] app_ame Name of the application, used as a Namespace
|
7
|
-
# @param [String] uri resource location to attach, eg redis://127.0.0.1/foo
|
8
|
-
def initialize(app_name, uri)
|
9
|
-
super(app_name, uri)
|
10
|
-
end
|
11
|
-
|
12
|
-
def get_all
|
6
|
+
def all
|
13
7
|
RServiceBus2.log 'Load subscriptions'
|
14
8
|
return {} unless File.exist?(@uri.path)
|
15
9
|
|
@@ -17,13 +11,7 @@ module RServiceBus2
|
|
17
11
|
end
|
18
12
|
|
19
13
|
def add(event_name, queue_name)
|
20
|
-
|
21
|
-
if File.exist?(@uri.path)
|
22
|
-
s = YAML.load(File.open(@uri.path))
|
23
|
-
else
|
24
|
-
s = {}
|
25
|
-
end
|
26
|
-
|
14
|
+
s = File.exist?(@uri.path) ? YAML.load(File.open(@uri.path)) : {}
|
27
15
|
s[event_name] = [] if s[event_name].nil?
|
28
16
|
|
29
17
|
s[event_name] << queue_name
|
@@ -35,8 +23,7 @@ module RServiceBus2
|
|
35
23
|
end
|
36
24
|
|
37
25
|
def remove(_event_name, _queue_name)
|
38
|
-
|
39
|
-
subscription storage'
|
26
|
+
raise 'Method, remove, needs to be implemented for this subscription storage'
|
40
27
|
end
|
41
28
|
end
|
42
29
|
end
|