Sureshkumar Suruli
Sureshkumar Suruli

Reputation: 1

Not able to connect ActiveMQ docker container from another docker container

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

In my app service I've configured the ActiveMQ broker URL using Spring Boot spring.activemq.broker-url=tcp://activemq:61616 and also username and password.

When I am trying to run docker-compose up the app service showing below error

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

I can access the ActiveMQ web console on browser (e.g. using http://localhost:8161).

Without docker container the same code is working fine in localhost.

Upvotes: 0

Views: 3241

Answers (2)

Maxim Grin
Maxim Grin

Reputation: 11

I also had this exact problem and what helped me is adding spring.activemq.broker-url=tcp://activemq:61616 to docker-compose for app environment tag. For me it's like that:

  app:
    build:
      context: .
    container_name: app
    ports:
      - 8080:8080
    environment:
      - spring.activemq.broker-url=tcp://activemq:61616
    depends_on:
      - activemq

I think containerized spring app doesn't see broker-url from app properties for whatever reason

Upvotes: 1

user3400136
user3400136

Reputation: 1

Yes, The big reason is your app run before activemq service. You can try docker-compose up and see the console log in terminal.

Fixed: It is not a good idea yet,but you can go to docker app and click on restart with you app container's name and then everything will work.

Upvotes: 0

Related Questions