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) ⇒ 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 = messages
  @last_offset = last_offset
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.



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

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

#messagesArray<Kafka::FetchedMessage>

Returns:



20
21
22
# File 'lib/kafka/fetched_batch.rb', line 20

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)


30
31
32
# File 'lib/kafka/fetched_batch.rb', line 30

def empty?
  @messages.empty?
end

#first_offsetObject



38
39
40
41
42
43
44
# File 'lib/kafka/fetched_batch.rb', line 38

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

#offset_lagObject



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

Returns:

  • (Boolean)


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

def unknown_last_offset?
  @last_offset.nil?
end