Message queue is a queue of messages sent between applications.
Message queues provide an asynchronous communications protocol, meaning that the sender and receiver of the message do not need to interact with the message queue at the same time.
What is Message Queues?
An application framework for sending and receiving messages;
A way to communicate between applications/systems;
A way to decouple components;
A way to offload work(handle to another worker)
Common use cases
1 Allow web servers to respond to request quickly instead of being forced to perform resource-heavy procedures;
2 Able to distribute a message to multiple recipients for consumption or for balancing loads between workers.
Message Queue in real life
Image resizing
Video processing
Sending out Emails (Ad Campaigns)
Log Analysis
Message Queue Protocol
AMQP: Advanced Message Queue Protocol (RabbitMQ)
STOMP: Streaming Text Oriented Messaging Protocol (ActiveMQ)
XMPP: Extensible Messaging and Presence Protocol
AMQP
Network wire-level Protocol
Defines how clients and brokers talk
Data serialization, heartbeat
AMQP Model
Defines routing and storing of messages
Defines rules how these are wired together
Exported API
Exchange
Queues
consumer gets a message from a queues;
Store message;(short time, has expire time)
FIFO;
Queues can be dynamic;
One message from a queue goes only to one consumer
Exchanges
Route messages
Publisher sends a message to exchange
Can switch between different routing algorithm
Exchange type
Direct(w/o binding)
point to point communication
Direct (w/binding)
binding provides a selector for routing messages from exchange to Queues
Each queue has a binding queues
Each messages has a binding key used fo routing
Fanout
broadcast messages
routing key is ignored
many queues / many consumers
Duplicate and send same message to all queues
Topic
routing key must be in from of xxx.xx.xxx
queues can use wild cast to match topics
exchange copies and sends messages to all matching queues
RabbitMQ
Implements AMQP
Easy to use
Runs on all major operating systems
Supports a huge number of developer platforms
Open source and commercially supported
Cloud-based solution: reduce dependency from localhost
Lower throughput than Apache Kafka
import pika in python