Python RabbitMQ客户端挂起

时间:2014-02-21 02:07:12

标签: python rabbitmq pika

我有一个基于RabbitMQ send.py 示例的简单python脚本。原始的 send.py 在我的设置上运行正常,但是当我使用添加的用户和虚拟主机时,脚本会在执行connection.channel()

时挂起
#!/usr/bin/python
import pika
import json

def getMessageFromFile():
    json_data=open('d:\src\TestData.json')
    data = json.load(json_data)
    json_data.close()
    return data

print "getting msg"
msg = getMessageFromFile()
print "creating credentials"
credentials = pika.credentials.PlainCredentials('DevUser', 'DevPassword')
print "getting connection"
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost', virtual_host='TestVirtualHost', credentials=credentials, socket_timeout=1000, port=5672))
print "getting channel"
channel = connection.channel()
print "getting queue"
channel.queue_declare(queue='TestWorkQueue')

data_string = json.dumps(msg)
print "sending msg"
channel.basic_publish(exchange='', routing_key='TestWorkQueue', body=data_string)
print "msg sent"

connection.close()

print "done"

当我运行它时,我看到了:

getting msg
creating credentials
getting connection
getting channel

此时脚本会挂起大约10分钟。然后打印:

getting queue

然后崩溃pika.exceptions.ChannelClosed例外。

我的猜测是频道并不存在,但没有迹象表明connection.channel()失败了。

0 个答案:

没有答案