Advanced Message Queuing Protocol (AMQP) is created as an open standard protocol that allows messaging interoperability between systems, regardless of message broker vendor or platform used; With AMQP, you can use whatever AMQP-compliant client library you want, and any AMQP-compliant broker you want. Message clients using AMQP are completely agnostic.
AMQP is an application layer protocol that lets client applications talk to the server and interact. However, AMQP should not just be considered a protocol used for over-the-wire communication; AMQP defines both the network layer protocol and a high-level architecture for message brokers.
It defines a set of messages capabilities which must be made available by an AMQP compliant server implementation (like RabbitMQ). Including rules of how messages must be routed and stored within the broker to follow the AMQ Model.
RabbitMQ is a messaging system that uses AMQP 0.9.1 as the basis for a set of standards controlling the entire message passing process. AMQP 0.9.1 was published in November 2008, which is also the version that will be covered in this article.
The Advanced Message Queuing Protocol
Advanced Message Queuing Protocol (AMQP) is an application layer protocol that focuses on process-to-process communication across IP networks. An encoding schema and a set of procedures allow for two different servers to communicate regardless of the technology used. Overall, the goal of AMQP is to enable message passing through broker services over TCP/IP connections. AMQP is considered a compact protocol, since it’s a binary protocol, meaning that everything sent over AMQP is binary data. A binary protocol avoids sending useless data over the wire.
The Advanced Message Queuing Model
Let’s start to talk about the AMQ Model and some concepts and core components to be familiar with, which are shown in the image below.
Typically, one client called the producer sends a message to an exchange. Exchanges then distribute message copies to queues, depending on rules defined by the exchange type and routing key provided in the message. The message is finally consumed by a subscriber.
Components of AMQP
A queue acts as a buffer that stores messages that are consumed later. A queue can also be declared with a number of attributes during creation. For instance, it can be marked as durable, auto-delete and exclusive, where exclusive means that it can be used by only one connection and this queue will be deleted when that connection closes.
Exchanges and Exchange Types
A channel routes messages to a queue depending on the exchange type and bindings between the exchange and the queue. For a queue to receive messages, it must be bound to at least one exchange.
AMQP 0.9.1 brokers should provide four exchange types - direct exchange, fanout exchange, topic exchange, and header exchange. A deeper understanding of the different exchange types, bindings, routing keys and how or when you should use them can be found in RabbitMQ for beginners - Exchanges, routing keys and bindings.
An exchange can be declared with a number of attributes during creation. For instance, it can be marked as durable so that it survives a broker restart, or it can be marked as auto-delete meaning that it’s automatically deleted when the last queue is unbound.
A binding is a relation between a queue and an exchange consisting of a set of rules that the exchange uses (among other things) to route messages to queues.
Message and Content
A message is an entity sent from the publisher to the queue and finally subscribed to by the consumer. Each message contains a set of headers defining properties such as life duration, durability, and priority.
AMQP 0.9.1 also has a built-in feature called message acknowledgment that is used to confirm message delivery and/or processing.
A connection in AMQP 0.9.1 is a network connection between your application and the AMQP broker, e.g. a TCP/IP socket connection.
A channel is a virtual connection inside a connection, between two AMQP peers. Message publishing or consuming to or from a queue is performed over a channel (AMQP). A channel is multiplexed, one single connection can have multiple channels.
More information about connections and channels and the relationship between them can be found here.
Virtual hosts (vhost) provide a way to segregate applications in the broker. Different users can have different access privileges to different vhost. Queues and exchanges is created so they only exist in one vhost.
AMQP 0.9.1 provides a number of methods or operations that can be performed. Some examples of AMQP methods are opening a channel, declaring a queue or deleting an exchange (channel.open, queue.declare or exchange.delete-ok)
More information can be found here: AMQP 0.9.1 reference.
Other information is passed in the body and is referred to as application data. Your message body will be located here. Application data may take any form or encoding.
How do changes to AMQP affect RabbitMQ?
RabbitMQ currently supports the latest version of AMQP, 1.0, through a plugin. The newest version of the protocol differs drastically from the officially supported release, 0.9.1. In particular, AMQP 1.0 imposes fewer semantic requirements but further defines mechanisms for creating and maintaining queues and connections. The latest version imposes less requirements for brokers with no attempt to define exchanges or routing. Instead of passing a message to a queue using a defined routing key, you send a message to an address containing your queue name with a subject that is your routing key. Version 1.0 of the protocol was released on October 30, 2011.
It is unlikely that RabbitMQ will deviate from AMQP 0.9.1. Version 1.0 of the protocol released on October 30, 2011 but has not gained widespread support from developers.
Get started with an AMQP broker
Get in touch with us if you have questions on how you can obtain the power of AMQP through your own private RabbitMQ instance, hosted by CloudAMQP. CloudAMQP supports the latest version of RabbitMQ, through nearly instantaneously available instances. You can even get started for free with the free plan Little Lemur.