rservicebus2 0.2.7 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rservicebus2.rb +6 -5
  3. data/lib/rservicebus2/agent.rb +7 -4
  4. data/lib/rservicebus2/appresource.rb +8 -9
  5. data/lib/rservicebus2/appresource/awss3.rb +3 -3
  6. data/lib/rservicebus2/appresource/awssqs.rb +2 -0
  7. data/lib/rservicebus2/appresource/dir.rb +3 -0
  8. data/lib/rservicebus2/appresource/file.rb +2 -0
  9. data/lib/rservicebus2/appresource/fluiddb.rb +3 -0
  10. data/lib/rservicebus2/appresource/fluiddb2.rb +3 -1
  11. data/lib/rservicebus2/appresource_configure.rb +8 -4
  12. data/lib/rservicebus2/audit.rb +4 -2
  13. data/lib/rservicebus2/circuitbreaker.rb +4 -2
  14. data/lib/rservicebus2/config.rb +44 -35
  15. data/lib/rservicebus2/cron_manager.rb +6 -1
  16. data/lib/rservicebus2/endpointmapping.rb +20 -14
  17. data/lib/rservicebus2/errormessage.rb +3 -2
  18. data/lib/rservicebus2/handler_loader.rb +35 -28
  19. data/lib/rservicebus2/handler_manager.rb +31 -25
  20. data/lib/rservicebus2/helper_functions.rb +20 -15
  21. data/lib/rservicebus2/host.rb +63 -124
  22. data/lib/rservicebus2/message.rb +11 -19
  23. data/lib/rservicebus2/message/statisticoutput.rb +2 -0
  24. data/lib/rservicebus2/message/subscription.rb +2 -0
  25. data/lib/rservicebus2/message/verboseoutput.rb +2 -0
  26. data/lib/rservicebus2/monitor.rb +7 -7
  27. data/lib/rservicebus2/monitor/awss3.rb +3 -1
  28. data/lib/rservicebus2/monitor/awssqs.rb +9 -7
  29. data/lib/rservicebus2/monitor/dir.rb +25 -23
  30. data/lib/rservicebus2/monitor/dirnotifier.rb +3 -0
  31. data/lib/rservicebus2/monitor/message.rb +2 -0
  32. data/lib/rservicebus2/monitor/xmldir.rb +2 -0
  33. data/lib/rservicebus2/monitor_configure.rb +47 -37
  34. data/lib/rservicebus2/mq.rb +27 -30
  35. data/lib/rservicebus2/mq/beanstalk.rb +5 -1
  36. data/lib/rservicebus2/resource_manager.rb +14 -19
  37. data/lib/rservicebus2/saga/data.rb +1 -1
  38. data/lib/rservicebus2/saga/manager.rb +2 -2
  39. data/lib/rservicebus2/saga_loader.rb +27 -24
  40. data/lib/rservicebus2/saga_storage.rb +5 -4
  41. data/lib/rservicebus2/sendat_manager.rb +5 -3
  42. data/lib/rservicebus2/sendat_storage.rb +5 -3
  43. data/lib/rservicebus2/sendat_storage/file.rb +6 -2
  44. data/lib/rservicebus2/sendat_storage/inmemory.rb +2 -0
  45. data/lib/rservicebus2/state_manager.rb +5 -4
  46. data/lib/rservicebus2/state_storage.rb +7 -6
  47. data/lib/rservicebus2/statistic_manager.rb +7 -3
  48. data/lib/rservicebus2/subscription_manager.rb +7 -5
  49. data/lib/rservicebus2/subscription_storage.rb +6 -5
  50. data/lib/rservicebus2/subscription_storage/file.rb +5 -18
  51. data/lib/rservicebus2/subscription_storage_configure.rb +2 -0
  52. data/lib/rservicebus2/transporter.rb +63 -52
  53. metadata +2 -3
  54. data/lib/rservicebus2/stats.rb +0 -68
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Coordinate Transactions across resources, handlers, and Sagas
3
5
  class ResourceManager
@@ -13,7 +15,7 @@ module RServiceBus2
13
15
  @app_resources[name] = res
14
16
  end
15
17
 
16
- def get_all
18
+ def all
17
19
  @app_resources
18
20
  end
19
21
 
@@ -37,9 +39,8 @@ module RServiceBus2
37
39
  def commit(msg_name)
38
40
  @state_manager.commit
39
41
  @saga_storage.commit
40
- RServiceBus2.rlog "HandlerManager.commitResourcesUsedToProcessMsg,
41
- #{msg_name}"
42
- @current_resources.each do |k, v|
42
+ RServiceBus2.rlog "HandlerManager.commitResourcesUsedToProcessMsg, #{msg_name}"
43
+ @current_resources.each do |_k, v|
43
44
  RServiceBus2.rlog "Commit resource, #{v.class.name}"
44
45
  v.commit
45
46
  v.finished
@@ -48,21 +49,15 @@ module RServiceBus2
48
49
 
49
50
  def rollback(msg_name)
50
51
  @saga_storage.rollback
51
- RServiceBus2.rlog "HandlerManager.rollbackResourcesUsedToProcessMsg,
52
- #{msg_name}"
53
- @current_resources.each do |k, v|
54
- begin
55
- RServiceBus2.rlog "Rollback resource, #{v.class.name}"
56
- v.rollback
57
- v.finished
58
- rescue StandardError => e1
59
- puts "Caught nested exception rolling back, #{v.class.name}, for msg,
60
- #{msg_name}"
61
- puts '****'
62
- puts e1.message
63
- puts e1.backtrace
64
- puts '****'
65
- end
52
+ RServiceBus2.rlog "HandlerManager.rollbackResourcesUsedToProcessMsg, #{msg_name}"
53
+ @current_resources.each do |_k, v|
54
+ RServiceBus2.rlog "Rollback resource, #{v.class.name}"
55
+ v.rollback
56
+ v.finished
57
+ rescue StandardError => e
58
+ puts "Caught nested exception rolling back, #{v.class.name}, for msg,
59
+ #{msg_name}"
60
+ puts "****\n#{e.message}\n#{e.backtrace}\n'****"
66
61
  end
67
62
  end
68
63
  end
@@ -5,7 +5,7 @@ module RServiceBus2
5
5
  attr_accessor :finished
6
6
 
7
7
  def initialize(saga)
8
- @createdat = DateTime.now
8
+ @createdat = Time.now
9
9
  @correlation_id = UUIDTools::UUID.random_create
10
10
  @saga_class_name = saga.class.name
11
11
  @finished = false
@@ -44,7 +44,7 @@ module RServiceBus2
44
44
  is in the 'attr_accessor' list"
45
45
 
46
46
  @resource_list_by_saga_name[saga.class.name] = []
47
- @resource_manager.get_all.each do |k, v|
47
+ @resource_manager.all.each do |k, v|
48
48
  if saga.class.method_defined?(k)
49
49
  @resource_list_by_saga_name[saga.class.name] << k
50
50
  RServiceBus2.log "Resource attribute, #{k}, found for: " +
@@ -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).get_resource)
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 = './' + file_path unless file_path.start_with?('/')
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('Filepath, ' + file_path + ", given for Saga require doesn't exist")
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 'Expected class name: ' + saga_name + ', not found after require:
43
- ' + require_path
44
- puts '**** Check in ' + file_path + ' that the class is named : ' +
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
- begin
63
- RServiceBus2.rlog 'file_path: ' + file_path
64
- RServiceBus2.rlog 'saga_name: ' + saga_name
67
+ RServiceBus2.rlog "file_path: #{file_path}"
68
+ RServiceBus2.rlog "saga_name: #{saga_name}"
65
69
 
66
- saga = load_saga_from_file(saga_name, file_path)
67
- RServiceBus2.log 'Loaded Saga: ' + saga_name
70
+ saga = load_saga_from_file(saga_name, file_path)
71
+ RServiceBus2.log "Loaded Saga: #{saga_name}"
68
72
 
69
- @saga_manager.register_saga(saga)
73
+ @saga_manager.register_saga(saga)
70
74
 
71
- @list_of_loaded_paths[file_path] = 1
72
- rescue StandardError => e
73
- puts 'Exception loading saga from file: ' + file_path
74
- puts e.message
75
- puts e.backtrace[0]
76
- abort
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)/){$1.upcase}.gsub(/(?:_)(\w)/,'\1')
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
- return SagaStorageDir.new(uri)
10
+ SagaStorageDir.new(uri)
9
11
  when 'inmem'
10
12
  require 'rservicebus2/saga_storage/inmemory'
11
- return SagaStorageInMemory.new(uri)
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 = DateTime.now
20
- @sendat_storage.get_all.each_with_index do |row, idx|
21
- next if row['timestamp'] <= now
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
- return SendAtStorageFile.new(uri)
11
+ SendAtStorageFile.new(uri)
10
12
  when 'inmem'
11
13
  require 'rservicebus2/sendat_storage/inmemory'
12
- return SendAtStorageInMemory.new(uri)
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 get_all
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(@uri.path, 'w') { |f| f.write(YAML.dump(content)) }
38
+ File.open(@path, 'w') { |f| f.write(content) }
35
39
  end
36
40
  end
37
41
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Send at storage in memory
3
5
  class SendAtStorageInMemory
@@ -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.begin unless @state_storage.nil?
20
+ @state_storage&.begin
20
21
  end
21
22
 
22
23
  def get(handler)
23
- @state_storage.get(handler) unless @state_storage.nil?
24
+ @state_storage&.get(handler)
24
25
  end
25
26
 
26
27
  def commit
27
- @state_storage.commit unless @state_storage.nil?
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.rb'
8
- return StateStorageDir.new(uri)
9
+ require 'rservicebus2/state_storage/dir'
10
+ StateStorageDir.new(uri)
9
11
  when 'inmem'
10
- require 'rservicebus2/state_storage/inmemory.rb'
11
- return StateStorageInMemory.new(uri)
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 get_for_reporting_2
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 get_for_reporting_9
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(get_for_reporting_9) if @output
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.get_all
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 "If there should be, ensure you have the appropriate evironment variable set, eg MESSAGE_ENDPOINT_MAPPINGS=#{event_name}:<Queue Name>"
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 'Adding subscription for, ' +
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
- fail 'Method, remove, needs to be implemented for this subscription storage'
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 get_all
18
- fail 'Method, get_all, needs to be implemented for SubscriptionStorage'
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
- fail 'Method, add, needs to be implemented for this subscription storage'
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
- fail 'Method, remove, needs to be implemented for this subscription
36
- storage'
37
+ raise 'Method, remove, needs to be implemented for this subscription storage'
37
38
  end
38
39
  end
39
40
  end