Docker image for Spring/RabbitMQ tutorial results

2019-07-27 09:26发布

I'm working through the Spring tutorial here;

Messaging with RabbitMQ

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

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.

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

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

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.

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

...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.

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.

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

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?

2条回答
我想做一个坏孩纸
2楼-- · 2019-07-27 10:03

From what I know, it is not possible to know all the time the IP address and you should instead of the ip address, provide the DNS which is the name of the rabbitmq server defined in your docker-compose file.

查看更多
我想做一个坏孩纸
3楼-- · 2019-07-27 10:08

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

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.

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

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

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

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

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.

查看更多
登录 后发表回答