我正在学习 RabbitMQ 并运行了 hello world 示例http://www.rabbitmq.com/tutorials/tutorial-one-python.html在本地主机上没有问题。现在我想测试从我的电脑到另一台服务器的消息传递,receive.py 似乎从未收到任何消息。也许我没有正确指定主机名?
接收.py:
#!/usr/bin/env python
import pika
import json
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='66.175.x.x'))
channel = connection.channel()
channel.queue_declare(queue='hello')
print ' [*] Waiting for messages. To exit press CTRL+C'
def callback(ch, method, properties, body):
data = json.loads(body)
print "Log filename is " + data["filename"]
print data["content"]
channel.basic_consume(callback,
queue='hello',
no_ack=True)
channel.start_consuming()
发送.py:
#!/usr/bin/env python
import pika
import json
import sys
filename = sys.argv[1]
logdata = open(filename, 'r').read()
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='66.175.x.x'))
channel = connection.channel()
channel.queue_declare(queue='logupload')
n = filename.rfind('\\')
if n != -1:
filename = filename[n + 1:]
data = {"filename":filename, "logdata":logdata}
channel.basic_publish(exchange='',
routing_key='logupload',
body=json.dumps(data))
connection.close()
print "sent %s %d bytes" % (filename, len(logdata))
答案1
RabbitMQ——http://www.rabbitmq.com/configure.html
查看 frame_max。似乎默认支持 128KB。您可能需要在安装中检查该设置。
答案2
确保 rabbitmq 确实在监听端口 5672,并且该端口在 Linode 服务器的防火墙中是打开的。
在您的配置中,RABBITMQ_NODE_IP_ADDRESS 应该为空白,RABBITMQ_NODE_PORT 应该是 5672。