jruby-kafka 0.0.6 → 0.0.7

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: 757dfa77ab64d37ae0f8f29fa76fbc96d2f7c884
4
- data.tar.gz: 6c5c2c0165dd8953a130209e56749de4abd3e628
3
+ metadata.gz: 8b35dfb83e50e1362ee256245f71ca6cb6a1f8f6
4
+ data.tar.gz: b3150ea89bf69749f87b5a20734101126ddaf3b5
5
5
  SHA512:
6
- metadata.gz: 8bf3deeaf7977da88e0bec066beb759be538ec37cf5f3e00bda5ddb4b642905e46f4e938b98d3ca041b96686f5b24f9ab457cbee6b029a64254cd8db37c1fad6
7
- data.tar.gz: e93dac339e897f42cf82fa78042d134a57cd546174a5fd80856fadfa834673ab7690cadd1cf8d2bd88c781edeb16b4e0b8ac5813170fa7a7011eb17e747edab0
6
+ metadata.gz: 2c2a6ef16503adb6afe836526c8b052ec3ab6c8fa1e0956d65c622ab314d350b5316c94ea46ad642d657c774e77aef76d4ae9ee40ae057db9f9b5bff75d412df
7
+ data.tar.gz: 083ccc699375cfc9aba9acfa4ca618954a4b50a5e8ca3d4fb8255fa47105d1ada2571c37c38b51009c21fe627a32df133f79c2664dd4f1140e4ecac72102f692
@@ -14,24 +14,32 @@ class Kafka::Consumer
14
14
  @m_threadNumber
15
15
  @m_queue
16
16
 
17
- def initialize(a_stream, a_threadNumber, a_queue)
17
+ def initialize(a_stream, a_threadNumber, a_queue, a_bool_restart_on_exception, a_sleep_ms)
18
18
  @m_threadNumber = a_threadNumber
19
19
  @m_stream = a_stream
20
20
  @m_queue = a_queue
21
+ @m_restart_on_exception = a_bool_restart_on_exception
22
+ @m_sleep_ms = 1.0 / 1000.0 * Float(a_sleep_ms)
21
23
  end
22
24
 
23
25
  def run
24
26
  it = @m_stream.iterator()
25
- while it.hasNext()
26
- begin
27
+ begin
28
+ while it.hasNext()
27
29
  begin
28
30
  @m_queue << it.next().message()
29
- rescue ConsumerRebalanceFailedException => e
30
- raise KafkaError.new(e), "Got ConsumerRebalanceFailedException: #{e}"
31
- rescue ConsumerTimeoutException => e
32
- raise KafkaError.new(e), "Got ConsumerTimeoutException: #{e}"
33
31
  end
34
32
  end
33
+ rescue Exception => e
34
+ puts("#{self.class.name} caught exception: #{e.class.name}")
35
+ puts(e.message) if e.message != ''
36
+ puts(e.backtrace)
37
+ if @m_restart_on_exception
38
+ sleep(@m_sleep_ms)
39
+ retry
40
+ else
41
+ raise e
42
+ end
35
43
  end
36
44
  end
37
45
  end
@@ -28,7 +28,8 @@ class Kafka::Group
28
28
  # :topic_id => "topic" - REQUIRED: The topic id to consume on.
29
29
  # :reset_beginning => "from-beginning" - (optional) If the consumer does not already have an established offset
30
30
  # to consume from, start with the earliest message present in the log rather than the latest message.
31
- #
31
+ # :consumer_restart_on_error => "true" - (optional) Controls if consumer threads are to restart on caught exceptions.
32
+ # exceptions are logged.
32
33
  def initialize(options={})
33
34
  validate_required_arguments(options)
34
35
 
@@ -52,6 +53,8 @@ class Kafka::Group
52
53
  @fetch_wait_max_ms = '100'
53
54
  @refresh_leader_backoff_ms = '200'
54
55
  @consumer_timeout_ms = '-1'
56
+ @consumer_restart_on_error = "#{true}"
57
+ @consumer_restart_sleep_ms = '2000'
55
58
 
56
59
  if options[:zk_connect_timeout]
57
60
  @zk_connect_timeout = options[:zk_connect_timeout]
@@ -110,6 +113,15 @@ class Kafka::Group
110
113
  @consumer_timeout_ms = options[:consumer_timeout_ms]
111
114
  end
112
115
 
116
+ if options[:consumer_restart_on_error]
117
+ @consumer_restart_on_error = options[:consumer_restart_on_error]
118
+ end
119
+
120
+ if options[:consumer_restart_sleep_ms]
121
+ @consumer_restart_sleep_ms = options[:consumer_restart_sleep_ms]
122
+ end
123
+
124
+
113
125
  if options[:reset_beginning]
114
126
  if options[:reset_beginning] == 'from-beginning'
115
127
  @auto_offset_reset = 'smallest'
@@ -159,7 +171,7 @@ class Kafka::Group
159
171
 
160
172
  threadNumber = 0
161
173
  for stream in streams
162
- @executor_submit.call(Kafka::Consumer.new(stream, threadNumber, a_queue))
174
+ @executor_submit.call(Kafka::Consumer.new(stream, threadNumber, a_queue, @consumer_restart_on_error, @consumer_restart_sleep_ms))
163
175
  threadNumber += 1
164
176
  end
165
177
  @running = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Lawson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-28 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: this is primarily to be used as an interface for logstash
14
14
  email: