ruby-kafka 0.3.14 → 0.3.15.beta1

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: 9464a030fbaaa71d6b6095fe7519787396afbc2d
4
- data.tar.gz: f432a7bf7401371251522b75980ff9116c8cb89e
3
+ metadata.gz: f737e31dc809145f5ea7d5d66d761df383103215
4
+ data.tar.gz: 82e1bb74dd93e01963c8ccff60ea4e26a27d24f3
5
5
  SHA512:
6
- metadata.gz: cbedf9f17a00f597700775919f396803f80a77cca6b33ef7c0217569a2c5d05c2f4aa6e834bb005c37b1eb090b3fb4ac994e5b3aef166bd7dc6df471c866d79b
7
- data.tar.gz: c9d7e0b9a37e2c081e3bbba5ba644997311b167900df4054df4e6204c456d1652fb022019662c4b3d58a86f1f56c660a0e52efefe52e5c5247ee905e3b8e97d9
6
+ metadata.gz: 5cca8d29dd690134e46833d3cd01e961c4c782c540f88472619edc4e9e9af6e273c5dbafbc5fd5df31856fce3f2550f2c0e3f1924372a86aa67cfbdb87120e7f
7
+ data.tar.gz: 269d7ff9dfbc342a8b942249889c55d8ddb9ca4a06e18003727537fd00dcda09a42e714626fa4045554de76c0a52fdafb3694b702c39446753016a1fa0cfba85
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ Changes and additions to the library will be listed here.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## v0.3.15.beta1
8
+
9
+ - Allow pausing consumption of a partition (#268).
10
+
7
11
  ## v0.3.14
8
12
 
9
13
  - Automatically recover from invalid consumer checkpoints.
data/lib/kafka.rb CHANGED
@@ -4,6 +4,19 @@ module Kafka
4
4
  class Error < StandardError
5
5
  end
6
6
 
7
+ # There was an error processing a message.
8
+ class ProcessingError < Error
9
+ attr_reader :topic, :partition, :offset
10
+
11
+ def initialize(topic, partition, offset)
12
+ @topic = topic
13
+ @partition = partition
14
+ @offset = offset
15
+
16
+ super()
17
+ end
18
+ end
19
+
7
20
  # Subclasses of this exception class map to an error code described in the
8
21
  # Kafka protocol specification.
9
22
  #
@@ -52,6 +52,9 @@ module Kafka
52
52
  @session_timeout = session_timeout
53
53
  @heartbeat = heartbeat
54
54
 
55
+ # A list of partitions that have been paused, per topic.
56
+ @paused_partitions = {}
57
+
55
58
  # Whether or not the consumer is currently consuming messages.
56
59
  @running = false
57
60
 
@@ -63,7 +66,7 @@ module Kafka
63
66
  #
64
67
  # Typically you either want to start reading messages from the very
65
68
  # beginning of the topic's partitions or you simply want to wait for new
66
- # messages to be written. In the former case, set `start_from_beginnign`
69
+ # messages to be written. In the former case, set `start_from_beginning`
67
70
  # true (the default); in the latter, set it to false.
68
71
  #
69
72
  # @param topic [String] the name of the topic to subscribe to.
@@ -91,6 +94,41 @@ module Kafka
91
94
  @running = false
92
95
  end
93
96
 
97
+ # Pause processing of a specific topic partition.
98
+ #
99
+ # When a specific message causes the processor code to fail, it can be a good
100
+ # idea to simply pause the partition until the error can be resolved, allowing
101
+ # the rest of the partitions to continue being processed.
102
+ #
103
+ # @param topic [String]
104
+ # @param partition [Integer]
105
+ # @return [nil]
106
+ def pause(topic, partition)
107
+ @paused_partitions[topic] ||= Set.new
108
+ @paused_partitions[topic] << partition
109
+ end
110
+
111
+ # Resume processing of a topic partition.
112
+ #
113
+ # @see #pause
114
+ # @param topic [String]
115
+ # @param partition [Integer]
116
+ # @return [nil]
117
+ def resume(topic, partition)
118
+ paused_partitions = @paused_partitions.fetch(topic, [])
119
+ paused_partitions.delete(partition)
120
+ end
121
+
122
+ # Whether the topic partition is currently paused.
123
+ #
124
+ # @see #pause
125
+ # @param topic [String]
126
+ # @param partition [Integer]
127
+ # @return [Boolean] true if the partition is paused, false otherwise.
128
+ def paused?(topic, partition)
129
+ @paused_partitions.fetch(topic, []).include?(partition)
130
+ end
131
+
94
132
  # Fetches and enumerates the messages in the topics that the consumer group
95
133
  # subscribes to.
96
134
  #
@@ -132,7 +170,7 @@ module Kafka
132
170
  backtrace = e.backtrace.join("\n")
133
171
  @logger.error "Exception raised when processing #{location} -- #{e.class}: #{e}\n#{backtrace}"
134
172
 
135
- raise
173
+ raise ProcessingError.new(message.topic, message.partition, message.offset)
136
174
  end
137
175
  end
138
176
 
@@ -274,9 +312,12 @@ module Kafka
274
312
  offset = @offset_manager.next_offset_for(topic, partition)
275
313
  max_bytes = @max_bytes.fetch(topic)
276
314
 
277
- @logger.debug "Fetching batch from #{topic}/#{partition} starting at offset #{offset}"
278
-
279
- operation.fetch_from_partition(topic, partition, offset: offset, max_bytes: max_bytes)
315
+ if paused?(topic, partition)
316
+ @logger.warn "Partition #{topic}/#{partition} is currently paused, skipping"
317
+ else
318
+ @logger.debug "Fetching batch from #{topic}/#{partition} starting at offset #{offset}"
319
+ operation.fetch_from_partition(topic, partition, offset: offset, max_bytes: max_bytes)
320
+ end
280
321
  end
281
322
  end
282
323
 
@@ -71,6 +71,7 @@ module Kafka
71
71
 
72
72
  def clear_offsets
73
73
  @processed_offsets.clear
74
+ @resolved_offsets.clear
74
75
 
75
76
  # Clear the cached commits from the brokers.
76
77
  @committed_offsets = nil
@@ -86,6 +87,7 @@ module Kafka
86
87
 
87
88
  # Clear the cached commits from the brokers.
88
89
  @committed_offsets = nil
90
+ @resolved_offsets.clear
89
91
  end
90
92
 
91
93
  private
data/lib/kafka/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kafka
2
- VERSION = "0.3.14"
2
+ VERSION = "0.3.15.beta1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -303,9 +303,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
303
  version: 2.1.0
304
304
  required_rubygems_version: !ruby/object:Gem::Requirement
305
305
  requirements:
306
- - - ">="
306
+ - - ">"
307
307
  - !ruby/object:Gem::Version
308
- version: '0'
308
+ version: 1.3.1
309
309
  requirements: []
310
310
  rubyforge_project:
311
311
  rubygems_version: 2.4.5.1