rservicebus2 0.2.6 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
- # Constructor
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
- # s => subscriptions
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
- fail 'Method, remove, needs to be implemented for this
39
- subscription storage'
26
+ raise 'Method, remove, needs to be implemented for this subscription storage'
40
27
  end
41
28
  end
42
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
  module RServiceBus2
3
5
  # Configure SubscriptionStorage for an rservicebus host
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'beanstalk-client'
2
4
  require 'rservicebus2'
3
5
  require 'net/ssh/gateway'
@@ -8,13 +10,15 @@ module RServiceBus2
8
10
 
9
11
  # TODO: Poison Message? Can I bury with timeout in beanstalk ?
10
12
  # Needs to end up on an error queue, destination queue may be down.
13
+ # rubocop:disable Metrics/ClassLength
11
14
  class Transporter
12
15
  def get_value(name, default = nil)
13
- value = (ENV[name].nil? || ENV[name] == '') ? default : ENV[name]
16
+ value = ENV[name].nil? || ENV[name] == '' ? default : ENV[name]
14
17
  RServiceBus2.log "Env value: #{name}: #{value}"
15
18
  value
16
19
  end
17
20
 
21
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
18
22
  def connect_to_source_beanstalk
19
23
  source_queue_name = get_value('SOURCE_QUEUE_NAME', 'transport-out')
20
24
  source_url = get_value('SOURCE_URL', '127.0.0.1:11300')
@@ -22,7 +26,6 @@ module RServiceBus2
22
26
  @source.watch source_queue_name
23
27
 
24
28
  RServiceBus2.log "Connected to, #{source_queue_name}@#{source_url}"
25
-
26
29
  rescue StandardError => e
27
30
  puts 'Error connecting to Beanstalk'
28
31
  puts "Host string, #{sourceUrl}"
@@ -35,71 +38,79 @@ module RServiceBus2
35
38
  end
36
39
  abort
37
40
  end
41
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
38
42
 
39
43
  def disconnect
40
44
  RServiceBus2.log "Disconnect from,
41
45
  #{@remote_user_name}@#{@remote_host_name}/#{@remote_queue_name}"
42
- @gateway.shutdown! unless @gateway.nil?
46
+ @gateway&.shutdown!
43
47
  @gateway = nil
44
48
  @remote_host_name = nil
45
49
 
46
- @destination.close unless @destination.nil?
50
+ @destination&.close
47
51
  @destination = nil
48
52
 
49
53
  @remote_user_name = nil
50
54
  @remote_queue_name = nil
51
55
  end
52
56
 
57
+ # rubocop:disable Metrics/MethodLength
58
+ def connect_local
59
+ @local_port = get_value('LOCAL_PORT', 27_018).to_i
60
+ RServiceBus2.rlog "Local Port: #{@local_port}"
61
+
62
+ RServiceBus2.log "Connect SSH, #{@remote_user_name}@#{@remoteHostName}"
63
+ # Open port 27018 to forward to 127.0.0.11300 on the remote host
64
+ @gateway = Net::SSH::Gateway.new(@remote_host_name, @remote_user_name)
65
+ @gateway.open('127.0.0.1', 11_300, @local_port)
66
+ RServiceBus2.log "Connected to SSH, #{@remote_user_name}@#{@remote_host_name}"
67
+ rescue Errno::EADDRINUSE
68
+ puts "*** Local transport port in use, #{@local_port}"
69
+ puts "*** Change local transport port, #{@localPort}, using format, LOCAL_PORT=#{@localPort + 1}"
70
+ abort
71
+ rescue Errno::EACCES
72
+ puts "*** Local transport port specified, #{@local_port}, needs sudo access"
73
+ puts '*** Change local transport port using format, LOCAL_PORT=27018'
74
+ abort
75
+ end
76
+ # rubocop:enable Metrics/MethodLength
77
+
78
+ def connect_destination
79
+ destination_url = "127.0.0.1:#{@local_port}"
80
+ RServiceBus2.rlog "Connect to Remote Beanstalk, #{destination_url}"
81
+ @destination = Beanstalk::Pool.new([destinationUrl])
82
+ RServiceBus2.rlog "Connected to Remote Beanstalk, #{destination_url}"
83
+ rescue StandardError => e
84
+ if e.message == 'Beanstalk::NotConnected'
85
+ puts "***Could not connect to destination, check beanstalk is running at, #{destination_url}"
86
+ raise CouldNotConnectToDestination
87
+ end
88
+ raise
89
+ end
90
+
91
+ def pull_config(remote_host_name)
92
+ @remote_host_name = remote_host_name
93
+ @remote_user_name = get_value("REMOTE_USER_#{remote_host_name.upcase}")
94
+ return unless @remote_user_name.nil?
95
+
96
+ RServiceBus2.log "**** Username not specified for Host, #{remoteHostName}"
97
+ RServiceBus2.log "**** Add an environment variable of the form, REMOTE_USER_#{remoteHostName.upcase}=[USERNAME]"
98
+ abort
99
+ end
100
+
53
101
  def connect(remote_host_name)
54
102
  RServiceBus2.rlog "connect called, #{remote_host_name}"
55
- if @gateway.nil? || remoteHostName != @remote_host_name || @destination.nil?
56
- disconnect
57
- end
103
+ disconnect if @gateway.nil? || remoteHostName != @remote_host_name || @destination.nil?
58
104
 
59
- if @gateway.nil?
60
- # Get destination url from job
61
- @remote_host_name = remote_host_name
62
- @remote_user_name = get_value("REMOTE_USER_#{remote_host_name.upcase}")
63
- if @remote_user_name.nil?
64
- RServiceBus2.log "**** Username not specified for Host, #{remoteHostName}"
65
- RServiceBus2.log "**** Add an environment variable of the form, REMOTE_USER_#{remoteHostName.upcase}=[USERNAME]"
66
- abort
67
- end
68
-
69
- @local_port = get_value('LOCAL_PORT', 27018).to_i
70
- RServiceBus2.rlog "Local Port: #{@local_port}"
71
- begin
72
- RServiceBus2.log "Connect SSH, #{@remote_user_name}@#{@remoteHostName}"
73
- # Open port 27018 to forward to 127.0.0.11300 on the remote host
74
- @gateway = Net::SSH::Gateway.new(@remote_host_name, @remote_user_name)
75
- @gateway.open('127.0.0.1', 11300, @local_port)
76
- RServiceBus2.log "Connected to SSH, #{@remote_user_name}@#{@remote_host_name}"
77
-
78
- rescue Errno::EADDRINUSE
79
- puts "*** Local transport port in use, #{@local_port}"
80
- puts "*** Change local transport port, #{@localPort}, using format, LOCAL_PORT=#{@localPort+1}"
81
- abort
82
- rescue Errno::EACCES
83
- puts "*** Local transport port specified, #{@local_port}, needs sudo access"
84
- puts '*** Change local transport port using format, LOCAL_PORT=27018'
85
- abort
86
- end
87
-
88
- begin
89
- destination_url = "127.0.0.1:#{@local_port}"
90
- RServiceBus2.rlog "Connect to Remote Beanstalk, #{destination_url}"
91
- @destination = Beanstalk::Pool.new([destinationUrl])
92
- RServiceBus2.rlog "Connected to Remote Beanstalk, #{destination_url}"
93
- rescue StandardError => e
94
- if e.message == 'Beanstalk::NotConnected'
95
- puts "***Could not connect to destination, check beanstalk is running at, #{destination_url}"
96
- raise CouldNotConnectToDestination
97
- end
98
- raise
99
- end
100
- end
105
+ return unless @gateway.nil?
106
+
107
+ # Get destination url from job
108
+ pull_config(remote_host_name)
109
+ connect_local
110
+ connect_destination
101
111
  end
102
112
 
113
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
103
114
  def process
104
115
  # Get the next job from the source queue
105
116
  job = @source.reserve @timeout
@@ -129,14 +140,14 @@ module RServiceBus2
129
140
  end
130
141
  raise e
131
142
  end
143
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
132
144
 
133
145
  def run
134
146
  @timeout = get_value('TIMEOUT', 5)
135
147
  connectToSourceBeanstalk
136
- while true
137
- process
138
- end
148
+ loop { process }
139
149
  disconnect_from_remote_ssh
140
150
  end
141
151
  end
152
+ # rubocop:enable Metrics/ClassLength
142
153
  end
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rservicebus2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Irvine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-28 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: uuidtools
14
+ name: beanstalk-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.0
19
+ version: 1.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.0
26
+ version: 1.1.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: json
28
+ name: fluiddb
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.5.1
33
+ version: 0.1.19
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.5.1
40
+ version: 0.1.19
41
41
  - !ruby/object:Gem::Dependency
42
- name: beanstalk-client
42
+ name: json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.1.1
47
+ version: 2.5.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.1.1
54
+ version: 2.5.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: fluiddb
56
+ name: parse-cron
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.19
61
+ version: 0.1.4
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.19
68
+ version: 0.1.4
69
69
  - !ruby/object:Gem::Dependency
70
- name: parse-cron
70
+ name: uuidtools
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.4
75
+ version: 2.2.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.1.4
82
+ version: 2.2.0
83
83
  description: A Ruby interpretation of NServiceBus
84
84
  email: guy@guyirvine.com
85
85
  executables:
@@ -106,6 +106,7 @@ files:
106
106
  - lib/rservicebus2/appresource.rb
107
107
  - lib/rservicebus2/appresource/awsdynamodb.rb
108
108
  - lib/rservicebus2/appresource/awss3.rb
109
+ - lib/rservicebus2/appresource/awssqs.rb
109
110
  - lib/rservicebus2/appresource/dir.rb
110
111
  - lib/rservicebus2/appresource/file.rb
111
112
  - lib/rservicebus2/appresource/fluiddb.rb
@@ -127,6 +128,7 @@ files:
127
128
  - lib/rservicebus2/message/verboseoutput.rb
128
129
  - lib/rservicebus2/monitor.rb
129
130
  - lib/rservicebus2/monitor/awss3.rb
131
+ - lib/rservicebus2/monitor/awssqs.rb
130
132
  - lib/rservicebus2/monitor/dir.rb
131
133
  - lib/rservicebus2/monitor/dirnotifier.rb
132
134
  - lib/rservicebus2/monitor/message.rb
@@ -154,7 +156,6 @@ files:
154
156
  - lib/rservicebus2/state_storage/dir.rb
155
157
  - lib/rservicebus2/state_storage/inmemory.rb
156
158
  - lib/rservicebus2/statistic_manager.rb
157
- - lib/rservicebus2/stats.rb
158
159
  - lib/rservicebus2/subscription_manager.rb
159
160
  - lib/rservicebus2/subscription_storage.rb
160
161
  - lib/rservicebus2/subscription_storage/file.rb
@@ -1,68 +0,0 @@
1
- module RServiceBus2
2
- # Used to collect various run time stats for runtime reporting
3
- class Stats
4
- def initialize
5
- @hash = {}
6
-
7
- @total_processed = 0
8
- @total_errored = 0
9
- @total_sent = 0
10
- @total_published = 0
11
- @total_reply = 0
12
-
13
- @total_by_message_type = {}
14
-
15
- @written = false
16
- end
17
-
18
- def inc_total_processed
19
- @total_processed += 1
20
- end
21
-
22
- def inc_total_errored
23
- @total_errored += 1
24
- end
25
-
26
- def inc_total_sent
27
- @total_sent += 1
28
- end
29
-
30
- def inc_total_published
31
- @total_published += 1
32
- end
33
-
34
- def inc_total_reply
35
- @total_reply += 1
36
- end
37
-
38
- def inc(key)
39
- @hash[key] = 0 if @hash[key].nil?
40
- @hash[key] += 1
41
- end
42
-
43
- def inc_message_type(class_name)
44
- @total_by_message_type[class_name] = 0 if @total_by_message_type[class_name].nil?
45
- @total_by_message_type[class_name] += 1
46
- end
47
- end
48
-
49
- def get_for_reporting_2
50
- return unless @written == false
51
-
52
- @written = true
53
- types = Hash.new(0)
54
- ObjectSpace.each_object do |obj|
55
- types[obj.class] += 1
56
- end
57
-
58
- types
59
- end
60
-
61
- def get_for_reporting
62
- "T:#{@total_processed};
63
- E:#{@total_errored};
64
- S:#{@total_sent};
65
- P:#{@total_published};
66
- R:#{@total_reply}"
67
- end
68
- end