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.
- #messages ⇒ Array<Kafka::FetchedMessage> readonly
- #partition ⇒ Integer readonly
- #topic ⇒ String readonly
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #first_offset ⇒ Object
-
#initialize(topic:, partition:, highwater_mark_offset:, messages:) ⇒ FetchedBatch
constructor
A new instance of FetchedBatch.
- #last_offset ⇒ Object
- #offset_lag ⇒ Object
Constructor Details
#initialize(topic:, partition:, highwater_mark_offset:, messages:) ⇒ FetchedBatch
Returns a new instance of FetchedBatch.
17 18 19 20 21 22 |
# File 'lib/kafka/fetched_batch.rb', line 17 def initialize(topic:, partition:, highwater_mark_offset:, messages:) @topic = topic @partition = partition @highwater_mark_offset = highwater_mark_offset @messages = end |
Instance Attribute Details
#highwater_mark_offset ⇒ Integer (readonly)
Returns the offset of the most recent message in the partition.
12 13 14 |
# File 'lib/kafka/fetched_batch.rb', line 12 def highwater_mark_offset @highwater_mark_offset end |
#messages ⇒ Array<Kafka::FetchedMessage> (readonly)
15 16 17 |
# File 'lib/kafka/fetched_batch.rb', line 15 def @messages end |
#partition ⇒ Integer (readonly)
9 10 11 |
# File 'lib/kafka/fetched_batch.rb', line 9 def partition @partition end |
#topic ⇒ String (readonly)
6 7 8 |
# File 'lib/kafka/fetched_batch.rb', line 6 def topic @topic end |
Instance Method Details
#empty? ⇒ Boolean
24 25 26 |
# File 'lib/kafka/fetched_batch.rb', line 24 def empty? @messages.empty? end |
#first_offset ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/kafka/fetched_batch.rb', line 28 def first_offset if empty? nil else .first.offset end end |
#last_offset ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/kafka/fetched_batch.rb', line 36 def last_offset if empty? highwater_mark_offset - 1 else .last.offset end end |
#offset_lag ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/kafka/fetched_batch.rb', line 44 def offset_lag if empty? 0 else (highwater_mark_offset - 1) - last_offset end end |