カフカの進捗状況は、最新の消費者の場所にリセットされます

 

 

 

/ ** 
*リセットカフカ消費スケジュール
*パラメータ、ブローカー・カフカのクラスタアドレスを指定するには、トピック名をリセットするために、消費者団体、およびパーティションの数
* /
パブリック
静的な 無効 seekLatest(文字列ブローカー、トピック文字列、文字列基、INT partitionCnt){ マップの<string、オブジェクト> = configProps 新しい新規のHashMap <> (); configProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG、ブローカー); configProps.put(ConsumerConfig.GROUP_ID_CONFIG、基); configProps.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG 、真の); configProps.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG、 100)。 configProps.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG、 30000 )。 configProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG、 "最新" ); configProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG、LongDeserializer。クラス)。 configProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG、ByteArrayDeserializer。クラス)。 DefaultKafkaConsumerFactory <ロング、バイト []>工場= 新しい DefaultKafkaConsumerFactory <>(configProps、新しい LongDeserializer()、新しいByteArrayDeserializer())。 org.apache.kafka.clients.consumer.KafkaConsumer <ロング、バイト[]>消費者=(org.apache.kafka.clients.consumer.KafkaConsumer <ロング、バイト []> )factory.createConsumer(); consumer.subscribe(は、Arrays.asList(トピック)); 一覧 <TopicPartition> topicPartitionLists = 新しい ArrayListを<> (); 以下のためにINT ; I <partitionCnt; iが0 = I ++ ){ topicPartitionLists.add(新しいTopicPartition(トピック、I))。 } consumer.poll( 1 )。 地図 <TopicPartition、ロング> topicPartitionLongMap = consumer.endOffsets(topicPartitionLists)。 (TopicPartitionのTP:topicPartitionLongMap.keySet()){ consumer.seek(TP、topicPartitionLongMap.get(TP))。 } consumer.close()。 }

 

おすすめ

転載: www.cnblogs.com/ZhengQiZHou/p/12627921.html