0

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()ん。

4

0 に答える 0