TrafficTraceEntiy entiy = consume(record);
entiyList.add(entiy);
}
try {
//根据第一条记录的时间和前缀生成索引名
Long date= entiyList.get(0).getStart_time().getTime();
String index= Table_Name.esIndexPrefix+ Instant.ofEpochMilli(date).atZone(ZoneId.systemDefault()).toLocalDateTime().format(DateTimeFormatter.ofPattern("yyyyMM"));
//使用es客户端存储数据
client.bulkIndexDocuments1(index,entiyList);
} catch (IOException e) {
throw new RuntimeException(e);
}
- 这是一个Kafka消费者监听器方法,用于批量消费Kafka主题中的记录。使用了@KafkaListener注解指定要监听的主题和消费者组ID。方法的参数List<ConsumerRecord<String, String>> records表示一次批量消费的记录列表。
- 在方法中,首先创建了一个空的TrafficTraceEntiy列表entiyList用于存储处理后的数据。然后通过for循环遍历records列表,对每条记录调用consume()方法根据业务需求进行数据处理,并将处理后的结果添加到entiyList中。
- 根据entiyList中第一条记录的时间和前缀生成一个索引名,以实现分索引存储,通过使用E