[rabbitmq-discuss] Publishing binary messages using ruby amqp gem
paneer_tikka
neerajapte at gmail.com
Sun Oct 24 09:02:37 BST 2010
Hi,
Has anyone published binary messages (where payload is binary) to
RabbitMQ using amqp gem? I am a newbie when it comes to RabbitMQ/AMQP.
I am able to publish text files and json messages fine. Having read
that RabbitMQ message is a pure binary message, I thought publishing
binary payload would be as simple as passing the bytes of the message
to the "publish" call.
When I try to publish a binary message, it seems that the queue simply
“hangs”. Any further messages on the queue, even text messages, seem
to get “stuck”. Here’s a simple test code you can run from irb. If I
run it as it is, the client gets the 'blabla' text message fine. Now
if I change the publisher to publish the contents (uncomment the line
q.publish(contents)), the queue seems to hang from there on. Any
subsequent text messages also seem to be lost.
I am hoping that I’m missing something obvious here, like a
configuration param to the queue or an optional arg to the publish
method, but I haven’t been able to figure it out. Spent several hours
fighting with this yesterday. Can anyone help please?
--- publisher---
require ‘mq’
AMQP.start(:host => '127.0.0.1') do
q = MQ.queue('test_bin_q')
contents = open('C:/Temp/guid.zip', "rb") {|io| io.read }
#q.publish(contents)
q.publish(‘blabla’)
puts 'done publishing'
end
----------------
--- subscriber---
AMQP.start(:host => '127.0.0.1') do
q = MQ.queue('test_bin_q1')
q.subscribe {|message| puts "got it!\n#{message}"}
end
----------------
Neeraj
More information about the rabbitmq-discuss
mailing list