aws-liam 0.0.7 → 0.0.8

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: ca62555809a9e79275146771a80aa72f2d6bd595
4
- data.tar.gz: 86bcc1a6ae4cc503b9bf2d47454d38dacc90da4c
2
+ SHA256:
3
+ metadata.gz: cb56b9b9adaa264e64fd5a8e60171e279c52761f5a00cea30977a96396a47b74
4
+ data.tar.gz: 86166f8802d24fd4aa93cda51d7606619658470fe3e66580b382acf89beb80f4
5
5
  SHA512:
6
- metadata.gz: da4597e779ea8d6a0466865fed72ceddd3d166675f3d001c7d69c92b16c59ca9c9a41cbb1c300913fdd54a442c994f59a41a940ecf3471c306ca4413a744a949
7
- data.tar.gz: f853d341dd2468c6c304ed400e9b3c792c8463b24373eb64d6585d0e87f6e9adde2e9229d972d150504e0e697b7a40af07ca19c71cc548cb8037f2a1df6aabba
6
+ metadata.gz: 93f2c7b2277433830e3f37b3630f97040d5b7916efa5954386b3b664dc3b6f6a75124aefc043caa686aa07c733669fae6b912a81fdd9c111441b33f35caf6289
7
+ data.tar.gz: 4823392801ca44d27bc379286a3e41d7a5b6777b740fb61ef91da7c7bbc07a87513ba1991ef899050f7abdbd0b31c8304eb74fd557983ac9ef2576cc662a962d
data/README.md CHANGED
@@ -52,10 +52,10 @@ Go to the first one an setup your credentials and topics endpoints at AWS. The s
52
52
  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):
53
53
 
54
54
  ```ruby
55
- message = { id: id, title: title, created_at: created_at }
56
- topic_name = 'liam_ArticleCreated'
55
+ message = { id: id, title: title, created_at: created_at }
56
+ topic_name = 'liam_ArticleCreated'
57
57
 
58
- Liam::Producer.message(topic: topic_name, message: message)
58
+ Liam::Producer.message(topic: topic_name, message: message)
59
59
  ```
60
60
 
61
61
  ### The Consumer (Service B)
@@ -82,23 +82,27 @@ All of these files should live at `app/services/liam`.
82
82
 
83
83
  Now you have to run the included task inside the Consumer App (make sure this task runs for ever):
84
84
 
85
- ```
85
+ ```bash
86
86
  $ bundle exec rake liam:consumer:start production
87
87
  ```
88
88
 
89
89
  And that's it!
90
90
 
91
91
  ## Testing
92
- Can you run the test easily executing
93
92
 
94
- ```
95
- $ bundle exec rspec
93
+ Before running the test suite you must create the topic we use to test the gem functionality:
94
+
95
+ ```bash
96
+ $ aws --endpoint-url=http://localhost:4575 sns create-topic --name liam_TestProducer
96
97
  ```
97
98
 
98
- If you want to run all test successfully, we need the LocalStack daemon when sending a message
99
+ This is mandatory, otherwise you're going to receive an `Aws::SNS::Errors::NotFound: Topic does not exist` exception.
99
100
 
100
- ## Localstack Running
101
- TODO
101
+ After that, you can run the suite with RSpec as usual:
102
+
103
+ ```bash
104
+ $ bundle exec rspec
105
+ ```
102
106
 
103
107
  ## Contributing
104
108
 
@@ -2,8 +2,18 @@
2
2
 
3
3
  require 'liam/version'
4
4
  require 'liam/consumer'
5
+ require 'liam/processor'
5
6
  require 'liam/producer'
6
- require 'liam/exceptions/message_without_value_attribute_error'
7
7
  require 'liam/exceptions/uninitialized_message_processor_error'
8
8
  require 'liam/exceptions/no_topics_in_config_file_error'
9
9
  require 'liam/exceptions/unexpected_message_error'
10
+
11
+ module Liam
12
+ class << self
13
+ attr_writer :logger
14
+
15
+ def logger
16
+ @logger ||= Logger.new($stdout).tap { |log| log.progname = self.name }
17
+ end
18
+ end
19
+ end
@@ -8,15 +8,17 @@ module Liam
8
8
 
9
9
  def client_options
10
10
  {
11
- access_key_id: env_credentials['aws']['access_key_id'],
12
- endpoint: env_credentials['aws']['sns']['endpoint'],
13
- region: env_credentials['aws']['region'],
14
- secret_access_key: env_credentials['aws']['secret_access_key']
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
 
18
18
  def env_credentials
19
- @env_credentials ||= credentials[ENV['RAILS_ENV']]
19
+ return @env_credentials if defined?(@env_credentials)
20
+
21
+ @env_credentials = credentials[ENV['RAILS_ENV']]
20
22
  end
21
23
 
22
24
  def credentials
@@ -22,10 +22,11 @@ module Liam
22
22
  attr_reader :options
23
23
 
24
24
  def execute
25
+ Liam.logger.info 'Consumer initialized'
25
26
  poller.poll(poller_options) do |messages|
26
- puts "INFO -- [aws-liam] : ** Received messages: #{messages.size} ** --"
27
+ Liam.logger.info "Total received messages: #{messages.size}"
27
28
  messages.each do |message|
28
- pp message
29
+ Liam.logger.info message
29
30
  MessageProcessor.process(message)
30
31
  end
31
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
- puts "[aws-liam] Processing..."
16
+ Liam.logger.info 'Processing...'
17
17
 
18
18
  new(message).send(:process)
19
19
  end
@@ -40,25 +40,14 @@ module Liam
40
40
  raise UninitializedMessageProcessorError, e
41
41
  end
42
42
 
43
- def message_topic_name
44
- message_attribute_value.sub('_', '::').gsub(/(?<=^)(.*)(?=::)/, &:capitalize)
45
- end
46
-
47
- def message_attribute_value
48
- raise MessageWithoutValueAttributeError if value.nil? || value.empty?
43
+ def topic_arn
44
+ return '' unless parsed_body.is_a?(Hash)
49
45
 
50
- value
46
+ parsed_body['TopicArn'] || ''
51
47
  end
52
48
 
53
- def value
54
- return @value if defined?(@value)
55
-
56
- @value = begin
57
- return if parsed_body.nil? || parsed_body.empty?
58
-
59
- message_attributes['event_name']&.string_value ||
60
- parsed_body.dig('MessageAttributes', 'event_name', 'Value')
61
- end
49
+ def message_topic_name
50
+ topic_arn.split(':').last.sub('_', '::').gsub(/(?<=^)(.*)(?=::)/, &:capitalize)
62
51
  end
63
52
  end
64
53
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Liam
4
+ module Processor
5
+ def initialize(message)
6
+ @message = message
7
+ end
8
+
9
+ private
10
+
11
+ attr_reader :message
12
+ end
13
+ end
@@ -34,7 +34,7 @@ module Liam
34
34
  return UNSUPPORTED_TOPIC_ERROR unless supported_topic?
35
35
  return UNSUPPORTED_MESSAGE_ERROR unless message.is_a?(Hash)
36
36
 
37
- puts "INFO -- [aws-liam]: ** Publishing message: #{message} ** --"
37
+ Liam.logger.info "Publishing message: #{message}"
38
38
  Aws::SNS::Client.new(client_options).publish(
39
39
  topic_arn: topic_arn,
40
40
  message: message.to_json,
@@ -1,3 +1,3 @@
1
1
  module Liam
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-liam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - alexismansilla
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-04-07 00:00:00.000000000 Z
13
+ date: 2020-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk-sns
@@ -135,11 +135,11 @@ files:
135
135
  - lib/liam/.DS_Store
136
136
  - lib/liam/common.rb
137
137
  - lib/liam/consumer.rb
138
- - lib/liam/exceptions/message_without_value_attribute_error.rb
139
138
  - lib/liam/exceptions/no_topics_in_config_file_error.rb
140
139
  - lib/liam/exceptions/unexpected_message_error.rb
141
140
  - lib/liam/exceptions/uninitialized_message_processor_error.rb
142
141
  - lib/liam/message_processor.rb
142
+ - lib/liam/processor.rb
143
143
  - lib/liam/producer.rb
144
144
  - lib/liam/version.rb
145
145
  homepage: http://github.com/archdaily/aws-liam
@@ -161,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.5.2
164
+ rubygems_version: 3.1.2
166
165
  signing_key:
167
166
  specification_version: 4
168
167
  summary: AWS SQS+SNS middleware integration between Ruby microservices
@@ -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