# AMQP

## Overview
**AMQP** (Advanced Message Queuing Protocol) is an open, binary wire-level messaging protocol, originally developed at JPMorgan Chase and later standardized by OASIS and ISO/IEC. It runs over **TCP**, on IANA-assigned port **5672** for cleartext traffic and **5671** for TLS-secured **AMQPS**, with SASL negotiation on 5672 also able to upgrade a connection to TLS in place. AMQP is broker-centric messaging middleware: producers publish messages to a broker (RabbitMQ, ActiveMQ, Azure Service Bus, etc.) that routes them via exchanges and queues (0-9-1) or link/node addressing (1.0) to consumers, making it common in enterprise messaging, IoT telemetry, and financial transaction systems.

Two incompatible wire formats circulate under the same protocol name and are readily distinguished on the wire: both open a connection with the fixed 8-byte ASCII preamble **`AMQP`** followed by a protocol-ID byte and three version bytes — `41 4D 51 50 00 00 09 01` for **AMQP 0-9-1** (the format used by RabbitMQ) versus `41 4D 51 50 00 01 00 00` for **AMQP 1.0** (the OASIS/ISO standard) — giving a reliable version fingerprint independent of payload. Traffic is cleartext by default unless the AMQPS/TLS variant or a SASL security layer is negotiated, and frames carry broker-, exchange-, and queue-name strings in plaintext that can further identify the messaging backend in use.

### General Frame Format

  
    
  
  
    
      0
      
        12
      
      
        36
      
      
        7size+6
      
      size+7
    
    
      typeoctet
      channelshort
      sizelong
      payload'size' octets
      frame-endoctet
    
  


AMQP defines these frame types:


  
    
  
  
    
      Type
      Name
      Description
    
  
  
    
      1
      METHOD
      Method frame.
    
    
      2
      HEADER
      Content header frame.
    
    
      3
      BODY
      Content body frame.
    
    
      4
      HEARTBEAT
      Heartbeat frame.
    
  



### Method Payloads

  
    
  
  
    
      0
      2
      4
    
    
      class-idshort
      method-idshort
      arguments......
    
  


### Property and Method Summary

#### connection (Class ID 10)

  
    
    
  
  
    
      Method
      ID
      Description
      Method
      ID
      Description
    
  
  
    
      start10start connection negotiation
      tune-ok31negotiate connection tuning parameters
    
    
      start-ok11select security mechanism and locale
      open40open connection to virtual host
    
    
      secure20security mechanism challenge
      open-ok41signal that connection is ready
    
    
      secure-ok21security mechanism response
      close50request a connection close
    
    
      tune30propose connection tuning parameters
      close-ok51confirm a connection close
    
  


#### channel (Class ID 20)

  
    
    
  
  
    
      Method
      ID
      Description
      Method
      ID
      Description
    
  
  
    
      open10open a channel for use
      flow-ok21confirm a flow method
    
    
      open-ok11signal that the channel is ready
      close40request a channel close
    
    
      flow20enable/disable flow from peer
      close-ok41confirm a channel close
    
  


#### exchange (Class ID 40)

  
    
    
  
  
    
      Method
      ID
      Description
      Method
      ID
      Description
    
  
  
    
      declare10verify exchange exists, create if needed
      delete20delete an exchange
    
    
      declare-ok11confirm exchange declaration
      delete-ok21confirm deletion of an exchange
    
  


#### queue (Class ID 50)

  
    
    
  
  
    
      Method
      ID
      Description
      Method
      ID
      Description
    
  
  
    
      declare10declare queue, create if needed
      purge-ok31confirms a queue purge
    
    
      declare-ok11confirms a queue definition
      delete40delete a queue
    
    
      bind20bind queue to an exchange
      delete-ok41confirm deletion of a queue
    
    
      bind-ok21confirm bind successful
      unbind50unbind a queue from an exchange
    
    
      purge30purge a queue
      unbind-ok51confirm unbind successful
    
  


#### basic (Class ID 60)

  
    
    
  
  
    
      Method
      ID
      Description
      Method
      ID
      Description
    
  
  
    
      qos10specify quality of service
      get70direct access to a queue
    
    
      qos-ok11confirm the requested qos
      get-ok71provide client with a message
    
    
      consume20start a queue consumer
      get-empty72indicate no messages available
    
    
      consume-ok21confirm a new consumer
      ack80acknowledge one or more messages
    
    
      cancel30end a queue consumer
      reject90reject an incoming message
    
    
      cancel-ok31confirm a cancelled consumer
      recover-async100redeliver unacknowledged messages
    
    
      publish40publish a message
      recover110redeliver unacknowledged messages
    
    
      return50return a failed message
      recover-ok111confirm recovery
    
    
      deliver60notify the client of a consumer message
      
    
  


#### tx (Class ID 90)

  
    
    
  
  
    
      Method
      ID
      Description
      Method
      ID
      Description
    
  
  
    
      select10select standard transaction mode
      commit-ok21confirm a successful commit
    
    
      select-ok11confirm transaction mode
      rollback30abandon the current transaction
    
    
      commit20commit the current transaction
      rollback-ok31confirm successful rollback
    
  


### Sample Hexdump
Protocol Header. The client MUST start a new connection by sending a protocol header. This is an 8-octet sequence:
```
Advanced Message Queuing Protocol
    Type: Method (1)
    Channel: 0
    Length: 524
    Class: Connection (10)
    Method: Start (10)
    Arguments

0000   41 4d 51 50 00 00 09 01                           AMQP....
```

Connection.Open
```
Advanced Message Queuing Protocol
    Type: Method (1)
    Channel: 0
    Length: 8
    Class: Connection (10)
    Method: Open (40)
    Arguments
        Virtual-Host: /
        Capabilities: 
        .... ...1 = Insist: True

0000   01 00 00 00 00 00 08 00 0a 00 28 01 2f 00 01 ce   ..........(./...
```

### Reference
[AMQP Wireshark Wiki](https://wiki.wireshark.org/AMQP)
[IANA search=amqp](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=amqp)
[RabbitMQ: Inspecting AMQP 0-9-1 Traffic using Wireshark](https://www.rabbitmq.com/amqp-wireshark)
[amqp-specification.zip](https://github.com/ericwu1997/ericwu1997.github.io/raw/refs/heads/main/content/docs/app-layer-protocols/amqp/amqp-specification.zip)