关于批写,kafka有什么原子性保证(如果有的话)?

piwo6bdm  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(405)

我们现在正在将我们的一项服务从通过传统通信技术推送数据转移到ApacheKafka。
当前的逻辑是向ibmq发送消息,并在发生错误时重试。我想重复一遍,但我不知道经纪人在那种情况下能提供什么样的担保。
假设我通过producer通过java客户机库批量发送100条消息。假设它到达集群,是否有可能只接受它的一部分(例如,磁盘已满,或者我在写入时接触到的某些分区复制不足)?我能从我的制作者那里检测到这个问题并只重试那些不被接受的消息吗?
我在找 kafka atomicity guarantee 但是空空如也,可能有一个众所周知的说法

qojgxg4l

qojgxg4l1#

当你说你在一个批中发送100条消息时,你的意思是,你想控制消息的数量,还是让生产者批处理一定数量的消息然后再发送?
因为您不确定是否可以控制一个producer批处理中生成的消息的数量,所以api将对它们进行排队并对它们进行批处理,但不能保证将它们全部批处理在一起(不过我会检查一下)。
如果您同意让api为您批处理一定数量的消息,那么这里有一些关于如何确认消息的线索。
在与producer打交道时,kafka在写操作(也叫“批写”)方面具有某种可靠性
如本幻灯片所述:https://www.slideshare.net/miguno/apache-kafka-08-basic-training-verisign (83)

The original list of messages is partitioned (randomly if the default partitioner is used) based on their destination partitions/topics, i.e. split into smaller batches. 
Each post-split batch is sent to the respective leader broker/ISR (the individual send()’s happen sequentially), and each is acked by its respective leader broker according to request.required.acks

关于原子性。。对于上述行为,不确定整个批处理将被视为原子。也许您可以确保为每条消息使用相同的密钥来发送您的一批消息,因为它们将进入相同的分区,因此可能成为原子的
如果您需要在生成时更清楚地了解确认规则,请参阅下面的说明https://docs.confluent.io/current/clients/producer.html :

You can control the durability of messages written to Kafka through the acks setting. 
The default value of "1" requires an explicit acknowledgement from the partition leader that the write succeeded. 
The strongest guarantee that Kafka provides is with "acks=all", which guarantees that not only did the partition leader accept the write, but it was successfully replicated to all of the in-sync replicas.

如果您的目标是在生成时没有重复项,那么还可以查看producer enable.幂等行为。
扬尼克

相关问题