我已经通过WSl(与商店)在Ubuntu 18.4上安装了RabbitMq。下载了最后一个稳定的发行版,如deb,然后下载了sudo apt-get install -f来修复依赖性。 然后,使用RabbitMq网站的第一个示例创建一个.py文件:
import logging
import pika
logging.basicConfig(level=logging.DEBUG)
connection =
pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
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()
但出现以下错误(在Ubuntu或Windows中运行):
coval@LAPTOP-PVGUIGKO:~/work/testMQ$ python3 send.py
DEBUG:pika.adapters.select_connection:Using EPollPoller
DEBUG:pika.callback:Added: {'callback': <bound method Connection._on_connection_start of <SelectConnection CLOSED socket=None params=<ConnectionParameters host=localhost port=5672 virtual_host=/ ssl=False>>>, 'one_shot': True, 'only': None, 'arguments': None, 'calls': 1}
DEBUG:pika.callback:Added: {'callback': <bound method Connection._on_connection_close of <SelectConnection CLOSED socket=None params=<ConnectionParameters host=localhost port=5672 virtual_host=/ ssl=False>>>, 'one_shot': True, 'only': None, 'arguments': None, 'calls': 1}
DEBUG:pika.callback:Added: {'callback': <bound method _CallbackResult.set_value_once of <pika.adapters.blocking_connection._CallbackResult object at 0x7fa7c6057d88>>, 'one_shot': False, 'only': None, 'arguments': None}
DEBUG:pika.callback:Added: {'callback': <bound method _CallbackResult.set_value_once of <pika.adapters.blocking_connection._CallbackResult object at 0x7fa7c6057e08>>, 'one_shot': False, 'only': None, 'arguments': None}
DEBUG:pika.callback:Added: {'callback': <bound method _CallbackResult.set_value_once of <pika.adapters.blocking_connection._CallbackResult object at 0x7fa7c3e5fe08>>, 'one_shot': False, 'only': None, 'arguments': None}
DEBUG:pika.adapters.select_connection:call_later: added timeout <pika.adapters.select_connection._Timeout object at 0x7fa7c31fe978> with deadline=1529463117.2377074 and callback=<bound method Connection._on_connect_timer of <SelectConnection INIT socket=None params=<ConnectionParameters host=localhost port=5672 virtual_host=/ ssl=False>>>; now=1529463117.2377074; delay=0
INFO:pika.adapters.base_connection:Pika version 0.12.0 connecting to 127.0.0.1:5672
ERROR:pika.adapters.base_connection:Read empty data, calling disconnect
INFO:pika.connection:Disconnected from RabbitMQ at localhost:5672 (-1): EOF
ERROR:pika.connection:Incompatible Protocol Versions
ERROR:pika.connection:Connection setup failed due to The protocol returned by the server is not supported: (-1, 'EOF')
DEBUG:pika.callback:Processing 0:_on_connection_error
DEBUG:pika.callback:Calling <bound method _CallbackResult.set_value_once of <pika.adapters.blocking_connection._CallbackResult object at 0x7fa7c6057d88>> for "0:_on_connection_error"
DEBUG:pika.callback:Processing 0:_on_connection_closed
DEBUG:pika.callback:Calling <bound method _CallbackResult.set_value_once of <pika.adapters.blocking_connection._CallbackResult object at 0x7fa7c3e5fe08>> for "0:_on_connection_closed"
DEBUG:pika.callback:Incremented callback reference counter: {'callback': <bound method Connection._on_connection_start of <SelectConnection CLOSED socket=None params=<ConnectionParameters host=localhost port=5672 virtual_host=/ ssl=False>>>, 'one_shot': True, 'only': None, 'arguments': None, 'calls': 2}
DEBUG:pika.callback:Incremented callback reference counter: {'callback': <bound method Connection._on_connection_close of <SelectConnection CLOSED socket=None params=<ConnectionParameters host=localhost port=5672 virtual_host=/ ssl=False>>>, 'one_shot': True, 'only': None, 'arguments': None, 'calls': 2}
ERROR:pika.adapters.blocking_connection:Connection open failed - The protocol returned by the server is not supported: (-1, 'EOF')
Traceback (most recent call last):
File "send.py", line 7, in <module>
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
File "/home/coval/.local/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 377, in __init__
self._process_io_for_connection_setup()
File "/home/coval/.local/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 417, in _process_io_for_connection_setup
self._open_error_result.is_ready)
File "/home/coval/.local/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 469, in _flush_output
raise maybe_exception
pika.exceptions.IncompatibleProtocolError: (-1, 'EOF')
{
"rabbit_version": "3.7.6",
"users": [
{
"name": "guest",
"password_hash": "0OxxjMIoTzeL48fpAUU12wXwOqX3ZOJCrU2f76TlneyB8TGJ",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [{ "name": "/" }],
"permissions": [
{
"user": "guest",
"vhost": "/",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"topic_permissions": [],
"parameters": [],
"global_parameters": [
{ "name": "cluster_name", "value": "rabbit@LAPTOP-PVGUIGKO.localdomain" }
],
"policies": [],
"queues": [],
"exchanges": [],
"bindings": []
}
有什么特别的配置吗?