作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在使用 pika 从 Python 代码连接到 dockerized RabbitMQ 时遇到了问题。我正在使用此代码连接到队列:
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=2)
def rabbit_connect():
connection_uri = cfg.get("System", "rabbit_uri", raw=True)
queue = cfg.get("System", "queue")
username = cfg.get("System", "username")
password = cfg.get("System", "password")
host = cfg.get("System", "rabbit_host")
port = cfg.get("System", "rabbit_port")
credentials = pika.PlainCredentials(username, password)
log.info("Connecting queue %s at %s:%s", queue, host, port)
connection = None
try:
connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=host, port=int(port)))
except Exception, e:
log.error("Can't connect to RabbitMQ")
log.error(e.message)
raise
这些是我的 docker 容器:
root@pc:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2063ad939823 rabbitmq:3-management "/docker-entrypoint.s" About an hour ago Up About an hour 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080->15672/tcp new-rabbitmg
94628f1fb33f rabbitmq "/docker-entrypoint.s" About an hour ago Up About an hour 4369/tcp, 5671-5672/tcp, 25672/tcp new-rabbit
当我尝试使用任何可用凭据连接到 localhost:8080 时,pika 会重试连接,直到出现错误:
Traceback (most recent call last):
File "script.py", line 146, in worker
connection = rabbit_connect()
File "build/bdist.linux-x86_64/egg/retrying.py", line 49, in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
File "build/bdist.linux-x86_64/egg/retrying.py", line 212, in call
raise attempt.get()
File "build/bdist.linux-x86_64/egg/retrying.py", line 247, in get
six.reraise(self.value[0], self.value[1], self.value[2])
File "build/bdist.linux-x86_64/egg/retrying.py", line 200, in call
attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
File "script.py", line 175, in rabbit_connect
connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=host, port=int(port)))
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 339, in __init__
self._process_io_for_connection_setup()
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 374, in _process_io_for_connection_setup
self._open_error_result.is_ready)
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 410, in _flush_output
self._impl.ioloop.poll()
File "build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py", line 602, in poll
self._process_fd_events(fd_event_map, write_only)
File "build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py", line 443, in _process_fd_events
handler(fileno, events, write_only=write_only)
File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 364, in _handle_events
self._handle_read()
File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 412, in _handle_read
return self._handle_disconnect()
File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 288, in _handle_disconnect
self._adapter_disconnect()
File "build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py", line 95, in _adapter_disconnect
super(SelectConnection, self)._adapter_disconnect()
File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 154, in _adapter_disconnect
self._check_state_on_disconnect()
File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 169, in _check_state_on_disconnect
raise exceptions.IncompatibleProtocolError
IncompatibleProtocolError
这是某种错误吗?还是我做错了什么?
最佳答案
您已经将localhost:8080 映射到docker 容器(new-rabbitmq)的15672 端口,这实际上是webui 管理的端口。 amqp通信的端口是5672或5671。
关于python - 尝试连接到 RabbitMQ 时出现 IncompatibleProtocolError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35773789/
我正在构建一个 docker-compose 文件。我启动了一个 RabbitMQ 容器并将必要的端口绑定(bind)到主机。然后我试图从另一个容器连接到它。 因此,我设置了 network_mode
我在使用 pika 从 Python 代码连接到 dockerized RabbitMQ 时遇到了问题。我正在使用此代码连接到队列: @retry(wait_exponential_multiplie
我是一名优秀的程序员,十分优秀!