简体   繁体   English

消息队列、EventBus 和 Pub/Sub 之间的区别?

[英]The difference between a Message Queue, EventBus and a Pub/Sub?

I am confused between the concept of Message Queue (eg, ActiveMQ, RabbitMQ, ZeroMQ) and EventBus (eg, Guava Event Bus , Akka EventBus )我对 Message Queue(例如 ActiveMQ、RabbitMQ、ZeroMQ)和 EventBus(例如Guava Event BusAkka EventBus )的概念感到困惑

I think MQ and eventBus both use the pub/sub pattern.我认为 MQ 和 eventBus 都使用发布/订阅模式。 MQ seems more powerful and heavy, compared to Guava.与 Guava 相比,MQ 似乎更加强大和沉重。

But what's the real difference?但真正的区别是什么? Is EventBus the same as MQ? EventBus 和 MQ 一样吗?

A message is usually used for inter-process communication and for sending messages between machines.消息通常用于进程间通信以及在机器之间发送消息。 You can encapsulate an event in a message (for example as XML or JSON) and transport this event using a message.您可以将事件封装在消息中(例如作为 XML 或 JSON)并使用消息传输此事件。 TIBCO RV, JMS, IBM or Hornet MQ, ... TIBCO RV、JMS、IBM 或 Hornet MQ、...

An event is usually used for inter-application communication .事件通常用于应用程序间通信 For example to communicate between threads or to react on user input in a GUI application (think Swing events, Guava, etc).例如,在线程之间进行通信或对 GUI 应用程序中的用户输入做出反应(想想 Swing 事件、Guava 等)。

A queue is a 1-to-1 destination of messages.队列是一对一的消息目的地。 The message is received by only one of the consuming receivers (please note: consistently using subscribers for 'topic client's and receivers for queue client's avoids confusion).该消息仅由一个消费接收者接收(请注意:始终使用订阅者为“主题客户端”和接收器为队列客户端避免混淆)。 Messages sent to a queue are stored on disk or memory until someone picks it up or it expires.发送到队列的消息存储在磁盘或内存上,直到有人捡起它或它过期。

A bus is a 1-to-many model of distribution.总线是一种一对多的分布模型。 The destination in this model is usually called topic or subject.此模型中的目的地通常称为主题或主题。 The same published message is received by all consuming subscribers.所有消费订阅者都会收到相同的发布消息。 You can also call this the 'broadcast' model.您也可以将其称为“广播”模型。 You can think of a topic as the equivalent of a Subject in an Observer design pattern for distributed computing.您可以将主题视为分布式计算的观察者设计模式中的主题。 Some message bus providers efficiently choose to implement this as UDP instead of TCP.一些消息总线提供者有效地选择将其实现为 UDP 而不是 TCP。 For topic's the message delivery is 'fire-and-forget' - if no one listens, the message just disappears.对于主题的消息传递是“即发即忘”——如果没有人听,消息就会消失。 If that's not what you want, you can use 'durable subscriptions'.如果这不是您想要的,您可以使用“持久订阅”。

If you take this all together you have these:如果你把这一切放在一起,你就有这些:

  1. Message Queue: queue-based messaging middlewares are IBM MQ, JMS/ActiveMQ Queues, Hornet MQ消息队列:基于队列的消息中间件有 IBM MQ、JMS/ActiveMQ Queues、Hornet MQ

  2. Event queue: queue-based programming framework.事件队列:基于队列的编程框架。 You could implement this with any class that implements the Java Queue interface.您可以使用任何实现 Java Queue 接口的类来实现它。 eg BlockingQueue例如阻塞队列

  3. Message Bus: a publish/subscribe messaging middleware, eg JMS/ActiveMQ Topics, TIBCO RV.消息总线:发布/订阅消息中间件,例如 JMS/ActiveMQ Topics、TIBCO RV。 Messages are sent to another process over TCP or UDP.消息通过 TCP 或 UDP 发送到另一个进程。 For further details see JMS Topic vs Queues有关更多详细信息,请参阅JMS 主题与队列

  4. Event Bus: a publish/subscribe based programming framework.事件总线:基于发布/订阅的编程框架。 Guava EventBus, Observer design pattern Guava EventBus,观察者设计模式

Guava EventBus is only for events within a single jvm. Guava EventBus 仅用于单个 jvm 中的事件。 It even explicitly states that it is not intended for interprocess communication.它甚至明确声明它不用于进程间通信。 I have not looked at Akka, but I am guessing it is similar.我没有看过 Akka,但我猜它是相似的。 MQ, on the other hand, is specifically intended for sending messages between processes.另一方面,MQ 专门用于在进程之间发送消息。

I found the right term in wiki for event bus is Event_monitoring , now then, I can understand what is event bus.我在 wiki 中发现事件总线的正确术语是Event_monitoring ,现在,我可以理解什么是事件总线。 Like a signal system, most of them work in one process, like Guava EventBus dose.就像信号系统一样,它们中的大多数都在一个进程中工作,例如 Guava EventBus 剂量。 Though, they can work as an IPC, but that is not the main purpose.虽然,它们可以作为 IPC 工作,但这不是主要目的。

MQ is an message system,most of them got message server, kind of complex,but grant more controls, more options. MQ 是一个消息系统,大多数都有消息服务器,有点复杂,但授予更多的控制权,更多的选择。 Some of they got an admin tool too.他们中的一些人也有一个管理工具。

So, they are kind of same tech to resolve different scale or situation.因此,它们是解决不同规模或情况的相同技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apache kafka:如何以编程方式查找队列和pub / sub之间的差异 - Apache kafka : how to find difference between queue and pub/sub programatically 消息持久性-Redis发布/订阅 - Message persistence - Redis pub/sub 使用Vertx“ IAsyncResult”和“ EventBus使用者”之间的区别 - the difference between using Vertx “IAsyncResult” and “EventBus consumer” 消息选择器在发布/订阅中并指向 - Message selector in pub/sub and point to point 云发布/订阅接收器中未收到消息 - Message not recieved in cloud pub/sub Receiver 如何使用供应商 bean 发布 Pub/Sub 消息? - How to publish a Pub/Sub message with a Supplier bean? Greenbot Eventbus 3.0:onEvent,onEventMainThread,onEventBackgroundThread和onEventAsync有什么区别? - Greenbot Eventbus 3.0: What is the difference between onEvent, onEventMainThread, onEventBackgroundThread and onEventAsync? Google Pub/Sub 消息大约需要 5 分钟才能发布。 这是为什么? - Google Pub/Sub message took ~5 minutes to be published. Why is that? Spring 引导 PUB/SUB 向主题发送消息的问题 - Problem with Spring Boot PUB/SUB sending message to topic 与机器人进行环聊聊天不会将消息发布到发布/订阅 - Hangout chat to a bot doesn't post the message to pub/sub
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM