rservicebus2 0.1.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fada1aee3a7884d50bf77a55981556c5b813ddcf
4
- data.tar.gz: dd63dae7e3e5dcac2d0fc9d316202edb38eab16a
2
+ SHA256:
3
+ metadata.gz: 977c2ab9f328770086dc29090e1d06def2037e763e872debc8bcbf9c1050e96c
4
+ data.tar.gz: 0565acd0857455a423c012e6b9f08dc155018c39adf6387642623684adbaaa07
5
5
  SHA512:
6
- metadata.gz: d0bfe746cdd9d90688a6dbea40589db4c9fdd99054fd38406eaaa87f46756d969422d6ca5d404622c7989638385ca0c6aff37fb34e95b02ce84caa4f689f193e
7
- data.tar.gz: c7f3ea7b8960d47ce837cffb3d085c64665cd0c053b531ccd7baecc146720597ca261a05166ccec26e2e74f6d92fea7d34506d3a8fe6d58b8cfc5be3f36d074b
6
+ metadata.gz: 596ef0eaed4a2462e324efcda720784bd96fde172975647bd48854c435b97b139029e8e3b5531451cd7e7df2a5a73d9116aa51c19c9bc10ecb55b0a8e9584436
7
+ data.tar.gz: 7fbad671a58644b047341c89f4ab54abf50856a82eadc6bfee121465cea6dbec83f81c59e35f5431c410f2e80ad7aedb9e97537ce35e81172ccf92488720c68b
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # rservicebus2
2
+
3
+ Use the examples directory as the starting point.
4
+
5
+ ## General Approach
6
+
7
+ 1. Convention over Configuration
8
+ 2. Configuration via Environment Variables
9
+ 3. Working examples provided for configuration
10
+
11
+ ## General Config
12
+
13
+ ### APPNAME
14
+ 1. Name of process
15
+ 2. Doubles as default queueName
16
+ 3. Defaults to directory name
17
+
18
+ ### MAX_RETRIES
19
+ 1. If an exception is generated while processing a message, the message can be
20
+ retried. This allows the number of retries to be set.
21
+ 2. Defaults to 5
22
+
23
+ ### ERROR_QUEUE_NAME
24
+ 1. If an exception is generated while processing a message, the message can be
25
+ retried. Once all retries are exhausted, the message will be put in the error queue.
26
+ 2. This allows the name of the queue to be set.
27
+ 3. Defaults to error
28
+
29
+ ### WORKING_DIR
30
+ 1. Where message handlers are looked for.
31
+ 2. Defaults to current directory
32
+
33
+ ### VERBOSE
34
+ 1. Send out more logging to track message processing
35
+
36
+ ### AUDIT_QUEUE_NAME
37
+ 1. When set, a copy of all messages sent and received will be add to this queue
38
+
39
+ ### RSBCRON_[msg name]
40
+ 1. An empty message will be created and sent based on the cron string
41
+
42
+ ## RSBMQ - Message queue
43
+ 1. Environment Variable Name: RSBMQ
44
+
45
+ ### Beanstalk
46
+
47
+ ### Redis
48
+
49
+ ### SQS
50
+ RSBMQ=aws://[region]/[queue_name]
@@ -0,0 +1,16 @@
1
+ require 'aws-sdk-dynamodb'
2
+
3
+ module RServiceBus2
4
+ # AppResourceAWSDynamoDb
5
+ class AppResourceAWSDynamoDb < AppResource
6
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
7
+ def connect(uri)
8
+ region = uri.host
9
+
10
+ Aws::DynamoDB::Client.new(region: region)
11
+ end
12
+
13
+ def finished
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'aws-sdk-s3'
2
+
3
+ module RServiceBus2
4
+ # AppResourceAWSDynamoDb
5
+ class AppResourceAWSS3 < AppResource
6
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
7
+ def connect(uri)
8
+ region = uri.host
9
+
10
+ Aws::S3::Client.new(region: region)
11
+ end
12
+
13
+ def finished
14
+ end
15
+ end
16
+ end
@@ -31,6 +31,12 @@ module RServiceBus2
31
31
  when 'file'
32
32
  require 'rservicebus2/appresource/file'
33
33
  rm.add k.sub('RSB_', ''), AppResourceFile.new(host, uri)
34
+ when 'awsdynamodb'
35
+ require 'rservicebus2/appresource/awsdynamodb'
36
+ rm.add k.sub('RSB_', ''), AppResourceAWSDynamoDb.new(host, uri)
37
+ when 'awss3'
38
+ require 'rservicebus2/appresource/awss3'
39
+ rm.add k.sub('RSB_', ''), AppResourceAWSS3.new(host, uri)
34
40
  else
35
41
  abort("Scheme, #{uri.scheme}, not recognised when configuring
36
42
  app resource, #{k}=#{v}")
@@ -43,8 +43,8 @@ module RServiceBus2
43
43
 
44
44
  # Thin veneer for Configuring state
45
45
  def configure_saga_storage
46
- string = RServiceBus2.get_value('SAGA_URI')
47
- string = 'dir:///tmp' if string.nil?
46
+ string = RServiceBus2.get_value('SAGA_URI', 'dir:///tmp/saga')
47
+ # string = 'dir:///tmp' if string.nil?
48
48
 
49
49
  uri = URI.parse(string)
50
50
  @saga_storage = SagaStorage.get(uri)
@@ -26,6 +26,7 @@ module RServiceBus2
26
26
  def initialize(bus, name, uri)
27
27
  @bus = bus
28
28
  new_anonymous_class = Class.new(MonitorMessage)
29
+ puts "name: #{name}"
29
30
  Object.const_set(name, new_anonymous_class)
30
31
  @msg_type = Object.const_get(name)
31
32
 
@@ -0,0 +1,51 @@
1
+ require 'aws-sdk-s3'
2
+
3
+ module RServiceBus2
4
+ # Monitor S3 Bucket for objects
5
+ class MonitorAWSS3 < Monitor
6
+ def connect(uri)
7
+ @bucket_name = uri.path
8
+ @bucket_name[0] = ''
9
+
10
+ @region = uri.host
11
+
12
+ @s3_client = Aws::S3::Client.new(region: @region)
13
+ @input_filter = []
14
+ end
15
+
16
+ def process_content(content)
17
+ content
18
+ end
19
+
20
+ def process_path(object_key)
21
+ # content = read_content_from_object(object_key)
22
+ resp = @s3_client.get_object(bucket: @bucket_name, key: object_key)
23
+
24
+ # call #read or #string on the response body
25
+ content = resp.body.read
26
+ payload = process_content(content)
27
+
28
+ send(payload, URI.parse(CGI.escape("s3://#{@region}/#{@bucket_name}/#{object_key}")))
29
+
30
+ @s3_client.delete_object({ bucket: @bucket_name, key: object_key })
31
+
32
+ content
33
+ end
34
+
35
+ def look
36
+ file_processed = 0
37
+ max_files_processed = 2
38
+
39
+ objects = @s3_client.list_objects_v2( bucket: @bucket_name, max_keys: max_files_processed).contents
40
+
41
+ objects.each do |object|
42
+ RServiceBus2.log "Ready to process, #{object.key}"
43
+ process_path(object.key)
44
+
45
+ file_processed += 1
46
+ RServiceBus2.log "Processed #{file_processed} of #{objects.length}."
47
+ RServiceBus2.log "Allow system tick #{self.class.name}"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -48,6 +48,9 @@ module RServiceBus2
48
48
  when 'dir'
49
49
  require 'rservicebus2/monitor/dir'
50
50
  monitor = MonitorDir.new(@host, name, uri)
51
+ when 'awss3'
52
+ require 'rservicebus2/monitor/awss3'
53
+ monitor = MonitorAWSS3.new(@host, name, uri)
51
54
  when 'dirnotifier'
52
55
  require 'rservicebus2/monitor/dirnotifier'
53
56
  monitor = MonitorDirNotifier.new(@host, name, uri)
@@ -20,10 +20,13 @@ module RServiceBus2
20
20
  mq = MQBeanstalk.new(uri)
21
21
  when 'file'
22
22
  require 'rservicebus2/mq/file'
23
- mq = MQFile.new(uri)
23
+ mq = MQFile.new(uri)
24
24
  when 'redis'
25
25
  require 'rservicebus2/mq/redis'
26
- mq = MQRedis.new(uri)
26
+ mq = MQRedis.new(uri)
27
+ when 'aws'
28
+ require 'rservicebus2/mq/aws'
29
+ mq = MQAWS.new(uri)
27
30
  else
28
31
  abort("Scheme, #{uri.scheme}, not recognised when configuring mq,
29
32
  #{string}")
@@ -0,0 +1,85 @@
1
+ require 'aws-sdk-sqs'
2
+ require 'aws-sdk-sts'
3
+ require 'rservicebus2/mq'
4
+
5
+ module RServiceBus2
6
+ # Beanstalk client implementation.
7
+ class MQAWS < MQ
8
+ # Connect to the broker
9
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
10
+ def connect(region, port)
11
+ begin
12
+ @max_job_size = 4_194_304
13
+ @region = region
14
+
15
+ sts_client = Aws::STS::Client.new(region: region)
16
+ @caller_identity_account = sts_client.get_caller_identity.account
17
+ rescue StandardError => e
18
+ puts 'Error connecting to AWS'
19
+ puts "Host string, #{region}"
20
+ puts e.message
21
+ puts e.backtrace
22
+ abort
23
+ end
24
+ end
25
+
26
+ def subscribe(queuename)
27
+ # For example:
28
+ # 'https://sqs.us-east-1.amazonaws.com/111111111111/my-queue'
29
+ @queue_url = 'https://sqs.' + @region + '.amazonaws.com/' +
30
+ @caller_identity_account + '/' + queuename
31
+ @sqs_client = Aws::SQS::Client.new(region: @region)
32
+ end
33
+
34
+ # Get next msg from queue
35
+ def pop
36
+ begin
37
+ response = @sqs_client.receive_message(
38
+ queue_url: @queue_url,
39
+ max_number_of_messages: 1
40
+ )
41
+
42
+ if response.messages.count.zero?
43
+ raise NoMsgToProcess
44
+ end
45
+
46
+ response.messages.each do |message|
47
+ @job = message
48
+ end
49
+ rescue StandardError => e
50
+ raise e
51
+ end
52
+ @job.body
53
+ end
54
+
55
+ def return_to_queue
56
+ # @job.release if @job
57
+ @job = nil
58
+ end
59
+
60
+ def ack
61
+ @sqs_client.delete_message({
62
+ queue_url: @queue_url,
63
+ receipt_handle: @job.receipt_handle
64
+ })
65
+ @job = nil
66
+ end
67
+
68
+ def send(queue_name, msg)
69
+ if msg.length > @max_job_size
70
+ puts '***Attempting to send a msg which will not fit on queue.'
71
+ puts "***Msg size, #{msg.length}, max msg size, #{@max_job_size}."
72
+ fail JobTooBigError, "Msg size, #{msg.length}, max msg size,
73
+ #{@max_job_size}"
74
+ end
75
+
76
+ queue_url = 'https://sqs.' + @region + '.amazonaws.com/' +
77
+ @caller_identity_account + '/' + queue_name
78
+
79
+ @sqs_client.send_message(
80
+ queue_url: queue_url,
81
+ message_body: msg
82
+ )
83
+ end
84
+ end
85
+ end
@@ -24,7 +24,7 @@ module RServiceBus2
24
24
  end
25
25
 
26
26
  def get_start_with_method_names(saga)
27
- get_methods_by_prefix(saga, 'startwith_')
27
+ get_methods_by_prefix(saga, 'start_with_')
28
28
  end
29
29
 
30
30
  # setBusAttributeIfRequested
@@ -63,7 +63,7 @@ module RServiceBus2
63
63
  @start_with[msg_name] = [] if @start_with[msg_name].nil?
64
64
  @start_with[msg_name] << s
65
65
 
66
- RServiceBus2.log "Registered, #{saga.name}, to startwith, #{msg_name}", true
66
+ RServiceBus2.log "Registered, #{saga.name}, to start_with, #{msg_name}", true
67
67
  end
68
68
 
69
69
  @saga[saga.name] = s
@@ -88,12 +88,13 @@ module RServiceBus2
88
88
  msg_class_name = msg.class.name.downcase
89
89
 
90
90
  RServiceBus2.log "SagaManager, started processing, #{msg_class_name}", true
91
- unless @start_with[msg_class_name].nil?
91
+ if @start_with.key?(msg_class_name)
92
+ # unless @start_with[msg_class_name].nil?
92
93
  @start_with[msg_class_name].each do |saga|
93
94
  data = SagaData.new(saga)
94
95
  @saga_storage.set(data)
95
96
 
96
- method_name = "startwith_#{msg_class_name}"
97
+ method_name = "start_with_#{msg_class_name}"
97
98
  process_msg(saga, data, method_name, msg)
98
99
 
99
100
  handled = true
@@ -102,8 +103,10 @@ module RServiceBus2
102
103
  return handled if handled == true
103
104
 
104
105
  return false if rmsg.correlation_id.nil?
106
+
105
107
  data = @saga_storage.get(rmsg.correlation_id)
106
- return handled if data.nil?
108
+ return false if data.nil?
109
+
107
110
  method_name = "handle_#{msg_class_name}"
108
111
  saga = @saga[data.saga_class_name]
109
112
  process_msg(saga, data, method_name, msg)
@@ -16,21 +16,21 @@ module RServiceBus2
16
16
  # Cleans the given path to ensure it can be used for as a parameter for the
17
17
  # require statement.
18
18
  # @param [String] file_path the path to be cleaned
19
- def get_require_path(filePath)
19
+ def get_require_path(file_path)
20
20
  file_path = './' + file_path unless file_path.start_with?('/')
21
21
 
22
22
  return file_path.sub('.rb', '') if File.exist?(file_path)
23
23
 
24
- abort('Filepath, ' + filePath + ", given for Saga require doesn't exist")
24
+ abort('Filepath, ' + file_path + ", given for Saga require doesn't exist")
25
25
  end
26
26
 
27
- # Instantiate the saga named in sagaName from the file name in filePath
27
+ # Instantiate the saga named in sagaName from the file name in file_path
28
28
  # Exceptions will be raised if encountered when loading sagas. This is a
29
29
  # load time activity, so sagas should load correctly. As much information
30
30
  # as possible is returned to enable the saga to be fixed, or configuration
31
31
  # corrected.
32
32
  # @param [String] sagaName name of the saga to instantiate
33
- # @param [String] filePath the path to the file to be loaded
33
+ # @param [String] file_path the path to the file to be loaded
34
34
  # @return [RServiceBus2::Saga] the loader
35
35
  def load_saga_from_file(saga_name, file_path)
36
36
  require_path = get_require_path(file_path)
@@ -50,7 +50,7 @@ module RServiceBus2
50
50
  end
51
51
 
52
52
  # Wrapper function
53
- # @param [String] filePath
53
+ # @param [String] file_path
54
54
  # @param [String] sagaName
55
55
  # @returns [RServiceBus2::Saga] saga
56
56
  def load_saga(file_path, saga_name)
@@ -97,7 +97,7 @@ module RServiceBus2
97
97
 
98
98
  saga_name = base_name.sub(ext_name, '')
99
99
 
100
- "Saga_#{saga_name}"
100
+ "saga_#{saga_name}".gsub(/(?<=_|^)(\w)/){$1.upcase}.gsub(/(?:_)(\w)/,'\1')
101
101
  end
102
102
 
103
103
  # Entry point for loading Sagas
@@ -106,7 +106,7 @@ module RServiceBus2
106
106
  RServiceBus2.rlog "SagaLoader.loadSagasFromPath. base_dir: #{base_dir}"
107
107
 
108
108
  get_list_of_files_for_dir(base_dir).each do |file_path|
109
- unless filePath.end_with?('.')
109
+ unless file_path.end_with?('.')
110
110
  saga_name = get_saga_name(file_path)
111
111
  load_saga(file_path, saga_name)
112
112
  end
@@ -75,7 +75,7 @@ module RServiceBus2
75
75
  end
76
76
 
77
77
  def load(path)
78
- return {} unless File.exist?(path)
78
+ return nil unless File.exist?(path)
79
79
 
80
80
  content = IO.read(path)
81
81
 
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.1.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Irvine
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-15 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uuidtools
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.2.0
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: '0'
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.5.1
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: '0'
40
+ version: 2.5.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: beanstalk-client
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.1.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: '0'
54
+ version: 1.1.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: fluiddb
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.1.19
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'
68
+ version: 0.1.19
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: parse-cron
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.1.4
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'
82
+ version: 0.1.4
83
83
  description: A Ruby interpretation of NServiceBus
84
84
  email: guy@guyirvine.com
85
85
  executables:
@@ -93,6 +93,7 @@ extensions: []
93
93
  extra_rdoc_files: []
94
94
  files:
95
95
  - LICENSE
96
+ - README.md
96
97
  - bin/return_messages_to_source_queue
97
98
  - bin/rsb_ctl
98
99
  - bin/rservicebus2
@@ -103,6 +104,8 @@ files:
103
104
  - lib/rservicebus2.rb
104
105
  - lib/rservicebus2/agent.rb
105
106
  - lib/rservicebus2/appresource.rb
107
+ - lib/rservicebus2/appresource/awsdynamodb.rb
108
+ - lib/rservicebus2/appresource/awss3.rb
106
109
  - lib/rservicebus2/appresource/dir.rb
107
110
  - lib/rservicebus2/appresource/file.rb
108
111
  - lib/rservicebus2/appresource/fluiddb.rb
@@ -123,12 +126,14 @@ files:
123
126
  - lib/rservicebus2/message/subscription.rb
124
127
  - lib/rservicebus2/message/verboseoutput.rb
125
128
  - lib/rservicebus2/monitor.rb
129
+ - lib/rservicebus2/monitor/awss3.rb
126
130
  - lib/rservicebus2/monitor/dir.rb
127
131
  - lib/rservicebus2/monitor/dirnotifier.rb
128
132
  - lib/rservicebus2/monitor/message.rb
129
133
  - lib/rservicebus2/monitor/xmldir.rb
130
134
  - lib/rservicebus2/monitor_configure.rb
131
135
  - lib/rservicebus2/mq.rb
136
+ - lib/rservicebus2/mq/aws.rb
132
137
  - lib/rservicebus2/mq/beanstalk.rb
133
138
  - lib/rservicebus2/mq/file.rb
134
139
  - lib/rservicebus2/mq/redis.rb
@@ -162,7 +167,7 @@ homepage: http://rubygems.org/gems/rservicebus2
162
167
  licenses:
163
168
  - LGPL-3.0
164
169
  metadata: {}
165
- post_install_message:
170
+ post_install_message:
166
171
  rdoc_options: []
167
172
  require_paths:
168
173
  - lib
@@ -177,9 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
182
  - !ruby/object:Gem::Version
178
183
  version: '0'
179
184
  requirements: []
180
- rubyforge_project:
181
- rubygems_version: 2.5.2.1
182
- signing_key:
185
+ rubygems_version: 3.0.9
186
+ signing_key:
183
187
  specification_version: 4
184
188
  summary: RServiceBus
185
189
  test_files: []