虽然我已经搜索了足够多,但无法获得解决此问题的帮助。我是Ruby的新手,所以如果我错过了一些非常基本的东西,请原谅我。
在windows上执行以下代码时,我收到error "C:/Users/shhashmi/workspace/rabbitmqSender/sender.rb:36:in []': can't convert Symbol into Integer (TypeError) from C:/Users/shhashmi/workspace/rabbitmqSender/sender.rb:36:ingetItem‘from C:/Users/shhashmi/workspace/rabbitmqSender/sender.rb:59:in `'“
然而,代码在CentOS上工作得很好。
require "bunny"
require "net/http"
# Rabbit MQ
@host = "test.host"
@queue = "test.queue"
#@host = "localhost"
#@queue = "TEST"
# Put your target machine here
@target = "http://localhost:3000/"
def getItem
b = Bunny.new(:host=>@host, :port=>5672,)
# start a communication session with the amqp server
b.start
# declare a queue
q = b.queue(@queue, :auto_delete=>true)
# declare default direct exchange which is bound to all queues
e = b.exchange("")
# publish a message to the exchange which then gets routed to the queue
#e.publish("Hello, everybody! 211", :key => @queue)
#e.publish("Hello, everybody! 311", :key => @queue)
# get message from the queue
msg = q.pop[:payload]
puts "This is the message: " + msg + "\n\n"
# close the connection
b.stop
return msg
end
getItem发布于 2013-06-25 15:14:09
我能够用你的代码重现这个错误。问题出在这一行:
msg = q.pop[:payload]从队列中弹出消息后,Queue#pop方法返回一个包含3个项的数组。该方法应如下所示:
delivery_info, message_properties, msg = q.pop现在,您应该在'msg‘变量中看到您的消息有效负载。您可以检查其他两个结果以收集任何有用的信息(例如,队列中剩余消息的数量),或者如果您不需要它们,则完全忽略它们
https://stackoverflow.com/questions/14120517
复制相似问题