An Introduction to ApacheMQ
Posted By : Asheesh Bhuria | 29-Jul-2019
When working with different technologies and systems which are located at different geographical locations, communication can become a challenge. This is mainly because of difference in time zone and data representation. Data representation in two different technologies is different most of the times. This can hinder the functionalities of the application. In such scenarios where the distributed system is involved, Message Broker can be very useful. Message broker is a program module responsible for message validation, transformation and routing.
Message brokers can be used to:-
Route messages to one or more destinations
Transform messages to an alternative representation
Perform message aggregation, decomposing messages into multiple messages and sending them to their destination, then recomposing the responses into one message to return to the user
Interact with an external repository to augment a message or store it
Invoke web services to retrieve data
Respond to events or errors
Provide content and topic-based message routing using the publish–subscribe pattern
Apache ActiveMQ is an open-source, multi-protocol, Java-based message broker. It provides multiple features like message load-balancing and high availability of the data. It supports a large number of transport protocols including OpenWire, STOMP, MQTT, AMQP, REST, and WebSockets.
ActiveMQ gives you the flexibility to send messages through both queues and topics using a single broker.
Topics and Queues
Topic implements publish and subscribe semantics. In this semantics there are subscribers, which subscribes to topics, and publishers, which publishes message under some topic. Whenever a message is published, it will be received by all the subscribers which have subscribed to that topic.
Queue implements load balancer semantics. A message will be received by only one consumer. If the consumer is not available at that time, it will be kelp until a consumer is available that can process the message. It is important that the consumer sends an acknowledgment after receiving a message, if it fails to do so then the message will be redelivered to another consumer.
In order to send messages across clients, message brokers have to communicate with each other. There are two different types of communication between broker to broker:-
Master Slave Cluster
Store and forward networks of broker
Master/Slave cluster ensures high availability because every message is replicated across every broker, so if the master fails clients can failover to a slave. The slaves will always be synced to the master and hence ensure high availability of the messages.
In Store and Forward Networks of Broker a message is sent across broker to broker. This might not be a good idea to accomplish high availability of messages as if a broker fails, the message remains in its persistent storage until it gets back online.