top of page
Writer's pictureThe Tech Platform

What is AMQP and why is it used in RabbitMQ?



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


Message Queue

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.


Binding

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.


Connection

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.


Channel

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.


Virtual Hosts

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 Methods

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)



AMQP frames

A frame is the basic unit with AMQP. A connection consists of the ordered sequence of frames. Order in this case means that the last frame must not arrive at the receiver until all other frames have first reached their destination. Each frame can be divided into three segments (in version 1.0):

  • Frame header: This mandatory header has a size of 8 bytes. Here you will find information that determines the routing of the message.

  • Extended header: This area is optional and has no set scope. It serves to expand the header in the future with further information.

  • Frame body: The body contains the actual data to be transferred. The size is freely selectable. However, this area can also be left empty, then the frame only serves to maintain the connection.


The body of a frame, in turn, can take nine different forms:

  • open: Negotiates the connection parameters between broker and client.

  • begin: Indicates that a connection is starting.

  • attach: The message is appended with a link that is necessary in order to use the data transfer.

  • flow: Changes the status of a link.

  • transfer: The actual message is transmitted with the transfer frame.

  • disposition: A disposition frame provides information on changes to the information delivery.

  • detach: Removes the link.

  • end: Indicates that the connection will be terminated.

  • close: Terminates the connection and declares that no further frames will be sent.


Features and Benefits:

AMQP can be used in any situation if there is a need for high-quality and secure message delivery between client and broker.


AMQP provides the following possibilities:

  • Monitoring and sharing updates;

  • Ensuring quick response of the server to requests and transmission of time-consuming tasks for further processing;

  • Distribute messages to multiple recipients;

  • Connection offline clients for further data retrieval;

  • Increase the reliability and smooth operation of applications.;

  • Reliability of message delivery;

  • High speed message delivery;

  • Message Acceptance.



Read More:



The Tech Platform

0 comments

Recent Posts

See All

Comments


bottom of page