Over a million developers have joined DZone.

AMQP Custom Headers In Ruby Client (tmm1-amqp)

·
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)
end


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.

Eric
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}