Consumer

Consumer is the contract for Kafka consumers.

Note
KafkaConsumer is the main public class that Kafka developers use to write Kafka consumers.

Consumer Contract

package org.apache.kafka.clients.consumer;

public interface Consumer<K, V> extends Closeable {
  void assign(Collection<TopicPartition> partitions);
  Set<TopicPartition> assignment();

  void subscribe(Collection<String> topics);
  void subscribe(Collection<String> topics, ConsumerRebalanceListener callback);
  void subscribe(Pattern pattern);
  void subscribe(Pattern pattern, ConsumerRebalanceListener callback);
  Set<String> subscription();

  void unsubscribe();

  ConsumerRecords<K, V> poll(long timeout);

  void commitSync();
  void commitSync(Map<TopicPartition, OffsetAndMetadata> offsets);

  void commitAsync();
  void commitAsync(OffsetCommitCallback callback);
  void commitAsync(Map<TopicPartition, OffsetAndMetadata> offsets, OffsetCommitCallback callback);

  void seek(TopicPartition partition, long offset);
  void seekToBeginning(Collection<TopicPartition> partitions);
  void seekToEnd(Collection<TopicPartition> partitions);

  long position(TopicPartition partition);
  OffsetAndMetadata committed(TopicPartition partition);
  Map<MetricName, ? extends Metric> metrics();
  List<PartitionInfo> partitionsFor(String topic);
  Map<String, List<PartitionInfo>> listTopics();
  Set<TopicPartition> paused();
  void pause(Collection<TopicPartition> partitions);
  void resume(Collection<TopicPartition> partitions);
  Map<TopicPartition, OffsetAndTimestamp> offsetsForTimes(Map<TopicPartition, Long> timestampsToSearch);
  Map<TopicPartition, Long> beginningOffsets(Collection<TopicPartition> partitions);
  Map<TopicPartition, Long> endOffsets(Collection<TopicPartition> partitions);

  void close();
  void close(long timeout, TimeUnit unit);

  void wakeup();
}
Table 1. Consumer Contract
Method Description

assign

commitSync

poll

Polling topics for data

seek

subscribe

unsubscribe

wakeup

results matching ""

    No results matching ""