Over a million developers have joined DZone.

AMQP Custom Headers In Ruby Client (tmm1-amqp)

DZone's Guide to

AMQP Custom Headers In Ruby Client (tmm1-amqp)

Free Resource
Want to send custom headers with your AMQP Basic messages?  The protocol mentions a "headers" field of type "table", which is where these get stuffed.  But how is this implemented in the Ruby client?

Publishing is as simple as this:

my_exchange.publish( my_message, :headers => { my_header => "foo" } )

Then on the subscribing end, the headers are accessible as an array of key-value pairs:

my_queue.subscribe do |hdr, body|
    pair = hdr.headers.find {|k, v| k == :my_header}
    my_header_value = (pair ? pair[1] : nil)

Despite Aman's generally excellent documentation of his AMQP client (http://github.com/tmm1/amqp), I couldn't find this without hunting through the code.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}