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?
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.
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.
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.
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.
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:
Message Queue: queue-based messaging middlewares are IBM MQ, JMS/ActiveMQ Queues, Hornet MQ
Event queue: queue-based programming framework. You could implement this with any class that implements the Java Queue interface. e.g. BlockingQueue
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
Event Bus: a publish/subscribe based programming framework. Guava EventBus, Observer design pattern
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With