Class IncomingKafkaRecordBatchMetadata<K,T>

java.lang.Object
io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordBatchMetadata<K,T>
Type Parameters:
K - The record key type
T - The record payload type

public class IncomingKafkaRecordBatchMetadata<K,T> extends Object
Contains information about the batch of messages received from a channel backed by Kafka. Encapsulates underlying Kafka ConsumerRecords received from the consumer client. As this is an incoming message metadata it is created by the framework and injected into incoming batch messages.
  • Constructor Details

    • IncomingKafkaRecordBatchMetadata

      public IncomingKafkaRecordBatchMetadata(org.apache.kafka.clients.consumer.ConsumerRecords<K,T> records, List<Message<?>> batchedMessages, String channel, int index, Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets, int consumerGroupGenerationId)
    • IncomingKafkaRecordBatchMetadata

      public IncomingKafkaRecordBatchMetadata(org.apache.kafka.clients.consumer.ConsumerRecords<K,T> records, String channel, int index, Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets, int consumerGroupGenerationId)
    • IncomingKafkaRecordBatchMetadata

      public IncomingKafkaRecordBatchMetadata(org.apache.kafka.clients.consumer.ConsumerRecords<K,T> records, String channel, Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets)
  • Method Details

    • getChannel

      public String getChannel()
      Returns:
      channel name from which this message is consumed
    • getRecords

      public org.apache.kafka.clients.consumer.ConsumerRecords<K,T> getRecords()
      Returns:
      the underlying Kafka ConsumerRecords
    • count

      public int count()
      Returns:
      the total number of records for all topic partitions
    • partitions

      public Set<org.apache.kafka.common.TopicPartition> partitions()
      Returns:
      the set of topic partitions with data in this record batch
    • getOffsets

      public Map<org.apache.kafka.common.TopicPartition,org.apache.kafka.clients.consumer.OffsetAndMetadata> getOffsets()
    • getConsumerIndex

      public int getConsumerIndex()
    • getConsumerGroupGenerationId

      public int getConsumerGroupGenerationId()
      Returns:
      the consumer group metadata generation id at the time of polling this record
    • getBatchedMessages

      public List<Message<?>> getBatchedMessages()
      Returns:
      batched messages
    • getMetadataForRecord

      public <M> M getMetadataForRecord(org.apache.kafka.clients.consumer.ConsumerRecord<K,T> rec, Class<M> metadata)
      Get metadata object for the given record. This method is useful when you need to access metadata for a specific record in the batch.
      Type Parameters:
      M - metadata type
      Parameters:
      rec - Kafka consumer record
      metadata - metadata type class
      Returns:
      metadata object for the given record