写一个kafka的工具类,返回所需要的信息,这样return会对kafka有影响吗?
kafka
List<String> buffer = new ArrayList<>();
Properties consumerProp = getConsumerProp();
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(consumerProp);
try{
consumer.subscribe(topicList);
while(true){
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(1000));
if(records.isEmpty()){
break;
}
for (ConsumerRecord<String, String> record : records){
buffer.add(record.value());
}
consumer.commitAsync();
}
}catch (Exception e){
e.printStackTrace();
}finally {
try{
consumer.commitSync();
}finally {
consumer.close();
}
}
return buffer;