RabbitMQ经纪人在不同的机器上

时间:2014-05-08 01:17:24

标签: python rabbitmq

rabbitMQ教程部分中的hello world example,只要求使用不同机器的ip更改主机名。但那不适合我。我试过了 Binding external IP address to Rabbit MQ server 但那并没有奏效。我还需要对配置文件或代码做些什么吗?

这是发送代码

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
    host='ip_address'))
channel = connection.channel()

channel.queue_declare(queue='hello')

channel.basic_publish(exchange='',
                  routing_key='hello',
                  body='Hello World!')
print " [x] Sent 'Hello World!'"
connection.close()

我接收的代码是我在另一台机器上运行的

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
    host='ip_address'))
channel = connection.channel()

channel.queue_declare(queue='hello1')

print ' [*] Waiting for messages. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] Received %r" % (body,)

channel.basic_consume(callback,
                  queue='hello',
                  no_ack=True)

channel.start_consuming()

我得到的错误是

No handlers could be found for logger "pika.adapters.base_connection"
Traceback (most recent call last):

File "send.py", line 25, in <module>
'ip_address'))
 File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py",    line 107, in __init__
   super(BlockingConnection, self).__init__(parameters, None, False)
 File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 62, in __init__
on_close_callback)
 File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 590, in __init__
self.connect()
 File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 206, in connect
   if not self._adapter_connect():
 File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 275, in _adapter_connect
raise exceptions.AMQPConnectionError(1)
pika.exceptions.AMQPConnectionError: 1

我感谢你们花时间帮助我。