我正在尝试将哈希对象推送到 rabbitmq 。这就是我推动的方式:
msg[:gateway] = "gat1"
msg[:params] = {
:status => "2",
:token_id => "SADF3434FG2FG",
:mb_tranaction_id => "1235ABC",
:random_num => "#{2*rand(155)}"
}
AmqpClient.instance.publish("#{RABBIT_MQ_CONFIG['ipn_queue']}", msg.to_json)
在输出上它看起来像这样:
{\"gateway\":\"gat1\",\"params\":{\"status\":\"2\",\"token_id\":\"SADF3434FG2FG\",\"mb_tranaction_id\":\"1235ABC\",\"random_num\":\"62\"}}
当我拉动时,我试图将其解码回哈希对象,如下所示:
msg = JSON.parse(msg)
p "worker: #{msg.inspect}"
输出是:
"worker: {\"gateway\"=>\"skrill\", \"params\"=>{\"status\"=>\"2\", \"token_id\"=>\"SADF3434FG2FG\", \"mb_tranaction_id\"=>\"1235ABC\", \"random_num\"=>\"62\"}}"
但是当我尝试通过键(网关)访问其中一个值时,msg[:gateway]
我得到一个空白字符串......