gpt4 book ai didi

Docker、rabbitMQ 和 pike 连接被拒绝

转载 作者:行者123 更新时间:2023-12-04 08:26:52 25 4
gpt4 key购买 nike

我正在尝试使用 docker-compose 从 docker 内部连接到 rabbitMQ。从容器外运行的程​​序连接到“image:rabbitmq:3-management”没有问题。
没有设置密码或任何东西。
在查看更多错误消息后,似乎 pika 尝试使用 IPv6 而不是 IPv4 连接。查看文档,我想不出连接 IPv4 的方法。
失败发生在

self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))

Error log
rabbitMQ_1 | 2020-12-09 12:41:42.332 [info] <0.685.0> Ready to start client connection listeners
rabbitMQ_1 | 2020-12-09 12:41:42.333 [info] <0.988.0> started TCP listener on [::]:5672
listener_1 | ERROR:pika.adapters.utils.io_services_utils:Socket failed to connect: <socket.socket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 36782)>; error=111 (Connection refused)
listener_1 | ERROR:pika.adapters.utils.connection_workflow:TCP Connection attempt failed: ConnectionRefusedError(111, 'Connection refused'); dest=(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 5672))
listener_1 | ERROR:pika.adapters.utils.connection_workflow:AMQPConnector - reporting failure: AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused')
listener_1 | ERROR:pika.adapters.utils.io_services_utils:<socket.socket fd=9, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6, laddr=('::', 0, 0, 0)>.connect(('::1', 5672, 0, 0)) failed: OSError(99, 'Cannot assign requested address')
listener_1 | ERROR:pika.adapters.utils.connection_workflow:TCP Connection attempt failed: OSError(99, 'Cannot assign requested address'); dest=(<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 5672, 0, 0))
listener_1 | ERROR:pika.adapters.utils.connection_workflow:AMQPConnector - reporting failure: AMQPConnectorSocketConnectError: OSError(99, 'Cannot assign requested address')
listener_1 | ERROR:pika.adapters.utils.connection_workflow:AMQP connection workflow failed: AMQPConnectionWorkflowFailed: 2 exceptions in all; last exception - AMQPConnectorSocketConnectError: OSError(99, 'Cannot assign requested address'); first exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused').
listener_1 | ERROR:pika.adapters.utils.connection_workflow:AMQPConnectionWorkflow - reporting failure: AMQPConnectionWorkflowFailed: 2 exceptions in all; last exception - AMQPConnectorSocketConnectError: OSError(99, 'Cannot assign requested address'); first exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused')
listener_1 | ERROR:pika.adapters.blocking_connection:Connection workflow failed: AMQPConnectionWorkflowFailed: 2 exceptions in all; last exception - AMQPConnectorSocketConnectError: OSError(99, 'Cannot assign requested address'); first exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused')
listener_1 | ERROR:pika.adapters.blocking_connection:Error in _create_connection().
listener_1 | Traceback (most recent call last):
listener_1 | File "/usr/local/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
listener_1 | raise self._reap_last_connection_workflow_error(error)
listener_1 | pika.exceptions.AMQPConnectionError
docker-compose.yml
version: '3'
services:
rabbitMQ:
image: rabbitmq:3-management
ports:
- "15672:15672"
- "5672:5672"
login:
build:
context: .
dockerfile: Dockerfile.login
restart: on-failure
listener:
build:
context: .
dockerfile: Dockerfile.listener
restart: on-failure

最佳答案

docker-compose 没有设置本地主机网络。这意味着每个服务都有自己的名称。在这种情况下,应该更改主机。

self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))

should be changed to

self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='rabbitMQ'))

关于Docker、rabbitMQ 和 pike 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65217124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com