rservicebus2 0.2.6 → 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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rservicebus2.rb +6 -4
  3. data/lib/rservicebus2/agent.rb +7 -4
  4. data/lib/rservicebus2/appresource.rb +8 -9
  5. data/lib/rservicebus2/appresource/awsdynamodb.rb +3 -3
  6. data/lib/rservicebus2/appresource/awss3.rb +3 -3
  7. data/lib/rservicebus2/appresource/awssqs.rb +27 -0
  8. data/lib/rservicebus2/appresource/dir.rb +3 -0
  9. data/lib/rservicebus2/appresource/file.rb +2 -0
  10. data/lib/rservicebus2/appresource/fluiddb.rb +3 -0
  11. data/lib/rservicebus2/appresource/fluiddb2.rb +3 -1
  12. data/lib/rservicebus2/appresource_configure.rb +11 -4
  13. data/lib/rservicebus2/audit.rb +4 -2
  14. data/lib/rservicebus2/circuitbreaker.rb +4 -2
  15. data/lib/rservicebus2/config.rb +44 -35
  16. data/lib/rservicebus2/cron_manager.rb +6 -1
  17. data/lib/rservicebus2/endpointmapping.rb +20 -14
  18. data/lib/rservicebus2/errormessage.rb +3 -2
  19. data/lib/rservicebus2/handler_loader.rb +35 -28
  20. data/lib/rservicebus2/handler_manager.rb +31 -25
  21. data/lib/rservicebus2/helper_functions.rb +20 -15
  22. data/lib/rservicebus2/host.rb +63 -124
  23. data/lib/rservicebus2/message.rb +11 -19
  24. data/lib/rservicebus2/message/statisticoutput.rb +2 -0
  25. data/lib/rservicebus2/message/subscription.rb +2 -0
  26. data/lib/rservicebus2/message/verboseoutput.rb +2 -0
  27. data/lib/rservicebus2/monitor.rb +7 -8
  28. data/lib/rservicebus2/monitor/awss3.rb +3 -1
  29. data/lib/rservicebus2/monitor/awssqs.rb +34 -0
  30. data/lib/rservicebus2/monitor/dir.rb +25 -23
  31. data/lib/rservicebus2/monitor/dirnotifier.rb +3 -0
  32. data/lib/rservicebus2/monitor/message.rb +2 -0
  33. data/lib/rservicebus2/monitor/xmldir.rb +2 -0
  34. data/lib/rservicebus2/monitor_configure.rb +47 -34
  35. data/lib/rservicebus2/mq.rb +27 -30
  36. data/lib/rservicebus2/mq/beanstalk.rb +5 -1
  37. data/lib/rservicebus2/resource_manager.rb +14 -19
  38. data/lib/rservicebus2/saga/data.rb +1 -1
  39. data/lib/rservicebus2/saga/manager.rb +2 -2
  40. data/lib/rservicebus2/saga_loader.rb +27 -24
  41. data/lib/rservicebus2/saga_storage.rb +5 -4
  42. data/lib/rservicebus2/sendat_manager.rb +5 -3
  43. data/lib/rservicebus2/sendat_storage.rb +5 -3
  44. data/lib/rservicebus2/sendat_storage/file.rb +6 -2
  45. data/lib/rservicebus2/sendat_storage/inmemory.rb +2 -0
  46. data/lib/rservicebus2/state_manager.rb +5 -4
  47. data/lib/rservicebus2/state_storage.rb +7 -6
  48. data/lib/rservicebus2/statistic_manager.rb +7 -3
  49. data/lib/rservicebus2/subscription_manager.rb +7 -5
  50. data/lib/rservicebus2/subscription_storage.rb +6 -5
  51. data/lib/rservicebus2/subscription_storage/file.rb +5 -18
  52. data/lib/rservicebus2/subscription_storage_configure.rb +2 -0
  53. data/lib/rservicebus2/transporter.rb +63 -52
  54. metadata +19 -18
  55. data/lib/rservicebus2/stats.rb +0 -68
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 977c2ab9f328770086dc29090e1d06def2037e763e872debc8bcbf9c1050e96c
4
- data.tar.gz: 0565acd0857455a423c012e6b9f08dc155018c39adf6387642623684adbaaa07
3
+ metadata.gz: 1bce55c00f0099834944f67c6f97ff927b0af11f2611724f1a7d74a923505588
4
+ data.tar.gz: 2ef31429bfc2a471b4a005598bd5b96e88e5257f81da9786322a6d8e1ba4a253
5
5
  SHA512:
6
- metadata.gz: 596ef0eaed4a2462e324efcda720784bd96fde172975647bd48854c435b97b139029e8e3b5531451cd7e7df2a5a73d9116aa51c19c9bc10ecb55b0a8e9584436
7
- data.tar.gz: 7fbad671a58644b047341c89f4ab54abf50856a82eadc6bfee121465cea6dbec83f81c59e35f5431c410f2e80ad7aedb9e97537ce35e81172ccf92488720c68b
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  class QueueNotFoundForMsg < StandardError
3
5
  end
@@ -22,17 +24,17 @@ 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/AbcSize,Metrics/MethodLength
27
+ # rubocop:disable Metrics/MethodLength
26
28
  def send_msg(message_obj, queue_name, return_address = nil)
27
- fail QueueNotFoundForMsg, message_obj.class.name if queue_name.nil?
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?
31
33
  q = queue_name
32
34
  else
33
35
  parts = queueName.split('@')
34
- msg.set_remote_queue_name(parts[0])
35
- msg.set_remote_host_name(parts[1])
36
+ msg.remote_queue_name = parts[0]
37
+ msg.remote_host_name = parts[1]
36
38
  q = 'transport-out'
37
39
  end
38
40
 
@@ -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
- fail 'Method, connect, needs to be implemented for resource'
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 get_resource
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 'Message: ' + e.message
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,16 +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
  Aws::DynamoDB::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,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
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk-sqs'
4
+ require 'aws-sdk-sts'
5
+
6
+ module RServiceBus2
7
+ # AppResourceAWSDynamoDb
8
+ class AppResourceAWSSQS < AppResource
9
+ def connect(uri)
10
+ queue_name = uri.path.sub('/', '')
11
+
12
+ region = uri.host
13
+
14
+ sts_client = Aws::STS::Client.new(region: region)
15
+ caller_identity_account = sts_client.get_caller_identity.account
16
+
17
+ queue_url = "https://sqs.#{region}.amazonaws.com/" \
18
+ "#{caller_identity_account}/#{queue_name}"
19
+ {
20
+ client: Aws::SQS::Client.new(region: region),
21
+ url: queue_url
22
+ }
23
+ end
24
+
25
+ def finished; end
26
+ end
27
+ end
@@ -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
@@ -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.index('fluiddb') == 0)
19
- v = v['fluiddb'.length..-1] if v.index('fluiddb') == 0
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
 
@@ -37,14 +39,19 @@ module RServiceBus2
37
39
  when 'awss3'
38
40
  require 'rservicebus2/appresource/awss3'
39
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)
40
45
  else
41
46
  abort("Scheme, #{uri.scheme}, not recognised when configuring
42
47
  app resource, #{k}=#{v}")
43
48
  end
44
49
  end
45
50
  end
51
+ # rubocop:enable Metrics/BlockLength
46
52
 
47
53
  rm
48
54
  end
55
+ # rubocop:enable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
49
56
  end
50
57
  end
@@ -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(mq)
5
- @mq = 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 == 0
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
- fail MessageArrivedWhileCricuitBroken if @broken == true
73
+ raise MessageArrivedWhileCricuitBroken if @broken == true
72
74
  end
73
75
 
74
76
  def break_circuit
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RServiceBus2
2
4
  # Marshals configuration information for an rservicebus host
5
+ # rubocop:disable Metrics/ClassLength
3
6
  class Config
4
7
  attr_reader :app_name, :message_endpoint_mappings, :handler_path_list,
5
8
  :saga_path_list, :error_queue_name, :max_retries,
@@ -19,7 +22,7 @@ module RServiceBus2
19
22
  end
20
23
 
21
24
  def get_value(name, default = nil)
22
- value = (ENV[name].nil? || ENV[name] == '') ? default : ENV[name]
25
+ value = ENV[name].nil? || ENV[name] == '' ? default : ENV[name]
23
26
  log "Env value: #{name}: #{value}"
24
27
  value
25
28
  end
@@ -47,6 +50,7 @@ module RServiceBus2
47
50
  self
48
51
  end
49
52
 
53
+ # rubocop:disable Metrics/MethodLength
50
54
  def load_host_section
51
55
  @app_name = get_value('APPNAME', 'RServiceBus2')
52
56
  @error_queue_name = get_value('ERROR_QUEUE_NAME', 'error')
@@ -66,6 +70,7 @@ module RServiceBus2
66
70
 
67
71
  self
68
72
  end
73
+ # rubocop:enable Metrics/MethodLength
69
74
 
70
75
  def ensure_contract_file_exists(path)
71
76
  unless File.exist?(path) || File.exist?("#{path}.rb")
@@ -73,11 +78,11 @@ module RServiceBus2
73
78
  puts "*** path, #{path}, provided does not exist as a file"
74
79
  abort
75
80
  end
76
- unless File.extname(path) == '' || File.extname(path) == '.rb'
77
- puts 'Error while processing contracts'
78
- puts "*** path, #{path}, should point to a ruby file, with extention .rb"
79
- abort
80
- 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
81
86
  end
82
87
 
83
88
  # Marshals paths for contracts
@@ -100,6 +105,16 @@ module RServiceBus2
100
105
  # Marshals paths for lib
101
106
  # Note. .rb extension is optional
102
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
+
103
118
  def load_libs
104
119
  @lib_list = []
105
120
 
@@ -107,18 +122,7 @@ module RServiceBus2
107
122
  paths = './lib' if paths.nil? && File.exist?('./lib')
108
123
  return self if paths.nil?
109
124
 
110
- paths.split(';').each do |path|
111
- log "Loading libs from, #{path}"
112
- unless File.exist?(path)
113
- puts 'Error while processing libs'
114
- puts "*** path, #{path}, should point to a ruby file, with extention
115
- .rb, or"
116
- puts "*** path, #{path}, should point to a directory than conatins
117
- ruby files, that have extention .rb"
118
- abort
119
- end
120
- @lib_list << path
121
- end
125
+ paths.split(';').each { |path| @lib_list << load_lib(path) }
122
126
  self
123
127
  end
124
128
 
@@ -130,38 +134,43 @@ module RServiceBus2
130
134
  # Marshals paths for working_dirs
131
135
  # Note. trailing slashs will be stripped
132
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
+
133
150
  def load_working_dir_list
134
- puts "Config.load_working_dir_list.1"
135
- puts "Config.load_working_dir_list.2 #{@contract_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}")
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
158
- end
165
+ def initialize; end
159
166
  end
160
167
 
161
168
  # Class
162
169
  class ConfigFromSetter < Config
163
- attr_writer :appName, :messageEndpointMappings, :handler_path_list, :errorQueueName, :maxRetries, :forward_received_messages_to, :beanstalkHost
164
- def initialize
165
- end
170
+ attr_writer :app_name, :message_endpoint_mappings, :handler_path_list, :error_queue_name, \
171
+ :max_retries, :forward_received_messages_to, :beanstalk_host
172
+
173
+ def initialize; end
166
174
  end
175
+ # rubocop:enable Lint/MissingSuper
167
176
  end