(场景)kafka的topic多分区的情况,如何保证跨区的消息消费的顺序性

本文探讨了在Kafka中如何保证部分消息的消费顺序性,特别是针对message.key相同的消息。Kafka仅能确保分区内的消息顺序,而通过控制Producer将同一key的消息发送至同一分区,可以实现部分有序。在Kafka-Storm集成测试中,由于模拟数据的随机性导致了负数滞留时间的计算错误。解决方案包括业务层面的规避和处理失败的重试策略优化。此外,文章还提到了Kafka消费原理的相关知识。
摘要由CSDN通过智能技术生成

这个问题严格来说是肯定有的,kafka只能保证分区内的有序性


下面是kafka作者Jay Kreps的blog中介绍kafka设计思想的一段话。

Each partition is a totally ordered log, but there is no global ordering between partitions (other than perhaps some wall-clock time you might include in your messages). The assignment of the messages to a particular partition is controllable by the writer, with most users choosing to partition by some kind of key (e.g. user id). Partitioning allows log appends to occur without co-ordination between shards and allows the throughput of the system to scale linearly with the Kafka cluster size.


针对部分消息有序(message.key相同的message要保证消费顺序)场景,可以在producer往kafka插入数据时控制,同一key分发到同一partition上面。


kafka源码如下,支持该方式

private [kafka] class DefaultPartitioner[T] extends Partitioner[T] {
   private
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值