23

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?

wener
  • 7,191
  • 6
  • 54
  • 78
  • Perfectly explained in [Message Queue vs Message Bus](https://stackoverflow.com/questions/7793927/message-queue-vs-message-bus-what-are-the-differences/33969224) topic – Anton Goncharov Mar 04 '20 at 15:25

3 Answers3

26

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

Axel Podehl
  • 4,034
  • 29
  • 41
  • How queue is 1-to-1? We can use Fanout exchange and message goes to all consumers. – Anish Mittal Oct 18 '22 at 13:56
  • 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://stackoverflow.com/questions/5576415/jms-topic-vs-queues – Axel Podehl Oct 19 '22 at 09:21
  • 1
    Possibly a typo, but it sounds like you meant "*event is usually used for **intra**-application [...]" – Bruno Aug 27 '23 at 13:08
  • yes, and thank you for improving my sloppy non-native English ! – Axel Podehl Aug 28 '23 at 16:46
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.

Brett Okken
  • 6,210
  • 1
  • 19
  • 25
  • So, MQ is an IPC tech.Except this they are interchangeable ?Seems akka EventBus is also distributable. – wener Jun 21 '14 at 16:11
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.

wener
  • 7,191
  • 6
  • 54
  • 78