首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将符号转换为整数(TypeError):仅在windows上使用bunny客户端使用bunny弹出队列时

无法将符号转换为整数(TypeError):仅在windows上使用bunny客户端使用bunny弹出队列时
EN

Stack Overflow用户
提问于 2013-01-02 18:35:19
回答 1查看 256关注 0票数 1

虽然我已经搜索了足够多,但无法获得解决此问题的帮助。我是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上工作得很好。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2013-06-25 15:14:09

我能够用你的代码重现这个错误。问题出在这一行:

代码语言:javascript
复制
msg = q.pop[:payload]

从队列中弹出消息后,Queue#pop方法返回一个包含3个项的数组。该方法应如下所示:

代码语言:javascript
复制
delivery_info, message_properties, msg = q.pop

现在,您应该在'msg‘变量中看到您的消息有效负载。您可以检查其他两个结果以收集任何有用的信息(例如,队列中剩余消息的数量),或者如果您不需要它们,则完全忽略它们

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14120517

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档