【问题标题】:I can't connect to Rabbitmq server port 5672我无法连接到 Rabbitmq 服务器端口 5672
【发布时间】:2017-02-09 12:50:36
【问题描述】:

用这个命令

php bin/console rabbitmq:consumer -w upload_picture

我有这个问题。

 [ErrorException]
stream_socket_client(): unable to connect to tcp://localhost:5672 (Aucune
 connexion n'a pu etre établie car l'ordinateur cible lÆa expressÚment
 refusée.

所以我无法连接到服务器rabbitmq

config.yml

old_sound_rabbit_mq:
connections:
    default:
        host:     'localhost' # hostname and port of the rabbitmq server
        port:     5672
        user:     'guest'
        password: 'guest'
        vhost:    '/'
        lazy:     true # a lazy connection avoids unnecessary connections to the broker on every request
        connection_timeout: 3
        read_write_timeout: 3
        keepalive: false
        heartbeat: 0
producers:
    upload_picture:
        connection:       default # connects to the default connection configured above
        exchange_options: {name: 'upload_picture', type: direct}
consumers:
    upload_picture:
        connection:       default # connects to the default connection configured above
        exchange_options: {name: 'upload_picture', type: direct}
        queue_options:    {name: 'upload_picture'}
        callback:         upload_picture_service # the UploadPictureConsumer defined below

【问题讨论】:

  • 你的命令连接到localhost,如果你的5672端口不是宿主机上的容器发布的,就会失败。显示docker port your_rabbitmq_container,这里是文档docs.docker.com/engine/reference/commandline/port
  • 在 rabbitmq 机器上,输入 netstat -a 并确保它正在侦听该端口,而不仅仅是在 unix 套接字上。
  • 列表中不存在5672端口(netstat -a)
  • with is command docker ps 7c01193b2f74 projecttest_queue "docker-entrypoint..." 24 小时前 Up 5 hours 4369/tcp, 5671/tcp, 25672/tcp, 0.0. 0.0:55672->5672/tcp, 0.0.0.0:32768->15672/tcp projecttest_queue_1
  • 将 localhost 替换为容器的名称(从您的评论看来是 projecttest_queue)

标签: docker rabbitmq symfony


【解决方案1】:

根据您的评论

7c01193b2f74 projecttest_queue "docker-entrypoint..." 24 hours ago Up 5 hours 4369/tcp, 5671/tcp, 25672/tcp, 0.0.0.0:55672->5672/tcp, 0.0.0.0:32768->15672/tcp

项目正在侦听的端口是 55672 - 请参阅 0.0.0.0:55672->5672/tcp

因此您需要更新您的 php 项目以连接到 localhost:55672 而不仅仅是 localhost:5672

【讨论】:

  • 不幸的是 55672 有同样的问题
  • 在这种情况下,检查 rabbitmq 服务器正在侦听的 IP。如果您提供的config.yml 来自rabbitmq 服务器,那么您需要将主机更改为0.0.0.0,以便rabbitmq DOES NOT 监听localhost,因为它无法从外部访问码头集装箱
【解决方案2】:

你可以直接找到你需要连接的端口

docker inspect --format '{{ (index (index .NetworkSettings.Ports "5672/tcp") 0).HostPort }}' rabbitmq_container

有关如何从docker inspect 获取特定值的更多详细信息,请参阅How to get ENV variable when doing Docker Inspect

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 2013-08-21
    • 2021-11-20
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多