aws-liam 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/main.yaml +22 -18
- data/.gitignore +1 -0
- data/Gemfile.lock +11 -11
- data/README.md +32 -4
- data/docker-compose.localstack.yml +1 -1
- data/lib/generators/liam/templates/liam.yml +4 -0
- data/lib/liam.rb +6 -8
- data/lib/liam/common.rb +1 -3
- data/lib/liam/exceptions/no_config_for_env_error.rb +9 -0
- data/lib/liam/producer.rb +18 -7
- data/lib/liam/version.rb +1 -1
- metadata +7 -8
- data/lib/.DS_Store +0 -0
- data/lib/liam/.DS_Store +0 -0
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,6 +1,13 @@
|
|
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:
|
@@ -10,36 +17,33 @@ jobs:
|
|
10
17
|
max-parallel: 4
|
11
18
|
|
12
19
|
steps:
|
13
|
-
- uses: actions/checkout@
|
20
|
+
- uses: actions/checkout@v2
|
14
21
|
|
15
|
-
- name: Set up
|
16
|
-
uses:
|
22
|
+
- name: Set up Ruby 2.7.2
|
23
|
+
uses: ruby/setup-ruby@v1
|
17
24
|
with:
|
18
|
-
|
25
|
+
ruby-version: 2.7.2
|
19
26
|
|
20
|
-
- name: Set up
|
21
|
-
uses:
|
27
|
+
- name: Set up aws-cli
|
28
|
+
uses: unfor19/install-aws-cli-action@v1
|
29
|
+
id: install-aws-cli
|
22
30
|
with:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
run: python -m pip install --upgrade pip
|
31
|
+
version: 2
|
32
|
+
run: aws --version
|
33
|
+
shell: bash
|
27
34
|
|
28
35
|
- name: Set up LocalStack
|
29
36
|
run: |
|
30
|
-
docker-compose -f docker-compose.localstack.yml up -d
|
31
|
-
curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
32
|
-
unzip -q awscliv2.zip
|
33
|
-
sudo ./aws/install
|
34
37
|
cp -avr .aws/ ~/
|
35
|
-
|
36
|
-
|
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
|
37
41
|
|
38
42
|
- name: Build
|
39
43
|
env:
|
40
44
|
RAILS_ENV: test
|
41
45
|
run: |
|
42
|
-
gem install bundler -v 2.1.4
|
46
|
+
gem install bundler -v 2.1.4 -N
|
43
47
|
bundle _2.1.4_ install --jobs 4 --retry 3
|
44
48
|
|
45
49
|
- name: Run tests
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aws-liam (0.0.
|
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,21 +10,21 @@ 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)
|
data/README.md
CHANGED
@@ -4,8 +4,6 @@ Liam is how we decided to call the implementation we did for our events based co
|
|
4
4
|
|
5
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:
|
6
6
|
|
7
|
-

|
8
|
-
|
9
7
|
> *I DONT KNOW WHO YOU ARE, I DON’T KNOW WHAT YOU WANT, BUT I WILL FIND YOU AND I WILL KILL YOU*...
|
10
8
|
|
11
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.
|
@@ -44,7 +42,21 @@ Then execute this little rake tast that will generate some configuration files n
|
|
44
42
|
1. config/liam.yaml
|
45
43
|
2. lib/task/liam.rake
|
46
44
|
|
47
|
-
Go to the first one an setup your credentials and
|
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
|
+
```
|
48
60
|
|
49
61
|
## Usage
|
50
62
|
|
@@ -58,6 +70,16 @@ topic_name = 'liam_ArticleCreated'
|
|
58
70
|
Liam::Producer.message(topic: topic_name, message: message)
|
59
71
|
```
|
60
72
|
|
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
|
+
|
61
83
|
### The Consumer (Service B)
|
62
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.
|
63
85
|
|
@@ -90,10 +112,16 @@ And that's it!
|
|
90
112
|
|
91
113
|
## Testing
|
92
114
|
|
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
|
119
|
+
```
|
120
|
+
|
93
121
|
Before running the test suite you must create the topic we use to test the gem functionality:
|
94
122
|
|
95
123
|
```bash
|
96
|
-
$ aws --endpoint-url=http://localhost:
|
124
|
+
$ aws --endpoint-url=http://localhost:4566 sns create-topic --name liam_TestProducer
|
97
125
|
```
|
98
126
|
|
99
127
|
This is mandatory, otherwise you're going to receive an `Aws::SNS::Errors::NotFound: Topic does not exist` exception.
|
data/lib/liam.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'liam/version'
|
4
|
-
require 'liam/consumer'
|
5
|
-
require 'liam/processor'
|
6
|
-
require 'liam/producer'
|
7
|
-
require 'liam/exceptions/uninitialized_message_processor_error'
|
8
|
-
require 'liam/exceptions/no_topics_in_config_file_error'
|
9
|
-
require 'liam/exceptions/unexpected_message_error'
|
2
|
+
Dir["lib/liam/exceptions/*.rb"].each {|file| load file }
|
10
3
|
|
11
4
|
module Liam
|
5
|
+
autoload :Consumer, 'liam/consumer'
|
6
|
+
autoload :Processor, 'liam/processor'
|
7
|
+
autoload :Producer, 'liam/producer'
|
8
|
+
autoload :VERSION, 'liam/version'
|
9
|
+
|
12
10
|
class << self
|
13
11
|
attr_writer :logger
|
14
12
|
|
data/lib/liam/common.rb
CHANGED
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,6 +34,8 @@ 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
|
|
@@ -57,10 +62,16 @@ module Liam
|
|
57
62
|
topics[topic]
|
58
63
|
end
|
59
64
|
|
60
|
-
def
|
61
|
-
|
65
|
+
def valid_config?
|
66
|
+
env_credentials && !env_credentials.empty?
|
67
|
+
end
|
68
|
+
|
69
|
+
def skipped?
|
70
|
+
!!env_credentials['skip']
|
71
|
+
end
|
62
72
|
|
63
|
-
|
73
|
+
def topics
|
74
|
+
@topics ||= env_credentials['events']
|
64
75
|
end
|
65
76
|
end
|
66
77
|
end
|
data/lib/liam/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +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
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-04-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws-sdk-sns
|
@@ -127,14 +127,13 @@ files:
|
|
127
127
|
- bin/setup
|
128
128
|
- docker-compose.localstack.yml
|
129
129
|
- liam.gemspec
|
130
|
-
- lib/.DS_Store
|
131
130
|
- lib/generators/liam/install_generator.rb
|
132
131
|
- lib/generators/liam/templates/liam.rake
|
133
132
|
- lib/generators/liam/templates/liam.yml
|
134
133
|
- lib/liam.rb
|
135
|
-
- lib/liam/.DS_Store
|
136
134
|
- lib/liam/common.rb
|
137
135
|
- lib/liam/consumer.rb
|
136
|
+
- lib/liam/exceptions/no_config_for_env_error.rb
|
138
137
|
- lib/liam/exceptions/no_topics_in_config_file_error.rb
|
139
138
|
- lib/liam/exceptions/unexpected_message_error.rb
|
140
139
|
- lib/liam/exceptions/uninitialized_message_processor_error.rb
|
@@ -146,7 +145,7 @@ homepage: http://github.com/archdaily/aws-liam
|
|
146
145
|
licenses:
|
147
146
|
- MIT
|
148
147
|
metadata: {}
|
149
|
-
post_install_message:
|
148
|
+
post_install_message:
|
150
149
|
rdoc_options: []
|
151
150
|
require_paths:
|
152
151
|
- lib
|
@@ -161,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
160
|
- !ruby/object:Gem::Version
|
162
161
|
version: '0'
|
163
162
|
requirements: []
|
164
|
-
rubygems_version: 3.
|
165
|
-
signing_key:
|
163
|
+
rubygems_version: 3.2.15
|
164
|
+
signing_key:
|
166
165
|
specification_version: 4
|
167
166
|
summary: AWS SQS+SNS middleware integration between Ruby microservices
|
168
167
|
test_files: []
|
data/lib/.DS_Store
DELETED
Binary file
|
data/lib/liam/.DS_Store
DELETED
Binary file
|