Class KafkaConsumerState<KafkaKeyT,​KafkaValueT,​ClientKeyT,​ClientValueT>


  • public class KafkaConsumerState<KafkaKeyT,​KafkaValueT,​ClientKeyT,​ClientValueT>
    extends Object
    Tracks all the state for a consumer. This class is abstract in order to support multiple serialization formats. Implementations must provide decoders and a method to convert KafkaMessageAndMetadata<K,V> values to ConsumerRecords that can be returned to the client (including translation if the decoded Kafka consumer type and ConsumerRecord types differ).
    • Method Detail

      • createConsumerRecord

        public ConsumerRecordAndSize<ClientKeyT,​ClientValueT> createConsumerRecord​(org.apache.kafka.clients.consumer.ConsumerRecord<KafkaKeyT,​KafkaValueT> record)
        Converts a MessageAndMetadata using the Kafka decoder types into a ConsumerRecord using the client's requested types. While doing so, computes the approximate size of the message in bytes, which is used to track the approximate total payload size for consumer read responses to determine when to trigger the response.
        Parameters:
        record - the message
        Returns:
        consumer record and size
      • commitOffsets

        public List<TopicPartitionOffset> commitOffsets​(boolean async,
                                                        ConsumerOffsetCommitRequest offsetCommitRequest)
        Commit the given list of offsets
        Parameters:
        async - the async flag
        offsetCommitRequest - the offset commit request
        Returns:
        a list of TopicPartitionOffset
      • seekToBeginning

        public void seekToBeginning​(ConsumerSeekToRequest seekToRequest)
        Seek to the first offset for each of the given partitions.
        Parameters:
        seekToRequest - the seek to request
      • seekToEnd

        public void seekToEnd​(ConsumerSeekToRequest seekToRequest)
        Seek to the last offset for each of the given partitions.
        Parameters:
        seekToRequest - the seek to request
      • seek

        public void seek​(ConsumerSeekRequest request)
        Overrides the fetch offsets that the consumer will use on the next poll(timeout).
        Parameters:
        request - the consumer seek request
      • assign

        public void assign​(ConsumerAssignmentRequest assignmentRequest)
        Manually assign a list of partitions to this consumer.
        Parameters:
        assignmentRequest - the assignment request
      • close

        public void close()
        Close the consumer,
      • subscribe

        public void subscribe​(ConsumerSubscriptionRecord subscription)
        Subscribe to the given list of topics to get dynamically assigned partitions.
        Parameters:
        subscription - the subscription
      • unsubscribe

        public void unsubscribe()
        Unsubscribe from topics currently subscribed with subscribe(Collection).
      • subscription

        public Set<String> subscription()
        Get the current list of topics subscribed.
        Returns:
        a set of String
      • assignment

        public Set<org.apache.kafka.common.TopicPartition> assignment()
        Get the set of partitions currently assigned to this consumer.
        Returns:
        a set of TopicPartition
      • committed

        public ConsumerCommittedResponse committed​(ConsumerCommittedRequest request)
        Get the last committed offset for the given partition (whether the commit happened by this process or another).
        Parameters:
        request - the request
        Returns:
        ConsumerCommittedResponse
      • expired

        public boolean expired​(Instant now)
      • updateExpiration

        public void updateExpiration()
      • convertHeaders

        protected Map<String,​String> convertHeaders​(org.apache.kafka.common.header.Headers headers)