来自多个主题的消息顺序卡夫卡 [英] Order of messages from multiple topics Kafka

查看:95
本文介绍了来自多个主题的消息顺序卡夫卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用Apache Kafka的软件.我有一个订阅了多个主题的消费者,我想知道是否有从这些主题接收消息的命令.我在计算机上尝试了一些组合,但是我需要对此进行确认. 例子

I'm developing a software that uses Apache Kafka. I've got one consumer that subscribed to multiple topics, I'd like to know if there is an order for receiving messages from those topics. I tried some combination on my computer but I need to be sure about this. Example

  • 主题1和主题2的消费子
  • Producer1在topic1上写一些东西
  • Producer2在topic2上写一些东西
  • Producer1在topic1上写一些东西
  • 当消费者进行轮询时,它会收到一条记录列表,该记录首先包含他所订阅的第一个主题的消息,然后包含另一个主题的消息.

我想知道是否总是这样,即消息的顺序与我订阅的主题相同. 谢谢

I'd like to know if it is always like this, i.e. the messages are in order like the topics that I subscribed. Thanks

我想指定我有两个主题,每个主题有一个分区,并且只有一个生产者和一个消费者.我需要先阅读第一个主题的所有消息,然后再阅读另一个主题的消息

I'd like to specify that I have the two topics with one partition each, and only one producer and one consumer. I need to read first all the messages from the first topic and then the messages from the other topic

推荐答案

Kafka仅向您保证分区内消息的顺序.这意味着即使只有一个主题但有多个分区,您也无法保证以相同的顺序接收消息.

Kafka gives you only the guarantee of messages ordering inside a partition. It means that even with only one topic but more than one partitions you have no guarantee that messages are received in the same order they are sent.

关于具有两个主题的用例,即使集群具有多个节点,主题分区负责人将位于不同的代理上,并且客户端通过不同的消息接收消息,因此,主题的订阅顺序与消息顺序之间没有关系.连接.顺便说一句,即使只有一个经纪人拥有所有主题/分区,您也无法保证所描述的内容.

Regarding your use case with two topics there is no relation between subscription order to the topics and messages ordering even because if the cluster has more than one node, the topic partition leader will be on different brokers and the client receives messages over different connections. Btw even with only one broker with all topics/partitions on that you can't have the guarantee you are describing.

这篇关于来自多个主题的消息顺序卡夫卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆