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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rservicebus2.rb +6 -4
  3. data/lib/rservicebus2/appresource/awss3.rb +3 -3
  4. data/lib/rservicebus2/appresource/awssqs.rb +2 -0
  5. data/lib/rservicebus2/appresource/dir.rb +3 -0
  6. data/lib/rservicebus2/appresource/file.rb +2 -0
  7. data/lib/rservicebus2/appresource/fluiddb.rb +3 -0
  8. data/lib/rservicebus2/appresource/fluiddb2.rb +3 -1
  9. data/lib/rservicebus2/config.rb +38 -29
  10. data/lib/rservicebus2/endpointmapping.rb +2 -4
  11. data/lib/rservicebus2/handler_manager.rb +1 -1
  12. data/lib/rservicebus2/helper_functions.rb +14 -13
  13. data/lib/rservicebus2/host.rb +1 -1
  14. data/lib/rservicebus2/message.rb +2 -0
  15. data/lib/rservicebus2/message/statisticoutput.rb +2 -0
  16. data/lib/rservicebus2/message/subscription.rb +2 -0
  17. data/lib/rservicebus2/message/verboseoutput.rb +2 -0
  18. data/lib/rservicebus2/monitor.rb +7 -7
  19. data/lib/rservicebus2/monitor/awss3.rb +3 -1
  20. data/lib/rservicebus2/monitor/awssqs.rb +9 -7
  21. data/lib/rservicebus2/monitor/dir.rb +24 -22
  22. data/lib/rservicebus2/monitor/dirnotifier.rb +3 -0
  23. data/lib/rservicebus2/monitor/message.rb +2 -0
  24. data/lib/rservicebus2/monitor/xmldir.rb +2 -0
  25. data/lib/rservicebus2/monitor_configure.rb +46 -36
  26. data/lib/rservicebus2/mq.rb +27 -30
  27. data/lib/rservicebus2/saga_loader.rb +27 -24
  28. data/lib/rservicebus2/saga_storage.rb +5 -4
  29. data/lib/rservicebus2/sendat_storage/file.rb +0 -1
  30. data/lib/rservicebus2/state_manager.rb +3 -3
  31. data/lib/rservicebus2/state_storage.rb +7 -6
  32. data/lib/rservicebus2/statistic_manager.rb +7 -3
  33. data/lib/rservicebus2/subscription_manager.rb +7 -5
  34. data/lib/rservicebus2/subscription_storage.rb +6 -5
  35. data/lib/rservicebus2/subscription_storage/file.rb +5 -18
  36. data/lib/rservicebus2/subscription_storage_configure.rb +2 -0
  37. data/lib/rservicebus2/transporter.rb +63 -52
  38. metadata +2 -3
  39. data/lib/rservicebus2/stats.rb +0 -68
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd8b2dfcd1227fbfa6285ecee4096a893a6f034c9bb7106564da2423a7344c8e
4
- data.tar.gz: de0f4dbbf5ac8f3b683485577a73f4f40d19f10705b2d487e13dbf2acd637ef4
3
+ metadata.gz: 1bce55c00f0099834944f67c6f97ff927b0af11f2611724f1a7d74a923505588
4
+ data.tar.gz: 2ef31429bfc2a471b4a005598bd5b96e88e5257f81da9786322a6d8e1ba4a253
5
5
  SHA512:
6
- metadata.gz: a0214102bf52760d3b773ef194cde8718ba6113637f65e4791329109b3ba3fbe05ab9b94e4f9dffc0d39d55f9e2530d5ddfd64629b9ed6916f5cf2b9ee4d38f2
7
- data.tar.gz: 329306b143ee14af68664432dfa7d541f82ef55d1695dd16f77ebb03dd3ffbd28a7bd19f1c6a116d2220bfad302903da6569b717b36e91980bb334eb1f2773d8
6
+ metadata.gz: c4e2c679790f968b54e117a06784a4b827579c8bfb44bf648a4e40a0607167bc09a73860bb18f1ff440bb48974b57c92bb85b5edcf996b33a1ede3e188694e1b
7
+ data.tar.gz: e7837975d2c1db75c7c82dd81a1ed505465d3abd92604b3295a362c8f9ba7427f0b71cd874a6d972e7f3f507f26deb1f88f01c8014c2e4e4168cbd66f8adf541
data/lib/rservicebus2.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Add the currently running directory to the start of the load path
2
4
  # $:.unshift File.dirname(__FILE__) + '/../../lib'
3
5
 
@@ -45,10 +47,10 @@ require 'rservicebus2/monitor_configure'
45
47
 
46
48
  require 'rservicebus2/agent'
47
49
 
48
- require 'rservicebus2/saga_loader.rb'
49
- require 'rservicebus2/saga/manager.rb'
50
- require 'rservicebus2/saga/data.rb'
51
- require 'rservicebus2/saga/base.rb'
50
+ require 'rservicebus2/saga_loader'
51
+ require 'rservicebus2/saga/manager'
52
+ require 'rservicebus2/saga/data'
53
+ require 'rservicebus2/saga/base'
52
54
 
53
55
  require 'rservicebus2/saga_storage'
54
56
 
@@ -1,16 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-sdk-s3'
2
4
 
3
5
  module RServiceBus2
4
6
  # AppResourceAWSDynamoDb
5
7
  class AppResourceAWSS3 < AppResource
6
- # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
7
8
  def connect(uri)
8
9
  region = uri.host
9
10
 
10
11
  Aws::S3::Client.new(region: region)
11
12
  end
12
13
 
13
- def finished
14
- end
14
+ def finished; end
15
15
  end
16
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-sdk-sqs'
2
4
  require 'aws-sdk-sts'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # AppResourceDir
3
5
  class AppResourceDir < AppResource
@@ -26,5 +28,6 @@ module RServiceBus2
26
28
 
27
29
  input_dir
28
30
  end
31
+ # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
29
32
  end
30
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # App Resource File
3
5
  class AppResourceFile < AppResource
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'FluidDb/Db'
4
+
2
5
  module RServiceBus2
3
6
  # Implementation of an AppResource - FluidDb
4
7
  class AppResourceFluidDb < AppResource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fluiddb2'
2
4
 
3
5
  module RServiceBus2
@@ -16,8 +18,8 @@ module RServiceBus2
16
18
  def commit
17
19
  @connection.commit
18
20
  end
19
-
20
21
  # Transaction Semantics
22
+
21
23
  def rollback
22
24
  @connection.rollback
23
25
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module RServiceBus2
4
4
  # Marshals configuration information for an rservicebus host
5
+ # rubocop:disable Metrics/ClassLength
5
6
  class Config
6
7
  attr_reader :app_name, :message_endpoint_mappings, :handler_path_list,
7
8
  :saga_path_list, :error_queue_name, :max_retries,
@@ -49,6 +50,7 @@ module RServiceBus2
49
50
  self
50
51
  end
51
52
 
53
+ # rubocop:disable Metrics/MethodLength
52
54
  def load_host_section
53
55
  @app_name = get_value('APPNAME', 'RServiceBus2')
54
56
  @error_queue_name = get_value('ERROR_QUEUE_NAME', 'error')
@@ -68,6 +70,7 @@ module RServiceBus2
68
70
 
69
71
  self
70
72
  end
73
+ # rubocop:enable Metrics/MethodLength
71
74
 
72
75
  def ensure_contract_file_exists(path)
73
76
  unless File.exist?(path) || File.exist?("#{path}.rb")
@@ -75,11 +78,11 @@ module RServiceBus2
75
78
  puts "*** path, #{path}, provided does not exist as a file"
76
79
  abort
77
80
  end
78
- unless File.extname(path) == '' || File.extname(path) == '.rb'
79
- puts 'Error while processing contracts'
80
- puts "*** path, #{path}, should point to a ruby file, with extention .rb"
81
- abort
82
- end
81
+ return if File.extname(path) == '.rb'
82
+
83
+ puts 'Error while processing contracts'
84
+ puts "*** path, #{path}, should point to a ruby file, with extention .rb"
85
+ abort
83
86
  end
84
87
 
85
88
  # Marshals paths for contracts
@@ -102,6 +105,16 @@ module RServiceBus2
102
105
  # Marshals paths for lib
103
106
  # Note. .rb extension is optional
104
107
  # Expected format: /one/two/contracts
108
+ def load_lib(path)
109
+ log "Loading libs from, #{path}"
110
+ return path if File.exist?(path)
111
+
112
+ puts 'Error while processing libs'
113
+ puts "*** path, #{path}, should point to a ruby file, with extention .rb, or"
114
+ puts "*** path, #{path}, should point to a directory than conatins ruby files, that have extention .rb"
115
+ abort
116
+ end
117
+
105
118
  def load_libs
106
119
  @lib_list = []
107
120
 
@@ -109,18 +122,7 @@ module RServiceBus2
109
122
  paths = './lib' if paths.nil? && File.exist?('./lib')
110
123
  return self if paths.nil?
111
124
 
112
- paths.split(';').each do |path|
113
- log "Loading libs from, #{path}"
114
- unless File.exist?(path)
115
- puts 'Error while processing libs'
116
- puts "*** path, #{path}, should point to a ruby file, with extention
117
- .rb, or"
118
- puts "*** path, #{path}, should point to a directory than conatins
119
- ruby files, that have extention .rb"
120
- abort
121
- end
122
- @lib_list << path
123
- end
125
+ paths.split(';').each { |path| @lib_list << load_lib(path) }
124
126
  self
125
127
  end
126
128
 
@@ -132,29 +134,35 @@ module RServiceBus2
132
134
  # Marshals paths for working_dirs
133
135
  # Note. trailing slashs will be stripped
134
136
  # Expected format: <path 1>;<path 2>
137
+ def load_working_dir_path(path)
138
+ path = path.strip.chomp('/')
139
+ unless Dir.exist?(path.to_s)
140
+ puts 'Error while processing working directory list'
141
+ puts "*** path, #{path}, does not exist"
142
+ abort
143
+ end
144
+ @handler_path_list << "#{path}/messagehandler" if Dir.exist?("#{path}/messagehandler")
145
+ @saga_path_list << "#{path}/saga" if Dir.exist?("#{path}/saga")
146
+ @contract_list << "#{path}/contract.rb" if File.exist?("#{path}/contract.rb")
147
+ @lib_list << "#{path}/lib" if File.exist?("#{path}/lib")
148
+ end
149
+
135
150
  def load_working_dir_list
136
151
  path_list = get_value('WORKING_DIR', './')
137
152
  return self if path_list.nil?
138
153
 
139
154
  path_list.split(';').each do |path|
140
- path = path.strip.chomp('/')
141
- unless Dir.exist?(path.to_s)
142
- puts 'Error while processing working directory list'
143
- puts "*** path, #{path}, does not exist"
144
- abort
145
- end
146
- @handler_path_list << "#{path}/messagehandler" if Dir.exist?("#{path}/messagehandler")
147
- @saga_path_list << "#{path}/saga" if Dir.exist?("#{path}/saga")
148
- @contract_list << "#{path}/contract.rb" if File.exist?("#{path}/contract.rb")
149
- @lib_list << "#{path}/lib" if File.exist?("#{path}/lib")
155
+ load_working_dir_path(path)
150
156
  end
151
157
  self
152
158
  end
153
159
  end
160
+ # rubocop:enable Metrics/ClassLength
154
161
 
155
162
  # Class
163
+ # rubocop:disable Lint/MissingSuper
156
164
  class ConfigFromEnv < Config
157
- def initialize; end;
165
+ def initialize; end
158
166
  end
159
167
 
160
168
  # Class
@@ -162,6 +170,7 @@ module RServiceBus2
162
170
  attr_writer :app_name, :message_endpoint_mappings, :handler_path_list, :error_queue_name, \
163
171
  :max_retries, :forward_received_messages_to, :beanstalk_host
164
172
 
165
- def initialize; end;
173
+ def initialize; end
166
174
  end
175
+ # rubocop:enable Lint/MissingSuper
167
176
  end
@@ -12,8 +12,7 @@ module RServiceBus2
12
12
  RServiceBus2.log(string)
13
13
  end
14
14
 
15
- # rubocop:disable Metrics/AbcSize
16
- # rubocop:disable Metrics/MethodLength
15
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
17
16
  def configure_mapping(mapping)
18
17
  match = mapping.match(/(.+):(.+)/)
19
18
  if match.nil?
@@ -36,8 +35,7 @@ module RServiceBus2
36
35
  end
37
36
  @queue_name_list << match[2]
38
37
  end
39
- # rubocop:enable Metrics/AbcSize
40
- # rubocop:enable Metrics/MethodLength
38
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
41
39
 
42
40
  # rubocop:disable Metrics/MethodLength
43
41
  def configure(local_queue_name = nil)
@@ -102,7 +102,7 @@ module RServiceBus2
102
102
  next if @resource_list_by_handler_name[handler.class.name].nil?
103
103
 
104
104
  @resource_list_by_handler_name[handler.class.name].each do |k|
105
- handler.instance_variable_set("@#{k}", @resource_manager.get(k).get_resource)
105
+ handler.instance_variable_set("@#{k}", @resource_manager.get(k).resource)
106
106
  RServiceBus2.rlog "App resource attribute, #{k}, set for: #{handler.class.name}"
107
107
  end
108
108
  end
@@ -14,14 +14,14 @@ module RServiceBus2
14
14
  convert_dto_to_hash(obj).to_json
15
15
  end
16
16
 
17
- def self.log(string, ver = false)
17
+ def self.log(string, ver: false)
18
18
  return if check_environment_variable('TESTING')
19
19
 
20
20
  type = ver ? 'VERB' : 'INFO'
21
- if check_environment_variable('VERBOSE') || !ver
22
- timestamp = Time.new.strftime('%Y-%m-%d %H:%M:%S')
23
- puts "[#{type}] #{timestamp} :: #{string}"
24
- end
21
+ return unless check_environment_variable('VERBOSE') || !ver
22
+
23
+ timestamp = Time.new.strftime('%Y-%m-%d %H:%M:%S')
24
+ puts "[#{type}] #{timestamp} :: #{string}"
25
25
  end
26
26
 
27
27
  def self.rlog(string)
@@ -43,6 +43,7 @@ module RServiceBus2
43
43
  value
44
44
  end
45
45
 
46
+ # rubocop:disable Metrics/MethodLength
46
47
  def self.send_msg(msg, response_queue = 'agent')
47
48
  require 'rservicebus2/endpointmapping'
48
49
  endpoint_mapping = EndpointMapping.new
@@ -54,13 +55,12 @@ module RServiceBus2
54
55
  Audit.new(agent).audit_to_queue(msg)
55
56
  agent.send_msg(msg, queue_name, response_queue)
56
57
  rescue QueueNotFoundForMsg => e
57
- msg = "\n"
58
- msg = "#{msg}*** Queue not found for, #{e.message}\n"
59
- msg = "#{msg}*** Ensure you have an environment variable set for this
60
- Message Type, eg, \n"
61
- msg = "#{msg}*** MESSAGE_ENDPOINT_MAPPINGS=#{e.message}:<QueueName>\n"
62
- raise StandardError, msg
58
+ raise StandardError, '' \
59
+ "*** Queue not found for, #{e.message}\n" \
60
+ "*** Ensure you have an environment variable set for this Message Type, eg, \n" \
61
+ "*** MESSAGE_ENDPOINT_MAPPINGS=#{e.message}:<QueueName>\n"
63
62
  end
63
+ # rubocop:enable Metrics/MethodLength
64
64
 
65
65
  def self.check_for_reply(queue_name)
66
66
  ENV['RSBMQ'] = 'beanstalk://localhost' if ENV['RSBMQ'].nil?
@@ -76,9 +76,9 @@ module RServiceBus2
76
76
  #{caller[0]}. #{string}"
77
77
  end
78
78
 
79
+ # rubocop:disable Metrics/CyclomaticComplexity
79
80
  def self.check_environment_variable(string)
80
- return false if ENV[string].nil?
81
- return false if ENV[string] == ''
81
+ return false if ENV[string].nil? || ENV[string] == ''
82
82
  return true if ENV[string] == true || ENV[string] =~ (/(true|t|yes|y|1)$/i)
83
83
  return false if ENV[string] == false ||
84
84
  ENV[string].nil? ||
@@ -86,4 +86,5 @@ module RServiceBus2
86
86
 
87
87
  raise ArgumentError, "invalid value for Environment Variable: \"#{string}\""
88
88
  end
89
+ # rubocop:enable Metrics/CyclomaticComplexity
89
90
  end
@@ -119,7 +119,7 @@ module RServiceBus2
119
119
  configure_saga_storage
120
120
  configure_app_resource
121
121
  @circuit_breaker = CircuitBreaker.new(self)
122
- @monitors = ConfigureMonitor.new(self, @resource_manager).get_monitors(ENV)
122
+ @monitors = ConfigureMonitor.new(self, @resource_manager).monitors(ENV)
123
123
  load_handlers
124
124
  load_sagas
125
125
  @cron_manager = CronManager.new(self, @handler_manager.msg_names)
@@ -18,6 +18,7 @@ module RServiceBus2
18
18
  # @param [Object] msg The msg to be sent
19
19
  # @param [Object] returnAddress A queue to which the destination message
20
20
  # handler can send replies
21
+ # rubocop:disable Metrics/MethodLength
21
22
  def initialize(msg, return_address, correlation_id = nil)
22
23
  if RServiceBus2.check_environment_variable('RSBMSG_COMPRESS')
23
24
  @compressed = true
@@ -35,6 +36,7 @@ module RServiceBus2
35
36
  @msg_id = UUIDTools::UUID.random_create
36
37
  @error_list = []
37
38
  end
39
+ # rubocop:enable Metrics/MethodLength
38
40
 
39
41
  # If an error occurs while processing the message, this method allows details of the error to held
40
42
  # next to the msg.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  class MessageStatisticOutputOn
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Class to hold message subscriptions
3
5
  class MessageSubscription
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  class MessageVerboseOutputOn
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Monitor
3
5
  class Monitor
@@ -5,12 +7,12 @@ module RServiceBus2
5
7
 
6
8
  # The method which actually connects to the resource.
7
9
  def connect(_uri)
8
- fail 'Method, connect, needs to be implemented for resource'
10
+ raise 'Method, connect, needs to be implemented for resource'
9
11
  end
10
12
 
11
13
  # The method which actually connects to the resource.
12
14
  def look
13
- fail 'Method, Look, needs to be implemented for the Monitor'
15
+ raise 'Method, Look, needs to be implemented for the Monitor'
14
16
  end
15
17
 
16
18
  def _connect
@@ -34,8 +36,7 @@ module RServiceBus2
34
36
  end
35
37
 
36
38
  # A notification that allows cleanup
37
- def finished
38
- end
39
+ def finished; end
39
40
 
40
41
  # At least called in the Host rescue block, to ensure all network links
41
42
  # are healthy
@@ -43,9 +44,8 @@ module RServiceBus2
43
44
  begin
44
45
  finished
45
46
  rescue StandardError => e
46
- puts '** Monitor. An error was raised while closing connection to, ' +
47
- @uri
48
- puts 'Message: ' + e.message
47
+ puts "** Monitor. An error was raised while closing connection to, #{@uri}"
48
+ puts "Message: #{e.message}"
49
49
  puts e.backtrace
50
50
  end
51
51
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-sdk-s3'
2
4
 
3
5
  module RServiceBus2
@@ -36,7 +38,7 @@ module RServiceBus2
36
38
  file_processed = 0
37
39
  max_files_processed = 2
38
40
 
39
- objects = @s3_client.list_objects_v2( bucket: @bucket_name, max_keys: max_files_processed).contents
41
+ objects = @s3_client.list_objects_v2(bucket: @bucket_name, max_keys: max_files_processed).contents
40
42
 
41
43
  objects.each do |object|
42
44
  RServiceBus2.log "Ready to process, #{object.key}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-sdk-sqs'
2
4
  require 'aws-sdk-sts'
3
5
 
@@ -12,20 +14,20 @@ module RServiceBus2
12
14
  sts_client = Aws::STS::Client.new(region: region)
13
15
  caller_identity_account = sts_client.get_caller_identity.account
14
16
 
15
- @queue_url = "https://sqs.#{region}.amazonaws.com/" +
16
- "#{caller_identity_account}/#{queue_name}"
17
+ @queue_url = "https://sqs.#{region}.amazonaws.com/#{caller_identity_account}/#{queue_name}"
17
18
  @sqs_client = Aws::SQS::Client.new(region: region)
18
19
  end
19
20
 
20
21
  def look
21
- # TODO make max available as env variable
22
22
  response = @sqs_client.receive_message(queue_url: @queue_url, max_number_of_messages: 1)
23
23
  response.messages.each do |message|
24
24
  send(message.body, URI.parse(CGI.escape(@queue_url)))
25
- @sqs_client.delete_message({
26
- queue_url: @queue_url,
27
- receipt_handle: message.receipt_handle
28
- })
25
+ @sqs_client.delete_message(
26
+ {
27
+ queue_url: @queue_url,
28
+ receipt_handle: message.receipt_handle
29
+ }
30
+ )
29
31
  end
30
32
  end
31
33
  end