simple_kafka_consumer 0.1.1 → 0.2.0
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/CHANGELOG.md +6 -0
- data/lib/simple_kafka_consumer/consumer.rb +28 -7
- data/lib/simple_kafka_consumer/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4f364e75d49922ba5100b94dbf1bf29aa2dbf19a
         | 
| 4 | 
            +
              data.tar.gz: d4940ce950c625ef94969c9b9af85733d593e242
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7675472522cd69fb4e4d97b961f83e328def1ea7617efb3c6318a394889f5078fb1412e5343476ff69d00555f87da7a95d227708e14e1b2612ee70a095af4461
         | 
| 7 | 
            +
              data.tar.gz: 829cf7f978b8f31c266edfe500c0e4cfca54ba85b715b245ce9ea8e7f83a2dc099606261799d712df199232f5775c38b3baa6e295ced1ba47d4837b02ea2c087
         | 
    
        data/CHANGELOG.md
    ADDED
    
    
| @@ -1,25 +1,36 @@ | |
| 1 1 | 
             
            module SimpleKafkaConsumer
         | 
| 2 | 
            -
              class Consumer | 
| 2 | 
            +
              class Consumer
         | 
| 3 3 | 
             
                class_attribute :group_name, :topic_name
         | 
| 4 | 
            +
             | 
| 4 5 | 
             
                attr_reader :consumer, :logger
         | 
| 5 6 | 
             
                def initialize(kafka_servers, zookeeper_servers, options = {})
         | 
| 6 7 | 
             
                  @logger = options.delete(:logger)
         | 
| 8 | 
            +
                  timeout_length = options.delete(:timeout) || 5
         | 
| 7 9 | 
             
                  @consumer = Poseidon::ConsumerGroup.new(
         | 
| 8 | 
            -
                    group_name, | 
| 9 | 
            -
                    kafka_servers, | 
| 10 | 
            -
                    zookeeper_servers, | 
| 10 | 
            +
                    group_name,
         | 
| 11 | 
            +
                    kafka_servers,
         | 
| 12 | 
            +
                    zookeeper_servers,
         | 
| 11 13 | 
             
                    topic_name,
         | 
| 12 14 | 
             
                    options
         | 
| 13 15 | 
             
                  )
         | 
| 16 | 
            +
                  %w(INT TERM).each do |signal|
         | 
| 17 | 
            +
                    Signal.trap(signal) do
         | 
| 18 | 
            +
                      @terminated = true
         | 
| 19 | 
            +
                      @timeout = timeout_length
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
                  end
         | 
| 14 22 | 
             
                end
         | 
| 15 23 |  | 
| 16 24 | 
             
                def run
         | 
| 17 25 | 
             
                  debug "partitions: #{consumer.partitions}"
         | 
| 18 26 | 
             
                  debug "claimed: #{consumer.claimed}"
         | 
| 19 27 | 
             
                  consumer.fetch_loop do |partition, bulk|
         | 
| 20 | 
            -
                     | 
| 21 | 
            -
                       | 
| 28 | 
            +
                    Timeout.timeout(@timeout) do
         | 
| 29 | 
            +
                      bulk.each do |message|
         | 
| 30 | 
            +
                        process(parse(message))
         | 
| 31 | 
            +
                      end
         | 
| 22 32 | 
             
                    end
         | 
| 33 | 
            +
                    break if @terminated
         | 
| 23 34 | 
             
                  end
         | 
| 24 35 | 
             
                rescue ZK::Exceptions::OperationTimeOut => e
         | 
| 25 36 | 
             
                  log e.message
         | 
| @@ -45,5 +56,15 @@ module SimpleKafkaConsumer | |
| 45 56 | 
             
                def consume(message)
         | 
| 46 57 | 
             
                  puts "doing nothing"
         | 
| 47 58 | 
             
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                def process(message)
         | 
| 61 | 
            +
                  instrumenter(message) do
         | 
| 62 | 
            +
                    consume(message)
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def instrumenter(message)
         | 
| 67 | 
            +
                  yield
         | 
| 68 | 
            +
                end
         | 
| 48 69 | 
             
              end
         | 
| 49 | 
            -
            end
         | 
| 70 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: simple_kafka_consumer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jeff Ching
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2016-12-29 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -88,6 +88,7 @@ extensions: [] | |
| 88 88 | 
             
            extra_rdoc_files: []
         | 
| 89 89 | 
             
            files:
         | 
| 90 90 | 
             
            - ".gitignore"
         | 
| 91 | 
            +
            - CHANGELOG.md
         | 
| 91 92 | 
             
            - Gemfile
         | 
| 92 93 | 
             
            - LICENSE.txt
         | 
| 93 94 | 
             
            - README.md
         | 
| @@ -121,4 +122,3 @@ signing_key: | |
| 121 122 | 
             
            specification_version: 4
         | 
| 122 123 | 
             
            summary: Write Kafka consumers in a model with retry
         | 
| 123 124 | 
             
            test_files: []
         | 
| 124 | 
            -
            has_rdoc: 
         |