What is the difference between message queue pattern and publish-subscribe?
What is the difference between message queue pattern and publish-subscribe? - Quora https://www.quora.com/What-is-the-difference-between-message-queue-pattern-and-publish-subscribe
A message queue is a stream of messages which typically so to exactly one consumer.
In Publish/Subscriber, you can have any number of subscribers (including zero) listening to the same messages.
A messaging system is a software interface, that maintains a stream of messages to transfer it from one application to another. This system maintains a queue in its in-memory or in its disk to store the messages that are produced by the producers. It will wipe out those messages once they are consumed by the consumers. It follows two kinds of patterns viz. message queueing pattern and pub-sub pattern.
Message queueing pattern is a kind of point-to-point messaging system, where the message from the queue will be wiped once it is consumed by any one of the consumer. It's similar to the default behavior of Post Office Protocol, where the message from the server will be deleted once it is consumed by any of the devices.
In Publish-Subscibe pattern, publishers are the set of producers that publishes different categories of messages and subscribers are set of consumers that consumes messages from the subscribed message categories. Unlike point-to-point messaging systems, the message will be wiped from the queue only if it is consumed by all of the subscribers. In certain messaging systems like kafka, there is a retention policy specifies how long the message should stay in the queue. So the message will be available in the queue for the specified duration even though it is consumed by all of the subscribers.
Kafka as a Messaging System
How does Kafka's notion of streams compare to a traditional enterprise messaging system?
Messaging traditionally has two models: queuing and publish-subscribe. In a queue, a pool of consumers may read from a server and each record goes to one of them; in publish-subscribe the record is broadcast to all consumers. Each of these two models has a strength and a weakness. The strength of queuing is that it allows you to divide up the processing of data over multiple consumer instances, which lets you scale your processing. Unfortunately, queues aren't multi-subscriber—once one process reads the data it's gone. Publish-subscribe allows you broadcast data to multiple processes, but has no way of scaling processing since every message goes to every subscriber.
The consumer group concept in Kafka generalizes these two concepts. As with a queue the consumer group allows you to divide up processing over a collection of processes (the members of the consumer group). As with publish-subscribe, Kafka allows you to broadcast messages to multiple consumer groups.
The advantage of Kafka's model is that every topic has both these properties—it can scale processing and is also multi-subscriber—there is no need to choose one or the other.
Kafka has stronger ordering guarantees than a traditional messaging system, too.
A traditional queue retains records in-order on the server, and if multiple consumers consume from the queue then the server hands out records in the order they are stored. However, although the server hands out records in order, the records are delivered asynchronously to consumers, so they may arrive out of order on different consumers. This effectively means the ordering of the records is lost in the presence of parallel consumption. Messaging systems often work around this by having a notion of "exclusive consumer" that allows only one process to consume from a queue, but of course this means that there is no parallelism in processing.
Kafka does it better. By having a notion of parallelism—the partition—within the topics, Kafka is able to provide both ordering guarantees and load balancing over a pool of consumer processes. This is achieved by assigning the partitions in the topic to the consumers in the consumer group so that each partition is consumed by exactly one consumer in the group. By doing this we ensure that the consumer is the only reader of that partition and consumes the data in order. Since there are many partitions this still balances the load over many consumer instances. Note however that there cannot be more consumer instances in a consumer group than partitions.
Apache Kafka http://kafka.apache.org/intro#kafka_mq
What is the difference between message queue pattern and publish-subscribe?的更多相关文章
- 消息队列(Message Queue)基本概念(转)
背景 之前做日志收集模块时,用到flume.另外也有的方案,集成kafaka来提升系统可扩展性,其中涉及到消息队列当时自己并不清楚为什么要使用消息队列.而在我自己提出的原始日志采集方案中不适用消息队列 ...
- 快速比较 Kafka 与 Message Queue 的区别
https://hackernoon.com/a-super-quick-comparison-between-kafka-and-message-queues-e69742d855a8 A supe ...
- 什么是 Message Queue
Message Queue 是一种非同步的从一个服务到另一个服务的交流形式, 被用于无服务器架构和微服务架构中. Messages 被储存在一个队列中直到被处理了或被删除. 每个Messages只会被 ...
- Top 10 Uses For A Message Queue
We’ve been working with, building, and evangelising message queues for the last year, and it’s no se ...
- You Probably Don’t Need a Message Queue
原文地址 I’m a minimalist, and I don’t like to complicate software too early and unnecessarily. And addi ...
- 初识Message Queue之--基础篇
之前我在项目中要用到消息队列相关的技术时,一直让Redis兼职消息队列功能,一个偶然的机会接触到了MSMQ消息队列.秉着技术还是专业的好为原则,对MSMQ进行了学习,以下是我个人的学习笔记. 一.什么 ...
- MSMQ(Microsoft Message Queue)
http://www.cnblogs.com/sk-net/archive/2011/11/25/2232341.html 利用 MSMQ(Microsoft Message Queue),应用程序开 ...
- Message Queue vs. Web Services?
From stackoverflow.com When you use a web service you have a client and a server: If the server fail ...
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
随机推荐
- nginx中access_log和nginx.conf中的log_format用法
nginx服务器日志相关指令主要有两条: 一条是log_format,用来设置日志格式; 另外一条是access_log,用来指定日志文件的存放路径.格式和缓存大小 可以参加ngx_http_log_ ...
- 安卓Toast实现
代码改变世界 Toast实现显示 // 第一个参数:当前的上下文环境.可用getApplicationContext()或this // 第二个参数:要显示的字符串.也可是R.string中字符串ID ...
- 【Luogu】P1586四方定理(DP)
题目链接 此题使用DP.设f[i][j]表示数i用j个数表示,则对于所有的k<=sqrt(i),有 f[i][j]=∑f[i-k*k][j-1] 但是这样会有重复情况.所以先枚举k,再枚举i和j ...
- NOIP一系列模拟赛小结
NOIP越发接近了,于是自己也跟着机房的几位师兄一起做了几次NOIP模拟赛,收获颇多. #1-T1:求点集中的点能否只用三条与坐标轴平行的直线就能全部被经过,其实只要将横纵坐标排序后逐个点检查下就行. ...
- Ignite集成Spark之IgniteDataFrames
下面简要地回顾一下在第一篇文章中所谈到的内容. Ignite是一个分布式的内存数据库.缓存和处理平台,为事务型.分析型和流式负载而设计,在保证扩展性的前提下提供了内存级的性能. Spark是一个流式数 ...
- USACO Longest Prefix
题目大意:给出一个长字符串,问最长的前缀,使得这个前缀能用给出的一些元素组合而成 思路:暴力dp,dp[i]表示长度为i的前缀能否被表示 /*{ ID:a4298442 PROB:prefix LAN ...
- bzoj2748 [HAOI2012]音量调节 背包
Description 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量.在演出开始之前,他已经做好了一个列表,里面写着在每首歌开始之前他想要改 ...
- bzoj 1818 Cqoi2010 内部白点 扫描线
[Cqoi2010]内部白点 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1126 Solved: 530[Submit][Status][Disc ...
- mybatis配置报错(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)
如下报错:解决方案:要按照提示的顺序添加属性,(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrappe ...
- 洛谷 [T21778] 过年
离线扫描线+查分+线段树 我们发现,这个题的询问都是离线的,所以我们尝试用离线扫描线的方法来处理 对于每一次操作,我们维护一个差分数组, 在询问的时候,我们用一根扫描线,从左往右扫,并用线段树维护,每 ...