尽管我已经进行了足够多的搜索,但无法获得解决此问题的帮助。我对 Ruby 很陌生,所以如果我遗漏了一些非常基本的东西,请原谅我。
在 Windows 上执行以下代码时,我收到[]': can't convert Symbol into Integer (TypeError)
from C:/Users/shhashmi/workspace/rabbitmqSender/sender.rb:36:in
来自 C:/Users/shhashmi/workspace/rabbitmqSender/sender.rb:59:in 的错误“C:/Users/shhashmi/workspace/rabbitmqSender/sender.rb:36:in getItem” `'"
但是代码在 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