Class: Kafka::FetchedBatch

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/fetched_batch.rb

Overview

An ordered sequence of messages fetched from a Kafka partition.

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = messages
  @last_offset = last_offset
  @leader_epoch = leader_epoch
end

Instance Attribute Details

#highwater_mark_offsetInteger (readonly)

Returns the offset of the most recent message in the partition.

Returns:

  • (Integer)

    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_offsetInteger (readonly)

Returns:

  • (Integer)


14
15
16
# File 'lib/kafka/fetched_batch.rb', line 14

def last_offset
  @last_offset
end

#leader_epochInteger (readonly)

Returns:

  • (Integer)


17
18
19
# File 'lib/kafka/fetched_batch.rb', line 17

def leader_epoch
  @leader_epoch
end

#messagesArray<Kafka::FetchedMessage>

Returns:



23
24
25
# File 'lib/kafka/fetched_batch.rb', line 23

def messages
  @messages
end

#partitionInteger (readonly)

Returns:

  • (Integer)


11
12
13
# File 'lib/kafka/fetched_batch.rb', line 11

def partition
  @partition
end

#topicString (readonly)

Returns:

  • (String)


8
9
10
# File 'lib/kafka/fetched_batch.rb', line 8

def topic
  @topic
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/kafka/fetched_batch.rb', line 34

def empty?
  @messages.empty?
end

#first_offsetObject



42
43
44
45
46
47
48
# File 'lib/kafka/fetched_batch.rb', line 42

def first_offset
  if empty?
    nil
  else
    messages.first.offset
  end
end

#offset_lagObject



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

Returns:

  • (Boolean)


38
39
40
# File 'lib/kafka/fetched_batch.rb', line 38

def unknown_last_offset?
  @last_offset.nil?
end