Future<RecordMetadata> future = producer.send(new ProducerRecord<>(topic, messageKey, messageStr));RecordMetadata recordMetadata = future.get();log.info("partition: {}", recordMetadata.partition());log.info("offset: {}", recordMetadata.offset());

BrokerNotAvailableError,NotLeaderForPartitionError 等异常。auto.leader.rebalance.enable = true 进行自动 reBalance,或是人工增加/削减 broker 并手动触发 reBalance 时,ack = all,并且 min.insync.replicas > 1 ,由于消息同时在 leader partition 和 follower partition 都确认,因此消息不会丢失。ack = 1 ,此时可能会出现设置在 replica.lag.time.max.ms 时间中的消息未同步到 follower partition,可能导致消息丢失。ack = all,并且 min.insync.replicas > 1 ,由于消息同时在 leader partition 和 follower partition 都确认,因此消息不会丢失。ack = 1 ,leader 切换将会自动同步 partition 中的 offset,因此消息不会丢失。文档反馈