0

I want to serialise an object into JSON send it across the wire via rabbitmq and then deserialize it.

I have the following object that I am serialising:

lead = Lead.new

lead.company = 'some company'

operation = proc{ AMQP::Exchange.default.publish(
                                lead.to_json, 
                                :routing_key => header.reply_to,
                                :correlation_id => header.correlation_id
                              )}

On the other side, I am trying to descerialise the object like this:

callback_queue.subscribe do |header, body|
  puts "received #{body.inspect}"

  lead = ActiveSupport::JSON.decode body

  puts lead.company #NoMethodError: undefined method `company' for #<Array:0x6fe03f3b>

The json is strangely an array of 3 hashes and looks like this.

[{\"created_at\":null,\"email\":\"dagda1@scotalt.net\",\"id\":null,\"lead_id\":null,\"updated_at\":null},{\"created_at\":null,\"email\":\"paul.cowan@continuity2.com\",\"id\":null,\"lead_id\":null,\"updated_at\":null}]"

Can anyone see anything I am doing wrong?

Daniel Roethlisberger
  • 6,958
  • 2
  • 41
  • 59
dagda1
  • 26,856
  • 59
  • 237
  • 450

1 Answers1

0

I'm using the same aproach more or less, and works correctly in my side. Probably you are sending a incorrect message (serialization problem). With new rabbitmq you can inspect the message in the rabbit web console.

You could try to print to_json before.

TlmaK0
  • 3,578
  • 2
  • 31
  • 51
  • thank you for the heads up. It is reassuring to know it should work and the problem is at my end. – dagda1 Mar 05 '12 at 16:05