aws-liam 0.0.7 → 0.0.8
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 +5 -5
- data/README.md +14 -10
- data/lib/liam.rb +11 -1
- data/lib/liam/common.rb +7 -5
- data/lib/liam/consumer.rb +3 -2
- data/lib/liam/message_processor.rb +6 -17
- data/lib/liam/processor.rb +13 -0
- data/lib/liam/producer.rb +1 -1
- data/lib/liam/version.rb +1 -1
- metadata +4 -5
- data/lib/liam/exceptions/message_without_value_attribute_error.rb +0 -14
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: cb56b9b9adaa264e64fd5a8e60171e279c52761f5a00cea30977a96396a47b74
         | 
| 4 | 
            +
              data.tar.gz: 86166f8802d24fd4aa93cda51d7606619658470fe3e66580b382acf89beb80f4
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
            -
             | 
| 56 | 
            -
             | 
| 55 | 
            +
            message    = { id: id, title: title, created_at: created_at }
         | 
| 56 | 
            +
            topic_name = 'liam_ArticleCreated'
         | 
| 57 57 |  | 
| 58 | 
            -
             | 
| 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 | 
            -
             | 
| 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 | 
            -
             | 
| 99 | 
            +
            This is mandatory, otherwise you're going to receive an `Aws::SNS::Errors::NotFound: Topic does not exist` exception.
         | 
| 99 100 |  | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 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 |  | 
    
        data/lib/liam.rb
    CHANGED
    
    | @@ -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
         | 
    
        data/lib/liam/common.rb
    CHANGED
    
    | @@ -8,15 +8,17 @@ 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 |  | 
| 18 18 | 
             
                def env_credentials
         | 
| 19 | 
            -
                  @env_credentials  | 
| 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
         | 
    
        data/lib/liam/consumer.rb
    CHANGED
    
    | @@ -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 | 
            -
                     | 
| 27 | 
            +
                    Liam.logger.info "Total received messages: #{messages.size}"
         | 
| 27 28 | 
             
                    messages.each do |message|
         | 
| 28 | 
            -
                       | 
| 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 | 
            -
                   | 
| 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  | 
| 44 | 
            -
                   | 
| 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 | 
            -
                   | 
| 46 | 
            +
                  parsed_body['TopicArn'] || ''
         | 
| 51 47 | 
             
                end
         | 
| 52 48 |  | 
| 53 | 
            -
                def  | 
| 54 | 
            -
                   | 
| 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
         | 
    
        data/lib/liam/producer.rb
    CHANGED
    
    | @@ -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 | 
            -
                   | 
| 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,
         | 
    
        data/lib/liam/version.rb
    CHANGED
    
    
    
        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. | 
| 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- | 
| 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 | 
            -
             | 
| 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
         |