我曾被要求评估RabbitMQ而不是Kafka,但发现很难找到一个消息队列比Kafka更适合的情况。有人知道在哪些用例中消息队列在吞吐量、持久性、延迟或易用性方面更适合吗?
当前回答
我知道有点晚了,也许你已经间接地说过了,但是,Kafka根本不是一个队列,它是一个日志(就像上面有人说的,基于民意调查)。
简单来说,当你更喜欢RabbitMQ(或任何队列技术)而不是Kafka时,最明显的用例是:
You have multiple consumers consuming from a queue and whenever there is a new message in the queue and an available consumer, you want this message to be processed. If you look closely at how Kafka works, you'll notice it does not know how to do that, because of partition scaling, you'll have a consumer dedicated to a partition and you'll get into starvation issue. Issue that is easily avoided by using simple queue techno. You can think of using a thread that will dispatch the different messages from same partition, but again, Kafka does not have any selective acknowledgment mechanisms.
你能做的最多的就是像那些家伙一样,试着把Kafka转换成一个队列: https://github.com/softwaremill/kmq
雅尼克
其他回答
RabbitMQ是一种传统的通用消息代理。它使web服务器能够快速响应请求,并将消息传递到多个服务。发布者能够发布消息并使其可用于队列,以便消费者可以检索它们。通信可以是异步的,也可以是同步的。
另一方面,Apache Kafka不仅仅是一个消息代理。它最初是由LinkedIn设计和实现的,用于作为消息队列。自2011年以来,Kafka已经开源,并迅速发展成为一个分布式流媒体平台,用于实现实时数据管道和流媒体应用程序。
它具有水平可扩展性、容错性、极快的速度和可磨合性 在数千家公司生产。
现代组织有各种各样的数据管道来促进系统或服务之间的通信。当相当数量的服务需要实时相互通信时,事情就变得有点复杂了。
The architecture becomes complex since various integrations are required in order to enable the inter-communication of these services. More precisely, for an architecture that encompasses m source and n target services, n x m distinct integrations need to be written. Also, every integration comes with a different specification, meaning that one might require a different protocol (HTTP, TCP, JDBC, etc.) or a different data representation (Binary, Apache Avro, JSON, etc.), making things even more challenging. Furthermore, source services might address increased load from connections that could potentially impact latency.
通过解耦数据管道,Apache Kafka带来了更简单、更易管理的体系结构。Kafka充当了一个高吞吐量的分布式系统,源服务在其中推送数据流,使它们可供目标服务实时提取。
另外,现在有很多开源的和企业级的用户界面来管理Kafka集群。有关更多详细信息,请参阅我的文章Apache Kafka集群的UI监控工具概述和为什么Apache Kafka?
使用RabbitMQ还是Kafka取决于项目的需求。一般来说,如果你想要一个简单的/传统的发布-订阅消息代理,那么选择RabbitMQ。如果你想构建一个事件驱动的体系结构,在此基础上你的组织将实时处理事件,那么选择Apache Kafka,因为它为这种体系结构类型提供了更多的功能(例如Kafka Streams或ksqlDB)。
投票最多的答案涵盖了大部分内容,但我想强调用例的观点。卡夫卡能做兔子mq能做的事情吗?答案是肯定的,但兔子mq能做卡夫卡能做的所有事情吗?答案是否定的。
rabbit mq不能做的让kafka与众不同的事情是分布式消息处理。现在读一下得票最多的答案,它会更有意义。
To elaborate, take a use case where you need to create a messaging system that has super high throughput for example "likes" in facebook and You have chosen rabbit mq for that. You created an exchange and queue and a consumer where all publishers (in this case FB users) can publish 'likes' messages. Since your throughput is high, you will create multiple threads in consumer to process messages in parallel but you still bounded by the hardware capacity of the machine where consumer is running. Assuming that one consumer is not sufficient to process all messages - what would you do?
你能再增加一个消费者到队列中吗?不,你不能这样做。 你能创建一个新的队列并绑定该队列来交换发布“喜欢”消息吗?答案是不能,因为你会有两次消息处理。
这是卡夫卡解决的核心问题。它允许您创建分布式分区(rabbit mq中的Queue)和相互通信的分布式消费者。这确保主题中的消息由分布在各个节点(Machines)中的使用者处理。
Kafka代理确保消息在该主题的所有分区上实现负载平衡。消费者组确保所有消费者彼此交谈,并且消息不会被处理两次。
但在现实生活中,除非吞吐量非常高,否则您不会遇到这个问题,因为即使只有一个消费者,rabbit mq也可以非常快地处理数据。
我能想到的唯一好处是事务性功能,其余的都可以用Kafka来完成
我知道有点晚了,也许你已经间接地说过了,但是,Kafka根本不是一个队列,它是一个日志(就像上面有人说的,基于民意调查)。
简单来说,当你更喜欢RabbitMQ(或任何队列技术)而不是Kafka时,最明显的用例是:
You have multiple consumers consuming from a queue and whenever there is a new message in the queue and an available consumer, you want this message to be processed. If you look closely at how Kafka works, you'll notice it does not know how to do that, because of partition scaling, you'll have a consumer dedicated to a partition and you'll get into starvation issue. Issue that is easily avoided by using simple queue techno. You can think of using a thread that will dispatch the different messages from same partition, but again, Kafka does not have any selective acknowledgment mechanisms.
你能做的最多的就是像那些家伙一样,试着把Kafka转换成一个队列: https://github.com/softwaremill/kmq
雅尼克
从技术上讲,与Rabbit MQ提供的特性集相比,Kafka提供了一个巨大的超特性集。
如果问题是
Rabbit MQ技术上比Kafka更好吗?
那么答案是
No.
但是,如果问题是
从业务角度看Rabbit MQ比Kafka好吗?
那么,答案是
在某些商业场景中,可能是“Yes”
从业务角度来看,Rabbit MQ可以比Kafka更好,原因如下:
Maintenance of legacy applications that depend on Rabbit MQ Staff training cost and steep learning curve required for implementing Kafka Infrastructure cost for Kafka is higher than that for Rabbit MQ. Troubleshooting problems in Kafka implementation is difficult when compared to that in Rabbit MQ implementation. A Rabbit MQ Developer can easily maintain and support applications that use Rabbit MQ. The same is not true with Kafka. Experience with just Kafka development is not sufficient to maintain and support applications that use Kafka. The support personnel require other skills like zoo-keeper, networking, disk storage too.