Spring / RabbitMQ教程的Docker映像导致连接被拒绝 [英] Docker image for Spring/RabbitMQ tutorial results in connection refused

查看:98
本文介绍了Spring / RabbitMQ教程的Docker映像导致连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这里浏览Spring教程;

I'm working through the Spring tutorial here;

使用RabbitMQ进行消息

我发现了这个问题,但没有解决关于 docker-在教程中找到了compose.yml 文件;

I found this question but it did not address my query regarding the docker-compose.yml file found in the tutorial;

Spring RabbitMQ tutorial results in Connection Refused error

我已经完成了所有必要的步骤直到应用程序实际运行为止,这时我收到 ConnectException 异常,表明服务器未在运行或运行不正常。

I've completed all necessary steps up until the actual running of the application, at which point I'm getting ConnectException exceptions suggesting that the server is not running or not running correctly.

在教程中指定的docker-compose.yml文件如下;

The docker-compose.yml file specified in the tutorial is as follows;

rabbitmq:
image: rabbitmq:management
ports:
  - "5672:5672"
  - "15672:15672"

基本上,我不确定这个docker-compose文件的实际作用,因为它似乎没有按照教程的建议设置RabbitMQ服务器(或者至少不是按照教程的预期设置)。我也是Docker的新手,所以也许我误以为这个文件会运行RabbitMQ服务器的新实例。

Basically I am unsure what this docker-compose file actually does, because it doesn't seem to set up the RabbitMQ server as the tutorial suggests (or at least not in the way the tutorial expects). I'm quite new to Docker also so perhaps I am mistaken in thinking this file would run a new instance of the RabbitMQ server.

当我运行 docker-compose up 我得到以下控制台输出;

When I run docker-compose up I get the following console output;

rabbitmq_1  |
rabbitmq_1  | =INFO REPORT==== 28-Jun-2017::13:27:26 ===
rabbitmq_1  | Starting RabbitMQ 3.6.10 on Erlang 20.0-rc2
rabbitmq_1  | Copyright (C) 2007-2017 Pivotal Software, Inc.
rabbitmq_1  | Licensed under the MPL.  See http://www.rabbitmq.com/
rabbitmq_1  |
rabbitmq_1  |               RabbitMQ 3.6.10. Copyright (C) 2007-2017            Pivotal Software, Inc.
rabbitmq_1  |   ##  ##      Licensed under the MPL.  See  http://www.rabbitmq.com/
rabbitmq_1  |   ##  ##
rabbitmq_1  |   ##########  Logs: tty
rabbitmq_1  |   ######  ##        tty
rabbitmq_1  |   ##########
rabbitmq_1  |               Starting broker...
rabbitmq_1  |
rabbitmq_1  | =INFO REPORT==== 28-Jun-2017::13:27:26 ===
rabbitmq_1  | node           : rabbit@bd20dc3d3d2a
rabbitmq_1  | home dir       : /var/lib/rabbitmq
rabbitmq_1  | config file(s) : /etc/rabbitmq/rabbitmq.config
rabbitmq_1  | cookie hash    : DTVsmjdKvD5KtH0o/OLVJA==
rabbitmq_1  | log            : tty
rabbitmq_1  | sasl log       : tty
rabbitmq_1  | database dir   : /var/lib/rabbitmq/mnesia/rabbit@bd20dc3d3d2a

... INFO报告。这使我相信RabbitMQ服务器已启动并正在运行,但是显然无法连接。

...plus a load of INFO reports. This led me to believe that the RabbitMQ server was up and running, but apparently not as I cannot connect.

我要使其正常工作的唯一方法是手动安装Erlang和RabbitMQ(在Windows系统上)确实可以使我完成本教程。

The only way I have gotten this to work is by manually installing Erlang and RabbitMQ (on a Windows system here) which does appear to let me complete the tutorial.

为什么在本教程中甚至提到Docker? docker-compose.yml 似乎没有按照本教程的建议执行。

Why is Docker even mentioned in this tutorial though? The docker-compose.yml does not appear to do what the tutorial suggests.

此文件实际上在这里做什么?就本教程而言,如何在docker容器中运行RabbitMQ?这是端口号的问题吗?

What is this file actually doing here and how would one run RabbitMQ in a docker container for the purposes of this tutorial? Is this an issue with port numbers?

推荐答案

事实证明,问题出在Spring RabbitMQ模板连接信息上。

It turns out the issue was with the Spring RabbitMQ template connection information.

Spring教程假定使用RabbitMQ(加上Erlang)的常规手动安装,并且RabbitMQ Spring模板使用一些与<$中的映像不兼容的默认连接参数在教程中指定的c $ c> docker-compose 文件。

The Spring tutorial assumes the use of the normal, manual installation of RabbitMQ (plus Erlang) and the RabbitMQ Spring template uses some default connection parameters that are not compatible with the image in docker-compose file specified in the tutorial.

要解决此问题,我需要添加一个Spring application.properties 文件,并将其添加到我的应用程序目录结构中的资源文件夹中。接下来,我需要使用以下命令找到我的Docker容器的IP地址;

To solve this I needed to add an Spring application.properties file and add it to the resources folder in my application directory structure. Next I needed to find the IP address of my Docker container using the following command;

docker-machine ip

这将提供IP地址。我在 application.properties 文件中添加了以下参数;

which will gives the IP address. I added the following parameters to the application.properties file;

spring.rabbitmq.host={docker-machine ip address}
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

此处的端口,用户名和密码均为默认值,可在RabbitMQ文档中找到。

The port, username and password here are all defaults and can be found in the RabbitMQ documentation.

这样做,我能够使我的应用程序正确连接到运行在Docker容器中的RabbitMQ服务器。

Doing this I was able to have my application connect correctly to the RabbitMQ server running in the Docker container.

看来Spring教程是稍微不完整,因为它不会通知读者在本教程其余部分假设的RabbitMQ手动安装上使用RabbitMQ docker-compose 文件时,需要执行一些额外的步骤。

It appears the Spring tutorial is slightly incomplete as it does not inform the reader that some extra steps are required when using the RabbitMQ docker-compose file over the manual installation of RabbitMQ that the rest of the tutorial assumes.

这篇关于Spring / RabbitMQ教程的Docker映像导致连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆