The difference between a Message Queue, EventBus and a Pub/Sub?
Asked Answered
A

3

26

I am confused between the concept of Message Queue (e.g., ActiveMQ, RabbitMQ, ZeroMQ) and EventBus (e.g., Guava Event Bus, Akka EventBus)

I think MQ and eventBus both use the pub/sub pattern. MQ seems more powerful and heavy, compared to Guava.

But what's the real difference? Is EventBus the same as MQ?

Annadiane answered 21/6, 2014 at 10:58 Comment(1)
Perfectly explained in Message Queue vs Message Bus topicErnaernald
T
27

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. TIBCO RV, JMS, IBM or Hornet MQ, ...

An event is usually used for intra-application communication. For example to communicate between threads or to react on user input in a GUI application (think Swing events, Guava, etc).

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. 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

  2. Event queue: queue-based programming framework. You could implement this with any class that implements the Java Queue interface. e.g. BlockingQueue

  3. Message Bus: a publish/subscribe messaging middleware, e.g. JMS/ActiveMQ Topics, TIBCO RV. Messages are sent to another process over TCP or UDP. For further details see JMS Topic vs Queues

  4. Event Bus: a publish/subscribe based programming framework. Guava EventBus, Observer design pattern

Traduce answered 2/7, 2020 at 9:58 Comment(4)
How queue is 1-to-1? We can use Fanout exchange and message goes to all consumers.Caprification
Queue Fanout is rare in JMS Providers. If I remember correctly RabbitMQ has exchanges. Is that what you refer to ? Conceptually I would call a queue going to a message exchange making copies into multiple queues a 'topic'. But also checkout https://mcmap.net/q/117091/-jms-topic-vs-queuesTraduce
Possibly a typo, but it sounds like you meant "*event is usually used for intra-application [...]"Prevention
yes, and thank you for improving my sloppy non-native English !Traduce
D
0

Guava EventBus is only for events within a single 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. MQ, on the other hand, is specifically intended for sending messages between processes.

Disputant answered 21/6, 2014 at 13:19 Comment(1)
So, MQ is an IPC tech.Except this they are interchangeable ?Seems akka EventBus is also distributable.Annadiane
A
0

I found the right term in wiki for event bus is Event_monitoring, now then, I can understand what is event bus. Like a signal system, most of them work in one process, like Guava EventBus dose. Though, they can work as an IPC, but that is not the main purpose.

MQ is an message system,most of them got message server, kind of complex,but grant more controls, more options. Some of they got an admin tool too.

So, they are kind of same tech to resolve different scale or situation.

Annadiane answered 21/6, 2014 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.