Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 597
wener Avatar asked Jun 21 '14 10:06

wener


People also ask

What is the difference between message queue and pub-sub?

Using message queues if a consumer application instance goes down then another consumer will be able to handle the message instead. Using pub-sub, if a subscriber is down then once it has recovered the messages it has missed will be available for consumption in its subscribing queue.

Is Pubsub a messaging queue?

The Pub Sub queue (or Pub/Sub) is a message pattern of message brokers and it is used to communicate between the various components of microservices. It is used to provide program-to-program and asynchronous communication between the micro-services.

Is Kafka a message queue or pub-sub?

In a very fast, reliable, persisted, fault-tolerance and zero downtime manner, Kafka offers a Pub-sub and queue-based messaging system. Moreover, producers send the message to a topic and the consumer can select any one of the message systems according to their wish.

What is EventBus?

EventBus is an open-source library for Android and Java using the publisher/subscriber pattern for loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development.


1 Answers

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

like image 54
Axel Podehl Avatar answered Sep 23 '22 19:09

Axel Podehl