aws-liam 0.0.4 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yaml +24 -19
- data/.gitignore +1 -0
- data/Gemfile.lock +15 -15
- data/README.md +93 -37
- data/docker-compose.localstack.yml +1 -1
- data/liam.gemspec +4 -4
- data/lib/generators/liam/templates/liam.yml +4 -0
- data/lib/liam.rb +15 -7
- data/lib/liam/common.rb +4 -4
- data/lib/liam/consumer.rb +4 -2
- data/lib/liam/exceptions/no_config_for_env_error.rb +9 -0
- data/lib/liam/message_processor.rb +13 -8
- data/lib/liam/processor.rb +13 -0
- data/lib/liam/producer.rb +18 -5
- data/lib/liam/version.rb +1 -1
- metadata +14 -13
- data/lib/.DS_Store +0 -0
- data/lib/liam/.DS_Store +0 -0
- data/lib/liam/exceptions/message_without_value_attribute_error.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58f7f42c10ec20d554b11e94099448bc7396e9fbeeeabc0908d4b27f3698dd0b
|
4
|
+
data.tar.gz: 615bd7386620f20e4368f2c1d2a98adaf1f3df64cf86debfa9802ef72df29371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8f61e0cd90d856adff8a55725d6837d768cab00ea7d6df49589b5264ef4a7a3546098fa1f72d1bea72689d4053367f6bab646364ef30d844aa7e70c883b6bb6
|
7
|
+
data.tar.gz: e969558c3ad2edcfd4d606787aafa1145071fb6a29e6db34627ef7862f73978b69052cca2a79ff7ee82b1f5e5c57fda9c0bc8fe063a6ce15af1da5a47a7f8dd4
|
data/.github/workflows/main.yaml
CHANGED
@@ -1,45 +1,50 @@
|
|
1
1
|
name: Main
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
inputs:
|
6
|
+
body:
|
7
|
+
default: ""
|
8
|
+
test:
|
9
|
+
default: false
|
10
|
+
pull_request_target:
|
4
11
|
|
5
12
|
jobs:
|
6
13
|
vm-job:
|
14
|
+
if: contains(toJson(github.event.commits), '[ci skip]') == false
|
7
15
|
runs-on: ubuntu-latest
|
8
16
|
strategy:
|
9
17
|
max-parallel: 4
|
10
18
|
|
11
19
|
steps:
|
12
|
-
- uses: actions/checkout@
|
20
|
+
- uses: actions/checkout@v2
|
13
21
|
|
14
|
-
- name: Set up
|
15
|
-
uses:
|
22
|
+
- name: Set up Ruby 2.7.2
|
23
|
+
uses: ruby/setup-ruby@v1
|
16
24
|
with:
|
17
|
-
|
25
|
+
ruby-version: 2.7.2
|
18
26
|
|
19
|
-
- name: Set up
|
20
|
-
uses:
|
27
|
+
- name: Set up aws-cli
|
28
|
+
uses: unfor19/install-aws-cli-action@v1
|
29
|
+
id: install-aws-cli
|
21
30
|
with:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
run: python -m pip install --upgrade pip
|
31
|
+
version: 2
|
32
|
+
run: aws --version
|
33
|
+
shell: bash
|
26
34
|
|
27
35
|
- name: Set up LocalStack
|
28
36
|
run: |
|
29
|
-
docker-compose -f docker-compose.localstack.yml up -d
|
30
|
-
curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
31
|
-
unzip -q awscliv2.zip
|
32
|
-
sudo ./aws/install
|
33
37
|
cp -avr .aws/ ~/
|
34
|
-
|
35
|
-
|
38
|
+
docker-compose -f docker-compose.localstack.yml up -d
|
39
|
+
while ! curl -s http://localhost:4566 > /dev/null; do echo waiting for localstack; sleep 3; done;
|
40
|
+
aws --endpoint-url=http://localhost:4566 sns create-topic --name liam_TestProducer
|
36
41
|
|
37
42
|
- name: Build
|
38
43
|
env:
|
39
44
|
RAILS_ENV: test
|
40
45
|
run: |
|
41
|
-
gem install bundler -v 1.
|
42
|
-
bundle
|
46
|
+
gem install bundler -v 2.1.4 -N
|
47
|
+
bundle _2.1.4_ install --jobs 4 --retry 3
|
43
48
|
|
44
49
|
- name: Run tests
|
45
50
|
run: |
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aws-liam (
|
4
|
+
aws-liam (0.0.9)
|
5
5
|
aws-sdk-sns (~> 1.21)
|
6
6
|
aws-sdk-sqs (~> 1.23, >= 1.23.1)
|
7
7
|
|
@@ -10,28 +10,28 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
addressable (2.7.0)
|
12
12
|
public_suffix (>= 2.0.2, < 5.0)
|
13
|
-
aws-eventstream (1.
|
14
|
-
aws-partitions (1.
|
15
|
-
aws-sdk-core (3.
|
16
|
-
aws-eventstream (~> 1
|
13
|
+
aws-eventstream (1.1.1)
|
14
|
+
aws-partitions (1.445.0)
|
15
|
+
aws-sdk-core (3.114.0)
|
16
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
17
17
|
aws-partitions (~> 1, >= 1.239.0)
|
18
18
|
aws-sigv4 (~> 1.1)
|
19
19
|
jmespath (~> 1.0)
|
20
|
-
aws-sdk-sns (1.
|
21
|
-
aws-sdk-core (~> 3, >= 3.
|
20
|
+
aws-sdk-sns (1.39.0)
|
21
|
+
aws-sdk-core (~> 3, >= 3.112.0)
|
22
22
|
aws-sigv4 (~> 1.1)
|
23
|
-
aws-sdk-sqs (1.
|
24
|
-
aws-sdk-core (~> 3, >= 3.
|
23
|
+
aws-sdk-sqs (1.38.0)
|
24
|
+
aws-sdk-core (~> 3, >= 3.112.0)
|
25
25
|
aws-sigv4 (~> 1.1)
|
26
|
-
aws-sigv4 (1.
|
27
|
-
aws-eventstream (~> 1
|
26
|
+
aws-sigv4 (1.2.3)
|
27
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
28
28
|
crack (0.4.3)
|
29
29
|
safe_yaml (~> 1.0.0)
|
30
30
|
diff-lcs (1.3)
|
31
31
|
hashdiff (1.0.0)
|
32
32
|
jmespath (1.4.0)
|
33
33
|
public_suffix (4.0.3)
|
34
|
-
rake (
|
34
|
+
rake (13.0.1)
|
35
35
|
rspec (3.9.0)
|
36
36
|
rspec-core (~> 3.9.0)
|
37
37
|
rspec-expectations (~> 3.9.0)
|
@@ -56,10 +56,10 @@ PLATFORMS
|
|
56
56
|
|
57
57
|
DEPENDENCIES
|
58
58
|
aws-liam!
|
59
|
-
bundler (~> 1.
|
60
|
-
rake (~>
|
59
|
+
bundler (~> 2.1.4)
|
60
|
+
rake (~> 13.0)
|
61
61
|
rspec (~> 3.9.0)
|
62
62
|
webmock (~> 3.7.6)
|
63
63
|
|
64
64
|
BUNDLED WITH
|
65
|
-
1.
|
65
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,29 +1,21 @@
|
|
1
|
-
#
|
1
|
+
# AWS Liam
|
2
2
|
|
3
|
-
Liam is
|
3
|
+
Liam is how we decided to call the implementation we did for our events based communication between different Ruby on Rails apps within our AWS infrastructure. We think it can be usefull for some of you that are struggling with this kind of issues too.
|
4
4
|
|
5
|
-
We called it Liam in honor to
|
6
|
-
|
7
|
-
![Image](https://pmctvline2.files.wordpress.com/2015/09/taken-prequel.jpg)
|
8
|
-
|
9
|
-
Liam sends an important message to Marko from Tropoja
|
5
|
+
We called it Liam in honor to Liam Neeson for so many reasons, being the most important this iconic scene when Bryan (Liam) called Marko and said:
|
10
6
|
|
11
7
|
> *I DONT KNOW WHO YOU ARE, I DON’T KNOW WHAT YOU WANT, BUT I WILL FIND YOU AND I WILL KILL YOU*...
|
12
8
|
|
13
|
-
We
|
14
|
-
But what happens when the App A needs data from App B and App B is down for a microsecond?
|
9
|
+
We wrote an [article at Medium](https://medium.com/archdaily-on-technology/microservices-events-aws-our-path-to-improve-communication-between-our-ruby-on-rails-apps-501b65e35fa3) where we explained the whole problem we had when we tried to use plain POST http requests between applications.
|
15
10
|
|
16
|
-
|
11
|
+
After implementing this solution in a couple of apps, Alexis and Sebastian decided to create this gem to encapsulate all the needed code.
|
17
12
|
|
18
|
-
With Liam we can send a message easily to SQS Service through SNS Service and process the message data through the consumer that Liam has
|
19
13
|
|
20
|
-
The
|
14
|
+
# The Gem
|
21
15
|
|
22
|
-
|
23
|
-
Amazon Simple Notification Service (SNS) [Documentation](https://docs.aws.amazon.com/sns/latest/dg/welcome.html)
|
16
|
+
With AWS Liam we can easily send an event (a message) from App A to App B using [SQS](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html) and [SNS](https://docs.aws.amazon.com/sns/latest/dg/welcome.html).
|
24
17
|
|
25
|
-
|
26
|
-
Amazon Simple Queue Service (SQS) [Documentation](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html)
|
18
|
+
The architecture you'll need is very simple: create as many SQS queues as applications you have (it's a good idea to call them `liam_NAME_OF_APPLICATION`, for example `liam_service_a` and `liam_service_b`) and as many SNS topics as events you want to work on (it's a good idea to call them `liam_NAME_OF_THE_EVENT`, for example `liam_ArticleCreated`, `liam_product_edited`, etc) and then subscribe the queues from the Services that need to consume the events from each topic as showed in the image bellow.
|
27
19
|
|
28
20
|
![Image](https://miro.medium.com/max/4000/1*DjlJlFUnT1UgviJzNJZ-xQ.png)
|
29
21
|
|
@@ -32,50 +24,114 @@ The first thing:
|
|
32
24
|
Add this line to your application's Gemfile:
|
33
25
|
|
34
26
|
```ruby
|
35
|
-
gem 'liam',
|
36
|
-
|
27
|
+
gem 'aws-liam', require: 'liam'
|
28
|
+
```
|
29
|
+
Then run a simple:
|
30
|
+
```
|
37
31
|
$ bundle install
|
38
32
|
```
|
39
33
|
|
40
|
-
|
34
|
+
Then execute this little rake tast that will generate some configuration files needed.
|
41
35
|
|
42
|
-
```ruby
|
43
|
-
$ bundle exec rails install:liam
|
44
36
|
```
|
37
|
+
$ bundle exec rails g liam:install
|
38
|
+
```
|
39
|
+
|
40
|
+
2 files will be created:
|
45
41
|
|
46
|
-
|
42
|
+
1. config/liam.yaml
|
43
|
+
2. lib/task/liam.rake
|
47
44
|
|
48
|
-
|
49
|
-
|
45
|
+
Go to the first one an setup your credentials and topic endpoints at AWS. You'll need to add here all the `events` you want to use later.
|
46
|
+
|
47
|
+
The second file corresponds to a rake task that will be needed only in the Services that want to be listening for new messages. If your Service will only publish messages (aka will be just a producer, not a consumer) then you can forget (or even delete) this rake task.
|
48
|
+
|
49
|
+
### Configuration
|
50
|
+
Liam will fail early if the key for your environment is missing on `config/liam.yaml`.
|
51
|
+
If you'd like to skip sending messages while you finish your setup, you can add the `skip: true` option.
|
52
|
+
|
53
|
+
For example:
|
54
|
+
|
55
|
+
```
|
56
|
+
staging:
|
57
|
+
<<: *default
|
58
|
+
skip: true
|
59
|
+
```
|
50
60
|
|
51
61
|
## Usage
|
52
62
|
|
53
|
-
|
63
|
+
### The Producer (Service A)
|
64
|
+
Every time something happens in Service A that needs to be shared to other applications (for example, an article was published) you need to put this simple three lines (basically create the article JSON, define where do you want to send the message and send the message):
|
54
65
|
|
55
66
|
```ruby
|
56
|
-
|
57
|
-
|
67
|
+
message = { id: id, title: title, created_at: created_at }
|
68
|
+
topic_name = 'liam_ArticleCreated'
|
58
69
|
|
59
|
-
|
70
|
+
Liam::Producer.message(topic: topic_name, message: message)
|
60
71
|
```
|
61
72
|
|
62
|
-
|
73
|
+
Now we have to define what `liam_ArticleCreated` means in terms of SNS. For this, we need to go to the `config/liam.yaml` file that was automatically generated by this gem and add this new event:
|
74
|
+
|
75
|
+
```yaml
|
76
|
+
...
|
77
|
+
events:
|
78
|
+
liam_ArticleCreated: "arn:aws:sns:us-east-1:xxxxxxxx:liam_ArticleCreated"
|
79
|
+
```
|
80
|
+
|
81
|
+
Of course, you need to create the topic called `liam_ArticleCreated` (and make sure that you have access to publish messages there from your Service A).
|
82
|
+
|
83
|
+
### The Consumer (Service B)
|
84
|
+
In the oher hand you will have to create a method in Service B that will consume the message received from Service A. At this point Class names is very important.
|
85
|
+
|
86
|
+
If you called the topic `liam_ArticleCreated` then you'll need to create a class called `ArticleCreated` within an `Liam` module at Service B, like the following example.
|
87
|
+
|
63
88
|
```ruby
|
64
|
-
|
89
|
+
# app/services/liam/article_created.rb
|
90
|
+
|
91
|
+
module Liam
|
92
|
+
class ArticleCreated
|
93
|
+
def initialize(message)
|
94
|
+
@message = message
|
95
|
+
end
|
96
|
+
|
97
|
+
def process
|
98
|
+
# Do all you need to do related to this article (at @message) that has been created at Service A
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
65
102
|
```
|
103
|
+
All of these files should live at `app/services/liam`.
|
104
|
+
|
105
|
+
Now you have to run the included task inside the Consumer App (make sure this task runs for ever):
|
106
|
+
|
107
|
+
```bash
|
108
|
+
$ bundle exec rake liam:consumer:start production
|
109
|
+
```
|
110
|
+
|
111
|
+
And that's it!
|
66
112
|
|
67
113
|
## Testing
|
68
|
-
Can you run the test easily executing
|
69
114
|
|
70
|
-
|
71
|
-
|
115
|
+
You can use the docker-compose.localstack.yml file to leave localstack running if you don't have it installed:
|
116
|
+
|
117
|
+
```bash
|
118
|
+
$ docker-compose -f docker-compose.localstack.yml up -d
|
72
119
|
```
|
73
120
|
|
74
|
-
|
121
|
+
Before running the test suite you must create the topic we use to test the gem functionality:
|
122
|
+
|
123
|
+
```bash
|
124
|
+
$ aws --endpoint-url=http://localhost:4566 sns create-topic --name liam_TestProducer
|
125
|
+
```
|
75
126
|
|
76
|
-
|
77
|
-
|
127
|
+
This is mandatory, otherwise you're going to receive an `Aws::SNS::Errors::NotFound: Topic does not exist` exception.
|
128
|
+
|
129
|
+
After that, you can run the suite with RSpec as usual:
|
130
|
+
|
131
|
+
```bash
|
132
|
+
$ bundle exec rspec
|
133
|
+
```
|
78
134
|
|
79
135
|
## Contributing
|
80
136
|
|
81
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
137
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/archdaily/aws-liam.
|
data/liam.gemspec
CHANGED
@@ -8,8 +8,8 @@ require 'liam/version'
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
9
|
spec.name = 'aws-liam'
|
10
10
|
spec.version = Liam::VERSION
|
11
|
-
spec.authors = ['alexismansilla', 'sebastian-palma']
|
12
|
-
spec.email = ['alexis.mansilla04@gmail.com', 'sebastianpalma@protonmail.com']
|
11
|
+
spec.authors = ['alexismansilla', 'sebastian-palma', 'luctus']
|
12
|
+
spec.email = ['alexis.mansilla04@gmail.com', 'sebastianpalma@protonmail.com', 'luctus@gmail.com']
|
13
13
|
spec.summary = 'AWS SQS+SNS middleware integration between Ruby microservices'
|
14
14
|
spec.description = 'Improved communication between our (Ruby on Rails) apps with AWS SNS - SQS'
|
15
15
|
spec.homepage = 'http://github.com/archdaily/aws-liam'
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
spec.add_dependency 'aws-sdk-sns', '~> 1.21'
|
20
20
|
spec.add_dependency 'aws-sdk-sqs', '~> 1.23', '>= 1.23.1'
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
22
|
-
spec.add_development_dependency 'rake', '~>
|
21
|
+
spec.add_development_dependency 'bundler', '~> 2.1.4'
|
22
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.9.0'
|
24
24
|
spec.add_development_dependency 'webmock', '~> 3.7.6'
|
25
25
|
end
|
data/lib/liam.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
Dir["lib/liam/exceptions/*.rb"].each {|file| load file }
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module Liam
|
5
|
+
autoload :Consumer, 'liam/consumer'
|
6
|
+
autoload :Processor, 'liam/processor'
|
7
|
+
autoload :Producer, 'liam/producer'
|
8
|
+
autoload :VERSION, 'liam/version'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_writer :logger
|
12
|
+
|
13
|
+
def logger
|
14
|
+
@logger ||= Logger.new($stdout).tap { |log| log.progname = self.name }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/liam/common.rb
CHANGED
@@ -8,10 +8,10 @@ module Liam
|
|
8
8
|
|
9
9
|
def client_options
|
10
10
|
{
|
11
|
-
access_key_id: env_credentials
|
12
|
-
endpoint: env_credentials
|
13
|
-
region: env_credentials
|
14
|
-
secret_access_key: env_credentials
|
11
|
+
access_key_id: env_credentials.dig('aws', 'access_key_id'),
|
12
|
+
endpoint: env_credentials.dig('aws', 'sns', 'endpoint'),
|
13
|
+
region: env_credentials.dig('aws', 'region'),
|
14
|
+
secret_access_key: env_credentials.dig('aws', 'secret_access_key')
|
15
15
|
}.compact
|
16
16
|
end
|
17
17
|
|
data/lib/liam/consumer.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'aws-sdk-sqs'
|
4
4
|
require 'liam/common'
|
5
5
|
require 'liam/message_processor'
|
6
|
+
require 'pp'
|
6
7
|
|
7
8
|
module Liam
|
8
9
|
class Consumer
|
@@ -21,10 +22,11 @@ module Liam
|
|
21
22
|
attr_reader :options
|
22
23
|
|
23
24
|
def execute
|
25
|
+
Liam.logger.info 'Consumer initialized'
|
24
26
|
poller.poll(poller_options) do |messages|
|
25
|
-
|
26
|
-
puts messages.join("\n")
|
27
|
+
Liam.logger.info "Total received messages: #{messages.size}"
|
27
28
|
messages.each do |message|
|
29
|
+
Liam.logger.info message
|
28
30
|
MessageProcessor.process(message)
|
29
31
|
end
|
30
32
|
end
|
@@ -13,7 +13,7 @@ module Liam
|
|
13
13
|
|
14
14
|
def self.process(message)
|
15
15
|
raise UnexpectedMessageError, message unless message.is_a?(Aws::SQS::Types::Message)
|
16
|
-
|
16
|
+
Liam.logger.info 'Processing...'
|
17
17
|
|
18
18
|
new(message).send(:process)
|
19
19
|
end
|
@@ -23,26 +23,31 @@ module Liam
|
|
23
23
|
attr_reader :message
|
24
24
|
|
25
25
|
private(*def_delegator(:message, :body))
|
26
|
+
private(*def_delegator(:message, :message_attributes))
|
26
27
|
private(*def_delegator(:processor, :process))
|
27
28
|
|
28
|
-
def
|
29
|
+
def parsed_body
|
29
30
|
JSON.parse(body)
|
30
31
|
end
|
31
32
|
|
33
|
+
def parsed_message
|
34
|
+
JSON.parse(parsed_body['Message'])
|
35
|
+
end
|
36
|
+
|
32
37
|
def processor
|
33
38
|
Object.const_get(message_topic_name).new(parsed_message)
|
34
39
|
rescue NameError => e
|
35
40
|
raise UninitializedMessageProcessorError, e
|
36
41
|
end
|
37
42
|
|
38
|
-
def
|
39
|
-
|
43
|
+
def topic_arn
|
44
|
+
return '' unless parsed_body.is_a?(Hash)
|
45
|
+
|
46
|
+
parsed_body['TopicArn'] || ''
|
40
47
|
end
|
41
48
|
|
42
|
-
def
|
43
|
-
|
44
|
-
raise MessageWithoutValueAttributeError unless value
|
45
|
-
end
|
49
|
+
def message_topic_name
|
50
|
+
topic_arn.split(':').last.sub('_', '::').gsub(/(?<=^)(.*)(?=::)/, &:capitalize)
|
46
51
|
end
|
47
52
|
end
|
48
53
|
end
|
data/lib/liam/producer.rb
CHANGED
@@ -2,26 +2,29 @@
|
|
2
2
|
|
3
3
|
require 'aws-sdk-sns'
|
4
4
|
require 'forwardable'
|
5
|
+
require 'liam/common'
|
5
6
|
|
6
7
|
module Liam
|
7
8
|
class Producer
|
8
9
|
DEFAULT_SUBJECT = 'liam message'
|
9
10
|
UNSUPPORTED_MESSAGE_ERROR = 'Unsupported message argument'
|
10
11
|
UNSUPPORTED_TOPIC_ERROR = 'Unsupported topic argument'
|
12
|
+
SKIPPED_MESSAGE = 'The message was skipped by the configuration of the environment'
|
13
|
+
|
11
14
|
private_constant :DEFAULT_SUBJECT
|
12
15
|
|
13
16
|
include Common
|
14
17
|
|
15
18
|
extend Forwardable
|
16
19
|
|
17
|
-
def initialize(message:, options: {}
|
20
|
+
def initialize(message:, topic:, options: {})
|
18
21
|
@message = message
|
19
|
-
@options = options
|
20
22
|
@topic = topic
|
23
|
+
@options = options
|
21
24
|
end
|
22
25
|
|
23
|
-
def self.message(
|
24
|
-
new(
|
26
|
+
def self.message(**args)
|
27
|
+
new(**args).send(:execute)
|
25
28
|
end
|
26
29
|
|
27
30
|
private
|
@@ -31,10 +34,12 @@ module Liam
|
|
31
34
|
attr_reader :topic, :message, :options
|
32
35
|
|
33
36
|
def execute
|
37
|
+
raise NoConfigForEnvError unless valid_config?
|
38
|
+
return SKIPPED_MESSAGE if skipped?
|
34
39
|
return UNSUPPORTED_TOPIC_ERROR unless supported_topic?
|
35
40
|
return UNSUPPORTED_MESSAGE_ERROR unless message.is_a?(Hash)
|
36
41
|
|
37
|
-
|
42
|
+
Liam.logger.info "Publishing message: #{message}"
|
38
43
|
Aws::SNS::Client.new(client_options).publish(
|
39
44
|
topic_arn: topic_arn,
|
40
45
|
message: message.to_json,
|
@@ -57,6 +62,14 @@ module Liam
|
|
57
62
|
topics[topic]
|
58
63
|
end
|
59
64
|
|
65
|
+
def valid_config?
|
66
|
+
env_credentials && !env_credentials.empty?
|
67
|
+
end
|
68
|
+
|
69
|
+
def skipped?
|
70
|
+
!!env_credentials['skip']
|
71
|
+
end
|
72
|
+
|
60
73
|
def topics
|
61
74
|
@topics ||= env_credentials['events']
|
62
75
|
end
|
data/lib/liam/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-liam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alexismansilla
|
8
8
|
- sebastian-palma
|
9
|
-
|
9
|
+
- luctus
|
10
|
+
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2021-04-20 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: aws-sdk-sns
|
@@ -51,28 +52,28 @@ dependencies:
|
|
51
52
|
requirements:
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
+
version: 2.1.4
|
55
56
|
type: :development
|
56
57
|
prerelease: false
|
57
58
|
version_requirements: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
60
|
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
+
version: 2.1.4
|
62
63
|
- !ruby/object:Gem::Dependency
|
63
64
|
name: rake
|
64
65
|
requirement: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
67
|
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
+
version: '13.0'
|
69
70
|
type: :development
|
70
71
|
prerelease: false
|
71
72
|
version_requirements: !ruby/object:Gem::Requirement
|
72
73
|
requirements:
|
73
74
|
- - "~>"
|
74
75
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
76
|
+
version: '13.0'
|
76
77
|
- !ruby/object:Gem::Dependency
|
77
78
|
name: rspec
|
78
79
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +107,7 @@ description: Improved communication between our (Ruby on Rails) apps with AWS SN
|
|
106
107
|
email:
|
107
108
|
- alexis.mansilla04@gmail.com
|
108
109
|
- sebastianpalma@protonmail.com
|
110
|
+
- luctus@gmail.com
|
109
111
|
executables: []
|
110
112
|
extensions: []
|
111
113
|
extra_rdoc_files: []
|
@@ -125,26 +127,25 @@ files:
|
|
125
127
|
- bin/setup
|
126
128
|
- docker-compose.localstack.yml
|
127
129
|
- liam.gemspec
|
128
|
-
- lib/.DS_Store
|
129
130
|
- lib/generators/liam/install_generator.rb
|
130
131
|
- lib/generators/liam/templates/liam.rake
|
131
132
|
- lib/generators/liam/templates/liam.yml
|
132
133
|
- lib/liam.rb
|
133
|
-
- lib/liam/.DS_Store
|
134
134
|
- lib/liam/common.rb
|
135
135
|
- lib/liam/consumer.rb
|
136
|
-
- lib/liam/exceptions/
|
136
|
+
- lib/liam/exceptions/no_config_for_env_error.rb
|
137
137
|
- lib/liam/exceptions/no_topics_in_config_file_error.rb
|
138
138
|
- lib/liam/exceptions/unexpected_message_error.rb
|
139
139
|
- lib/liam/exceptions/uninitialized_message_processor_error.rb
|
140
140
|
- lib/liam/message_processor.rb
|
141
|
+
- lib/liam/processor.rb
|
141
142
|
- lib/liam/producer.rb
|
142
143
|
- lib/liam/version.rb
|
143
144
|
homepage: http://github.com/archdaily/aws-liam
|
144
145
|
licenses:
|
145
146
|
- MIT
|
146
147
|
metadata: {}
|
147
|
-
post_install_message:
|
148
|
+
post_install_message:
|
148
149
|
rdoc_options: []
|
149
150
|
require_paths:
|
150
151
|
- lib
|
@@ -159,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
160
|
- !ruby/object:Gem::Version
|
160
161
|
version: '0'
|
161
162
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
163
|
-
signing_key:
|
163
|
+
rubygems_version: 3.2.15
|
164
|
+
signing_key:
|
164
165
|
specification_version: 4
|
165
166
|
summary: AWS SQS+SNS middleware integration between Ruby microservices
|
166
167
|
test_files: []
|
data/lib/.DS_Store
DELETED
Binary file
|
data/lib/liam/.DS_Store
DELETED
Binary file
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Liam
|
4
|
-
class MessageWithoutValueAttributeError < StandardError
|
5
|
-
def initialize
|
6
|
-
super(
|
7
|
-
<<~MSG.gsub(/\n/, '')
|
8
|
-
Expected to get a message attribute value to initialize the class to process
|
9
|
-
this message, but the value received is invalid.
|
10
|
-
MSG
|
11
|
-
)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|