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
- #leader_epoch ⇒ 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, leader_epoch: 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, leader_epoch: nil) ⇒ FetchedBatch
Returns a new instance of FetchedBatch.
25 26 27 28 29 30 31 32 |
# File 'lib/kafka/fetched_batch.rb', line 25 def initialize(topic:, partition:, highwater_mark_offset:, messages:, last_offset: nil, leader_epoch: nil) @topic = topic @partition = partition @highwater_mark_offset = highwater_mark_offset @messages = @last_offset = last_offset @leader_epoch = leader_epoch end |
Instance Attribute Details
#highwater_mark_offset ⇒ Integer (readonly)
Returns the offset of the most recent message in the partition.
20 21 22 |
# File 'lib/kafka/fetched_batch.rb', line 20 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 |
#leader_epoch ⇒ Integer (readonly)
17 18 19 |
# File 'lib/kafka/fetched_batch.rb', line 17 def leader_epoch @leader_epoch end |
#messages ⇒ Array<Kafka::FetchedMessage>
23 24 25 |
# File 'lib/kafka/fetched_batch.rb', line 23 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
34 35 36 |
# File 'lib/kafka/fetched_batch.rb', line 34 def empty? @messages.empty? end |
#first_offset ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/kafka/fetched_batch.rb', line 42 def first_offset if empty? nil else .first.offset end end |
#offset_lag ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/kafka/fetched_batch.rb', line 50 def offset_lag if empty? 0 else (highwater_mark_offset - 1) - last_offset end end |
#unknown_last_offset? ⇒ Boolean
38 39 40 |
# File 'lib/kafka/fetched_batch.rb', line 38 def unknown_last_offset? @last_offset.nil? end |