Sha256: 05cd1479516fc8af1e6bd9ad7abe8751f118a1abdcfb90fd3dd52f75951112f5

Contents?: true

Size: 1 KB

Versions: 30

Compression:

Stored size: 1 KB

Contents

module Kafka

  # An ordered sequence of messages fetched from a Kafka partition.
  class FetchedBatch
    # @return [String]
    attr_reader :topic

    # @return [Integer]
    attr_reader :partition

    # @return [Integer] the offset of the most recent message in the partition.
    attr_reader :highwater_mark_offset

    # @return [Array<Kafka::FetchedMessage>]
    attr_reader :messages

    def initialize(topic:, partition:, highwater_mark_offset:, messages:)
      @topic = topic
      @partition = partition
      @highwater_mark_offset = highwater_mark_offset
      @messages = messages
    end

    def empty?
      @messages.empty?
    end

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

    def last_offset
      if empty?
        highwater_mark_offset - 1
      else
        messages.last.offset
      end
    end

    def offset_lag
      if empty?
        0
      else
        (highwater_mark_offset - 1) - last_offset
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
ruby-kafka-0.6.0.beta4 lib/kafka/fetched_batch.rb
ruby-kafka-0.6.0.beta3 lib/kafka/fetched_batch.rb
ruby-kafka-0.6.0.beta2 lib/kafka/fetched_batch.rb
ruby-kafka-0.6.0.beta1 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.5 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.4 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.4.beta1 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.3 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.2 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.2.beta3 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.2.beta2 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.2.beta1 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.1 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.1.beta2 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.1.beta1 lib/kafka/fetched_batch.rb
ruby-kafka-0.4.4 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.0 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.0.beta6 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.0.beta5 lib/kafka/fetched_batch.rb
ruby-kafka-0.5.0.beta4 lib/kafka/fetched_batch.rb