Apache kafka 卡夫卡制作人时间戳无法从消费者记录中读取
我正在使用卡夫卡0.10.2Apache kafka 卡夫卡制作人时间戳无法从消费者记录中读取,apache-kafka,Apache Kafka,我正在使用卡夫卡0.10.2KafkaProducer生成主题中的数据。 下面是我的代码 ProducerRecord record = new ProducerRecord(topic, (Integer)null, Long.valueOf(System.currentTimeMillis()), partitionKey.getBytes(), message.getBytes()); Future<RecordMetadata> future = this.produ
KafkaProducer
生成主题中的数据。
下面是我的代码
ProducerRecord record = new ProducerRecord(topic, (Integer)null, Long.valueOf(System.currentTimeMillis()), partitionKey.getBytes(), message.getBytes());
Future<RecordMetadata> future = this.producer.send(record, new Callback() {
public void onCompletion(RecordMetadata recordMetadata, Exception e) {
if(e != null) {
LOGGER.error("Error producing to topic " + partitionKey, e.getCause());
} else {
LOGGER.info(" Successfully produced topic " + recordMetadata.topic() + " on partition " + recordMetadata.partition() + "at " + recordMetadata.timestamp());
}
}
});
ProducerRecord=new ProducerRecord(主题,(整数)null,Long.valueOf(System.currentTimeMillis()),partitionKey.getBytes(),message.getBytes());
Future=this.producer.send(记录,新回调(){
完成时的公共void(RecordMetadata RecordMetadata,异常e){
如果(e!=null){
LOGGER.error(“生成主题的错误”+partitionKey,e.getCause());
}否则{
LOGGER.info(“已成功生成主题”+recordMetadata.topic()+“位于分区”+recordMetadata.partition()+“位于”+recordMetadata.timestamp());
}
}
});
此消息将通过不同集群中的mirrormaker进行复制。我编写了一个Mirrormaker处理程序,通过每条消息发送捕获延迟。
当我在mirrormaker消费者处检查时间戳时。我看不到时间戳。下面是mirrormaker处理程序的代码
@Override
public List<ProducerRecord<byte[], byte[]>> handle(BaseConsumerRecord record) {
LOGGER.debug("Timestamp from dal producer "+record.timestamp());
return Collections.singletonList(new ProducerRecord<byte[], byte[]>(topicToSend,partitionToSend,timeStampAtMM, record.key(), record.value()));
}
@覆盖
公共列表句柄(BaseConsumerRecord记录){
debug(“dal生产者的时间戳”+record.Timestamp());
return Collections.singletonList(新的ProducerRecord(topicToSend、partitionToSend、timestatmm、record.key()、record.value());
}
您的意思是时间戳为空或-1?当我试图从消费者记录中读取时间戳时,我得到了-1。您能否在onCompletion
中添加一些打印逻辑,以确保在生产者端正确生成时间戳?这可能有助于缩小根本原因。此外,您是使用旧消费者还是新消费者来购买MirrorMaker?我正在使用新消费者。我还在生产者代码中添加了时间戳。您是否在server.properties中设置了message.format.version?