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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a21f016929a276ed2b73ee8f10043328ebf1cf26
4
- data.tar.gz: 1e2e5ae7ce54dbdbec1c24982cded2cde0af0a84
3
+ metadata.gz: 4f364e75d49922ba5100b94dbf1bf29aa2dbf19a
4
+ data.tar.gz: d4940ce950c625ef94969c9b9af85733d593e242
5
5
  SHA512:
6
- metadata.gz: 0b8f3e54b41a66d20a0599273fad4b05584dea51c275deb9ae16a51d6d5dde5a7109d8d235ca7ee8891fe4300d20fd14846f2fe6a9205dab06c8e9af051d3e82
7
- data.tar.gz: 643b9a6c6090841da5dfe17288bff7f026ba5b8dbf2b900fa2ffa7f33d1a2ca995a292cd79ca7ef341e5c580259babf133328aad2dd5a19a3796b485505c26ad
6
+ metadata.gz: 7675472522cd69fb4e4d97b961f83e328def1ea7617efb3c6318a394889f5078fb1412e5343476ff69d00555f87da7a95d227708e14e1b2612ee70a095af4461
7
+ data.tar.gz: 829cf7f978b8f31c266edfe500c0e4cfca54ba85b715b245ce9ea8e7f83a2dc099606261799d712df199232f5775c38b3baa6e295ced1ba47d4837b02ea2c087
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## v0.2.0
4
+
5
+ * Add signal handling - trap SIGINT and SIGTERM and allow processing to happen for a options[:timeout] amount of time.
6
+ * Add a hook for instrumenting the consumer.
@@ -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
- bulk.each do |message|
21
- consume(parse(message))
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
@@ -1,3 +1,3 @@
1
1
  module SimpleKafkaConsumer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  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.1.1
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: 2015-09-29 00:00:00.000000000 Z
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: