rservicebus2 0.2.0 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +50 -0
- data/lib/rservicebus2/appresource/awsdynamodb.rb +16 -0
- data/lib/rservicebus2/appresource/awss3.rb +16 -0
- data/lib/rservicebus2/appresource/awssqs.rb +25 -0
- data/lib/rservicebus2/appresource_configure.rb +9 -0
- data/lib/rservicebus2/monitor/awss3.rb +51 -0
- data/lib/rservicebus2/monitor/awssqs.rb +32 -0
- data/lib/rservicebus2/monitor_configure.rb +6 -0
- data/lib/rservicebus2/mq.rb +5 -2
- data/lib/rservicebus2/mq/aws.rb +85 -0
- metadata +38 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e5cab110a6dd40b7b80824e669ac85709bbec790bc948d5bdcb954a1b29184a5
|
4
|
+
data.tar.gz: 1bc1c569d5af1d01e79c69c0aef99781498bdac5aac13671fd4cd47a286aa2b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d2065fbd9b061cf17eca6f9c8eea5e8aa4663a9e68a27463417d511496d9e329d2d2d227bd7dc0b677f39e1a0f62b56292394f5b22217517f80f097698b2dc
|
7
|
+
data.tar.gz: 5637363459b8c27057d5d2cba9bbd99f558a3a25fbf4f0d0e2971d4e249e8ab58001f123fee08e82c4ee116c38d849ae9ecafd5452c4416f319277e2c91bbabb
|
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
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aws-sdk-dynamodb'
|
4
|
+
|
5
|
+
module RServiceBus2
|
6
|
+
# AppResourceAWSDynamoDb
|
7
|
+
class AppResourceAWSDynamoDb < AppResource
|
8
|
+
def connect(uri)
|
9
|
+
region = uri.host
|
10
|
+
|
11
|
+
Aws::DynamoDB::Client.new(region: region)
|
12
|
+
end
|
13
|
+
|
14
|
+
def finished; 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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'aws-sdk-sqs'
|
2
|
+
require 'aws-sdk-sts'
|
3
|
+
|
4
|
+
module RServiceBus2
|
5
|
+
# AppResourceAWSDynamoDb
|
6
|
+
class AppResourceAWSSQS < AppResource
|
7
|
+
def connect(uri)
|
8
|
+
queue_name = uri.path.sub('/', '')
|
9
|
+
|
10
|
+
region = uri.host
|
11
|
+
|
12
|
+
sts_client = Aws::STS::Client.new(region: region)
|
13
|
+
caller_identity_account = sts_client.get_caller_identity.account
|
14
|
+
|
15
|
+
queue_url = "https://sqs.#{region}.amazonaws.com/" \
|
16
|
+
"#{caller_identity_account}/#{queue_name}"
|
17
|
+
{
|
18
|
+
client: Aws::SQS::Client.new(region: region),
|
19
|
+
url: queue_url
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def finished; end
|
24
|
+
end
|
25
|
+
end
|
@@ -31,6 +31,15 @@ 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)
|
40
|
+
when 'awssqs'
|
41
|
+
require 'rservicebus2/appresource/awssqs'
|
42
|
+
rm.add k.sub('RSB_', ''), AppResourceAWSSQS.new(host, uri)
|
34
43
|
else
|
35
44
|
abort("Scheme, #{uri.scheme}, not recognised when configuring
|
36
45
|
app resource, #{k}=#{v}")
|
@@ -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
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'aws-sdk-sqs'
|
2
|
+
require 'aws-sdk-sts'
|
3
|
+
|
4
|
+
module RServiceBus2
|
5
|
+
# Monitor S3 Bucket for objects
|
6
|
+
class MonitorAWSSQS < Monitor
|
7
|
+
def connect(uri)
|
8
|
+
queue_name = uri.path.sub('/', '')
|
9
|
+
|
10
|
+
region = uri.host
|
11
|
+
|
12
|
+
sts_client = Aws::STS::Client.new(region: region)
|
13
|
+
caller_identity_account = sts_client.get_caller_identity.account
|
14
|
+
|
15
|
+
@queue_url = "https://sqs.#{region}.amazonaws.com/" +
|
16
|
+
"#{caller_identity_account}/#{queue_name}"
|
17
|
+
@sqs_client = Aws::SQS::Client.new(region: region)
|
18
|
+
end
|
19
|
+
|
20
|
+
def look
|
21
|
+
# TODO make max available as env variable
|
22
|
+
response = @sqs_client.receive_message(queue_url: @queue_url, max_number_of_messages: 1)
|
23
|
+
response.messages.each do |message|
|
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
|
+
})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -48,6 +48,12 @@ 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)
|
54
|
+
when 'awssqs'
|
55
|
+
require 'rservicebus2/monitor/awssqs'
|
56
|
+
monitor = MonitorAWSSQS.new(@host, name, uri)
|
51
57
|
when 'dirnotifier'
|
52
58
|
require 'rservicebus2/monitor/dirnotifier'
|
53
59
|
monitor = MonitorDirNotifier.new(@host, name, uri)
|
data/lib/rservicebus2/mq.rb
CHANGED
@@ -20,10 +20,13 @@ module RServiceBus2
|
|
20
20
|
mq = MQBeanstalk.new(uri)
|
21
21
|
when 'file'
|
22
22
|
require 'rservicebus2/mq/file'
|
23
|
-
|
23
|
+
mq = MQFile.new(uri)
|
24
24
|
when 'redis'
|
25
25
|
require 'rservicebus2/mq/redis'
|
26
|
-
|
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
|
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.
|
4
|
+
version: 0.2.7
|
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:
|
11
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: beanstalk-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
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:
|
26
|
+
version: 1.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: fluiddb
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
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:
|
40
|
+
version: 0.1.19
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
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:
|
54
|
+
version: 2.5.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: parse-cron
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
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:
|
68
|
+
version: 0.1.4
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: uuidtools
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
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:
|
82
|
+
version: 2.2.0
|
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,9 @@ 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
|
109
|
+
- lib/rservicebus2/appresource/awssqs.rb
|
106
110
|
- lib/rservicebus2/appresource/dir.rb
|
107
111
|
- lib/rservicebus2/appresource/file.rb
|
108
112
|
- lib/rservicebus2/appresource/fluiddb.rb
|
@@ -123,12 +127,15 @@ files:
|
|
123
127
|
- lib/rservicebus2/message/subscription.rb
|
124
128
|
- lib/rservicebus2/message/verboseoutput.rb
|
125
129
|
- lib/rservicebus2/monitor.rb
|
130
|
+
- lib/rservicebus2/monitor/awss3.rb
|
131
|
+
- lib/rservicebus2/monitor/awssqs.rb
|
126
132
|
- lib/rservicebus2/monitor/dir.rb
|
127
133
|
- lib/rservicebus2/monitor/dirnotifier.rb
|
128
134
|
- lib/rservicebus2/monitor/message.rb
|
129
135
|
- lib/rservicebus2/monitor/xmldir.rb
|
130
136
|
- lib/rservicebus2/monitor_configure.rb
|
131
137
|
- lib/rservicebus2/mq.rb
|
138
|
+
- lib/rservicebus2/mq/aws.rb
|
132
139
|
- lib/rservicebus2/mq/beanstalk.rb
|
133
140
|
- lib/rservicebus2/mq/file.rb
|
134
141
|
- lib/rservicebus2/mq/redis.rb
|
@@ -162,7 +169,7 @@ homepage: http://rubygems.org/gems/rservicebus2
|
|
162
169
|
licenses:
|
163
170
|
- LGPL-3.0
|
164
171
|
metadata: {}
|
165
|
-
post_install_message:
|
172
|
+
post_install_message:
|
166
173
|
rdoc_options: []
|
167
174
|
require_paths:
|
168
175
|
- lib
|
@@ -177,9 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
184
|
- !ruby/object:Gem::Version
|
178
185
|
version: '0'
|
179
186
|
requirements: []
|
180
|
-
|
181
|
-
|
182
|
-
signing_key:
|
187
|
+
rubygems_version: 3.0.9
|
188
|
+
signing_key:
|
183
189
|
specification_version: 4
|
184
190
|
summary: RServiceBus
|
185
191
|
test_files: []
|