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



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

def highwater_mark_offset
  @highwater_mark_offset
end

#messagesArray<Kafka::FetchedMessage> (readonly)

Returns:



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

def messages
  @messages
end

#partitionInteger (readonly)

Returns:

  • (Integer)


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

def partition
  @partition
end

#topicString (readonly)

Returns:

  • (String)


6
7
8
# File 'lib/kafka/fetched_batch.rb', line 6

def topic
  @topic
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @messages.empty?
end

#last_offsetObject



28
29
30
# File 'lib/kafka/fetched_batch.rb', line 28

def last_offset
  messages.last.offset
end

#offset_lagObject



32
33
34
35
36
37
38
# File 'lib/kafka/fetched_batch.rb', line 32

def offset_lag
  if empty?
    0
  else
    highwater_mark_offset - last_offset
  end
end