1010import org .apache .kafka .clients .producer .KafkaProducer ;
1111import org .apache .kafka .clients .producer .Producer ;
1212import org .apache .kafka .clients .producer .ProducerRecord ;
13+ import org .apache .kafka .common .TopicPartition ;
1314import org .wowtools .hppt .common .util .ResourcesReader ;
1415
1516import java .time .Duration ;
17+ import java .util .Arrays ;
1618import java .util .Collections ;
19+ import java .util .List ;
1720import java .util .Properties ;
1821
1922/**
@@ -57,7 +60,7 @@ public interface BytesFunction {
5760 public static BytesFunction buildProducer (String topic ) {
5861 Producer <String , byte []> producer = new KafkaProducer <>(buildProperties ());
5962 return (bytes -> {
60- ProducerRecord <String , byte []> record = new ProducerRecord <>(topic , bytes );
63+ ProducerRecord <String , byte []> record = new ProducerRecord <>(topic ,0 , "x" , bytes );
6164 producer .send (record );
6265 });
6366 }
@@ -75,7 +78,12 @@ public static void buildConsumer(String groupId, String topic, BytesFunction cb)
7578 props .put ("auto.offset.reset" , "latest" );
7679 KafkaConsumer <String , byte []> consumer = new KafkaConsumer <>(props );
7780 // 订阅主题
78- consumer .subscribe (Collections .singletonList (topic ));
81+ TopicPartition partition = new TopicPartition (topic , 0 );
82+ try {
83+ consumer .seekToEnd (List .of (partition ));
84+ } catch (java .lang .IllegalStateException e ) {
85+ consumer .assign (List .of (partition ));
86+ }
7987 {
8088 ConsumerRecords <String , byte []> records = consumer .poll (Duration .ofMillis (100 ));
8189 for (ConsumerRecord <String , byte []> record : records ) {
0 commit comments