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

Kafka只能保证分区内的消息顺序,对于跨区消息顺序,可以通过控制生产者将相同key的消息发送到同一分区来实现部分有序。在Kafka Storm集成测试中,由于模拟数据的随机性可能导致负滞留时间计算,可通过业务过滤或调整处理策略解决。实际场景如用户位置滞留时间计算,需要注意数据的正确性和处理流程的可靠性。
摘要由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]classDefaultPartitioner[T]extendsPartitioner[T]{
  privateval random = newjava
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_26182553

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值