Understanding of AMQP Basic.Publish frame format

114 views
Skip to first unread message

Daron Burleson

unread,
Feb 7, 2021, 8:24:18 AM2/7/21
to rabbitmq-users

Hello everyone,

I am trying to parse the "arguments" field in the payload of AMQP Basic.Publish method According to the specifications, the three first parameters have always the same size:

  • Consumer-tag: (shortsrt) 31 bytes
  • Delivery-tag: (longlong) 8 bytes
  • Redelivered: (1 bit) packed into 1 byte as far I understand from the pcap file

The problem comes with the two following parameters, "exchange" and "routing-key" parameters, as they have variable size and sometimes even the "exchange" field is empty (and I don't meant that is a empty string, what I mean is that the actual bytes are not sent into the wire). Even though I know the total payload size, I cannot detected where the "exchange" parameter ends and the "routing-key" parameter starts

My doubt is wow can I know where each fields starts in order to parse them. Wireshark is able to parse them correctly, but I don't know where it gets that info.

Any help is much appreciated!

Cheers,

Daron

Wesley Peng

unread,
Feb 7, 2021, 8:32:48 AM2/7/21
to RabbitMQ Users
Maybe you look through the C library source who can give you glues.

Thanks 
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.

Dominic Morneau

unread,
Feb 7, 2021, 8:45:23 AM2/7/21
to rabbitmq-users
There's a couple string types defined in the AMQP spec, quote follows:
  • Short strings, stored as an 8-bit unsigned integer length followed by zero or more octets of data. Short strings can carry up to 255 octets of UTF-8 data, but may not contain binary zero octets.
  • Long strings, stored as a 32-bit unsigned integer length followed by zero or more octets of data. Long strings can contain any data.
The fields you're referring to are listed as short strings in the AMQP reference page on the RabbitMQ website. 

Dominic
2021年2月7日日曜日 22:24:18 UTC+9 Daron Burleson:

Daron Burleson

unread,
Feb 7, 2021, 2:32:03 PM2/7/21
to rabbitmq-users
Thanks Dominic and Wesley for the hint!

I've been digesting the C library source ,which has been quite useful, and I understand that the length of both fields are stored in variable of this type

typedef struct amqp_envelope_t_ {
    ... other fields ..
    amqp_bytes_t exchange;
    amqp_bytes_t routing_key;
 } amqp_envelope_t;


Field type of both parameters is amqp_bytes_t that has just two fields:

      size_t  len
   void *  bytes

but the thing is that I cannot understand/find/understand the logic that computes its length (size_t len)

Any help is much appreciated!

-- Daron

Gavin M. Roy

unread,
Feb 7, 2021, 7:35:15 PM2/7/21
to rabbitm...@googlegroups.com
You might find Chapter 2 of my book useful: https://livebook.manning.com/book/rabbitmq-in-depth/chapter-2/26

--

Daron Burleson

unread,
Feb 8, 2021, 4:00:34 AM2/8/21
to rabbitmq-users
 I have just understood how the string encoding works here... The first byte in the wire accounts for the field lenght, that's all :)

Thanks!
Reply all
Reply to author
Forward
0 new messages