This is part 2 of series of blogs Getting started with RabbitMq.
In this blog we will dwell into Advanced Message Queuing Protocol. A truly interoperable protocol whose one of the implementation is rabbitMq.
This blog presents the elementary topics from AMQP's official documentation. If you have time, energy and interest to read 39 pages on AMQP then I would suggest you to skip this blog and go for it.
What Is AMQP?
AMPQ is a networking protocol which enables client applications (publisher and consumer) to connect with messaging middleware server (broker like rabbitMq) and exchange messages.
Primary entities of AMQP: Let us try to understand parts of AMQP by taking the analogy of our postal service.
Message: Data which one service wants to communicate to another one. Think it as a mail(snail-mail) you want to send to your cousin.
Connection: Physical connection between client and broker. It is a TCP connection which closes only on client disconnection or network failures.
Channel: A logical connection between client and broker. A connection is multiplexed into multiple channels. It saves client and broker to open multiple costly TCP connections.
Broker: The middleware messaging server. Server which acts as the communication channel between publisher and subscriber(Consumer) and implements AMQP messaging routing functions. RabbitMq is one of the many AMQP brokers. This is the whole postal service, and everything following below is part of it.
Exchange: Exchange receives messages from all the publishers and routes them to queues based upon some routing criteria. In the analogy of postal service this is the post office where you drop your letter to be delivered.
It is this post office(exchange) which segregates the messages depending upon the routing criteria.
Queues: Takes the messages from exchange and holds them until they can be safely processed by a consuming client. A message can be delivered to multiple queues if the exchange's routing rules say so.
Binding key: This is the property of every message which defines the destination queue message will be redirected to. In postal terms, it is the address of your cousin.
Binding: This is the routing criteria. The process of delivering the message from exchange to queue, using binding key.
Life cycle of a Message
- Every time a service wants to communicate with another service, it creates a message having a binding key and the data to be communicated.
- Then it publishes the message to the exchange, which is routed to the desired queue(s) depending upon the binding key.
- If no exchange-queue binding is present for given binding key, then the message will be dropped (or submitted to dead letter exchange).
- Once the message reaches the queue, it is consumer app's duty to pick it from queue and process it.
- If no consumer picks the message from the queue, the message will remain intact inside it until TTL expires(only if you have set any).
Final thoughts: RabbitMq is based upon AMQP V 0-9-1. This blog covered the most essential parts of AMQP which one should know to start working with RabbitMq. In upcoming articles we will be exploring these topics in more details. Stayed tuned.