Category: java
what is mq
Published on 26 May 2026
Explanation
MQ (Message Queue) is a system
that allows applications or services to
communicate asynchronously
by sending messages through
a queue. One application sends a
message to the queue, and another
application processes it later. MQ helps
in decoupling services,
improving scalability, reliability,
and performance in distributed systems.
Code:
Producer Service --> Message Queue --> Consumer Service
Explanation
Uses of MQ: 1. Async task
processing 2. Microservice communication
3. Email/SMS
notifications 4. Order processing
5. Background
jobs 6. Load balancing 7. Event-driven
architecture 8. Real-time data streaming
Code:
Example: User places order -> Order message added to queue -> Payment service and Email service process the message independently
Explanation
Popular MQ technologies include RabbitMQ,
Apache
Kafka, Redis Pub/Sub, Amazon SQS, and
ActiveMQ.
Code:
RabbitMQ -> Traditional queue messaging Kafka -> High-throughput event streaming SQS -> Cloud-based queue service
Explanation
Simple Python example using RabbitMQ with
pika library.
Code:
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='tasks')
channel.basic_publish(exchange='',
routing_key='tasks', body='Hello MQ')
print('Message Sent')
connection.close()