Class: Kafka::FetchedBatch
- Inherits:
-
Object
- Object
- Kafka::FetchedBatch
- Defined in:
- lib/kafka/fetched_batch.rb
Overview
An ordered sequence of messages fetched from a Kafka partition.
Instance Attribute Summary collapse
-
#highwater_mark_offset ⇒ Integer
readonly
The offset of the most recent message in the partition.
- #last_offset ⇒ Integer readonly
- #messages ⇒ Array<Kafka::FetchedMessage>
- #partition ⇒ Integer readonly
- #topic ⇒ String readonly
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #first_offset ⇒ Object
-
#initialize(topic:, partition:, highwater_mark_offset:, messages:, last_offset: nil) ⇒ FetchedBatch
constructor
A new instance of FetchedBatch.
- #offset_lag ⇒ Object
- #unknown_last_offset? ⇒ Boolean
Constructor Details
#initialize(topic:, partition:, highwater_mark_offset:, messages:, last_offset: nil) ⇒ FetchedBatch
Returns a new instance of FetchedBatch.
22 23 24 25 26 27 28 |
# File 'lib/kafka/fetched_batch.rb', line 22 def initialize(topic:, partition:, highwater_mark_offset:, messages:, last_offset: nil) @topic = topic @partition = partition @highwater_mark_offset = highwater_mark_offset @messages = @last_offset = last_offset end |
Instance Attribute Details
#highwater_mark_offset ⇒ Integer (readonly)
Returns the offset of the most recent message in the partition.
17 18 19 |
# File 'lib/kafka/fetched_batch.rb', line 17 def highwater_mark_offset @highwater_mark_offset end |
#last_offset ⇒ Integer (readonly)
14 15 16 |
# File 'lib/kafka/fetched_batch.rb', line 14 def last_offset @last_offset end |
#messages ⇒ Array<Kafka::FetchedMessage>
20 21 22 |
# File 'lib/kafka/fetched_batch.rb', line 20 def @messages end |
#partition ⇒ Integer (readonly)
11 12 13 |
# File 'lib/kafka/fetched_batch.rb', line 11 def partition @partition end |
#topic ⇒ String (readonly)
8 9 10 |
# File 'lib/kafka/fetched_batch.rb', line 8 def topic @topic end |
Instance Method Details
#empty? ⇒ Boolean
30 31 32 |
# File 'lib/kafka/fetched_batch.rb', line 30 def empty? @messages.empty? end |
#first_offset ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/kafka/fetched_batch.rb', line 38 def first_offset if empty? nil else .first.offset end end |
#offset_lag ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/kafka/fetched_batch.rb', line 46 def offset_lag if empty? 0 else (highwater_mark_offset - 1) - last_offset end end |
#unknown_last_offset? ⇒ Boolean
34 35 36 |
# File 'lib/kafka/fetched_batch.rb', line 34 def unknown_last_offset? @last_offset.nil? end |