无法从另一个 docker 容器连接 ActiveMQ docker 容器

时间:2021-01-20 09:19:03

标签: spring-boot docker activemq

version: '3.9'
services:
activemq:
image: rmohr/activemq:5.15.9-alpine
restart: always
ports:
  - 61616:61616
  - 8161:8161
  - 5672:5672
container_name: activemq


app-service:
image: app-service:v1
restart: always
ports:
  - 8080:8080
container_name: app-service
links:
  - activemq
depends_on:
  - activemq

在我的应用服务中,我使用 Spring Boot spring.activemq.broker-url=tcp://activemq:61616 以及用户名和密码配置了 ActiveMQ 代理 URL。

当我尝试运行 docker-compose up 时,应用服务显示以下错误

DefaultMessageListenerContainer  : Could not refresh JMS Connection for   
destination 'queueName' - retrying using FixedBackOff{interval=5000,   
currentAttempts=5, maxAttempts=unlimited}. Cause:   Java.lang.NullPointerException.

我可以在浏览器上访问 ActiveMQ Web 控制台(例如使用 http://localhost:8161)。

如果没有 docker 容器,同样的代码在 localhost 中也能正常工作。

1 个答案:

答案 0 :(得分:0)

是的,主要原因是您的应用在 activemq 服务之前运行。 您可以尝试 docker-compose up 并在终端中查看控制台日志。

修正: 这还不是一个好主意,但是您可以转到 docker app 并使用您的应用程序容器的名称单击重新启动,然后一切都会正常进行。