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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5cab110a6dd40b7b80824e669ac85709bbec790bc948d5bdcb954a1b29184a5
4
- data.tar.gz: 1bc1c569d5af1d01e79c69c0aef99781498bdac5aac13671fd4cd47a286aa2b1
3
+ metadata.gz: a3c83b298bb79d2335fa0c00cfc6493249617f0cff9cfbd2f1d21ee6f0e241d0
4
+ data.tar.gz: 93bd9a061367a3243b99d29c0d9cf18c1aa3d6361d10afba694b775961591eb3
5
5
  SHA512:
6
- metadata.gz: 64d2065fbd9b061cf17eca6f9c8eea5e8aa4663a9e68a27463417d511496d9e329d2d2d227bd7dc0b677f39e1a0f62b56292394f5b22217517f80f097698b2dc
7
- data.tar.gz: 5637363459b8c27057d5d2cba9bbd99f558a3a25fbf4f0d0e2971d4e249e8ab58001f123fee08e82c4ee116c38d849ae9ecafd5452c4416f319277e2c91bbabb
6
+ metadata.gz: 490c5af6b79552613745e6b8b01f53da8f3a3f861268cf854d905fcaa19f65994a4675b0669ee4174fcd2eb7b0367520651faefbf30fbb7864ab9aa0c40e5376
7
+ data.tar.gz: '08698a30dc4cb75f00b14b7fa18b2aebcffef02c7a5b86089e18449e472fe978db16e270bb7a3b115e996fa6eeebd26c12e89ceff980f8cd3e45d71ef1af319a'
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
 
@@ -19,7 +21,6 @@ require 'rservicebus2/mq'
19
21
  require 'rservicebus2/host'
20
22
  require 'rservicebus2/config'
21
23
  require 'rservicebus2/endpointmapping'
22
- require 'rservicebus2/stats'
23
24
  require 'rservicebus2/statistic_manager'
24
25
  require 'rservicebus2/audit'
25
26
 
@@ -45,10 +46,10 @@ require 'rservicebus2/monitor_configure'
45
46
 
46
47
  require 'rservicebus2/agent'
47
48
 
48
- require 'rservicebus2/saga_loader.rb'
49
- require 'rservicebus2/saga/manager.rb'
50
- require 'rservicebus2/saga/data.rb'
51
- require 'rservicebus2/saga/base.rb'
49
+ require 'rservicebus2/saga_loader'
50
+ require 'rservicebus2/saga/manager'
51
+ require 'rservicebus2/saga/data'
52
+ require 'rservicebus2/saga/base'
52
53
 
53
54
  require 'rservicebus2/saga_storage'
54
55
 
@@ -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-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
@@ -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
 
@@ -46,8 +48,10 @@ module RServiceBus2
46
48
  end
47
49
  end
48
50
  end
51
+ # rubocop:enable Metrics/BlockLength
49
52
 
50
53
  rm
51
54
  end
55
+ # rubocop:enable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
52
56
  end
53
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
@@ -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
- fail NoMatchingMsgForCron, name if list.length == 0
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