RabbitMQ的连接错误

时间:2016-01-13 06:07:43

标签: python rabbitmq pika

我是MQs和pika的新手。

当我尝试执行此代码(服务器代码)时,我收到错误: (我的接收器代码也出现了同样的错误。)

import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
     host="localhost:5672"))
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()

错误:

Traceback (most recent call last):
File "D:\Workspace\Luna_WS\MQ\RabbitMQ\Sample\Src\Sample.py", line 10, in <module>
host="localhost:5672"))
File "C:\Python34\lib\site-packages\pika\adapters\blocking_connection.py", line 339, in __init__
self._process_io_for_connection_setup()
File "C:\Python34\lib\site-packages\pika\adapters\blocking_connection.py", line 374, in _process_io_for_connection_setup
self._open_error_result.is_ready)
File "C:\Python34\lib\site-packages\pika\adapters\blocking_connection.py", line 395, in _flush_output
raise exceptions.ConnectionClosed()
pika.exceptions.ConnectionClosed

我安装了:(使用Windows 7,32位)

pikka package - pika-0.10.0-py2.py3-none-any.whl

Erlang - esl-erlang_18.2-1-windows_i386

RabbitMq服务器 - rabbitmq-server-3.6.0

1 个答案:

答案 0 :(得分:3)

尝试将主机拆分为单独的主机和端口连接参数:

connection = pika.BlockingConnection(
                 pika.ConnectionParameters(host="localhost", port=5672))