參考:https://www.zhihu.com/question/30343125
兩者雖然都是從傳統的Pub/Sub消息系統演化出來的,但是進化的方向不一樣,以下是幾個比較突出的點:
- Kafka是為了數據集成的場景,與以往Pub/Sub消息總線不一樣,通過分布式架構提供了海量消息處理、高容錯的方式存儲海量數據流、保證數據流的順序等特性。可以參考雲上的卡夫卡 - 數據工會。
- MQTT是為了物聯網場景而優化,不但提供多個QoS選項(exact once、at least once、at most once),而且還有層級主題、遺囑等等特性。可以參考MQTT入門篇 - 數據工會。
說白了都是傳統消息系統(老爸)的子嗣,只是與不同的場景(老媽)結合的產物。不過,兩者卻可以結合起來使用。比如可以用MQTT接受物聯網設備上傳的數據,然后接入Kafka,最后可以同時分發到HDFS歸檔、數據倉庫做OLAP分析、Elasticsearch做全文檢索,這樣的架構非常適合大型物聯網項目,不但能夠處理海量數據同時也具有很好的擴展性。
MQTT and Kafka, on paper, are publish/subscribe (pub/sub) messaging platforms. But a key distinction between the two relates to how they are put to use. Unlike Kafka, MQTT is a machine-to-machine (M2M) messaging protocol. This means that while Kafka is responsible for data management and ingestion into computation systems, MQTT specializes in data packet exchange between two physical devices. In our home automation example, if we want to adjust air conditioning according to ambient temperature, the temperature sensor must be able to communicate with the air conditioner. This communication is held through MQTT. As expected, MQTT is only intended for small-sized data sets, where responsiveness and power efficiency are prioritized. This doesn’t lend well to large data sets – the result being bad scaling. Kafka, on the other hand, is designed specifically with massive data feeds in mind. Sound IoT systems use Kafka and MQTT in conjunction, co-existing separately for maximum performance and scalability.