Linux
RabbitMQ,讓 hello world 範例無法在 localhost 以外的任何地方工作
我正在學習 RabbitMQ 並在http://www.rabbitmq.com/tutorials/tutorial-one-python.html上執行了 hello world 範例,在本地主機上沒有問題。現在我想測試從我的電腦到另一台伺服器的消息傳遞,receive.py 似乎從來沒有收到任何消息。也許我沒有正確指定主機名?
Receive.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()
send.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))
RabbitMQ—— http: //www.rabbitmq.com/configure.html
請參閱 frame_max。似乎預設支持 128KB。您可能需要在安裝中檢查該設置。
確保 rabbitmq 實際上正在偵聽埠 5672,並且該埠在您的 Linode 伺服器的防火牆中是打開的。
在您的配置中,RABBITMQ_NODE_IP_ADDRESS 應該是空白的,RABBITMQ_NODE_PORT 應該是 5672。