Microservice not able to connect to AXON Server running as docker image

Viewed 221

I have discovery service: https://github.com/Naresh-Chaurasia/API-MicroServices-Kafka/tree/master/Microservices-CQRS-SAGA-Kafka/DiscoveryService

I have product service: https://github.com/Naresh-Chaurasia/API-MicroServices-Kafka/tree/master/Microservices-CQRS-SAGA-Kafka/ProductsService

Following is my docker-compose.yml file: https://github.com/Naresh-Chaurasia/API-MicroServices-Kafka/tree/master/Microservices-CQRS-SAGA-Kafka/docker-compose.yml

version: "3.8"

services:

  axon-server:
    image: axoniq/axonserver
    container_name: axon-server
    ports:
      - 8124:8124
      - 8024:8024
    networks:
      - axon-demo

  discovery-service:
    build:
      context: ./DiscoveryService
    container_name: discovery-service
    ports:
      - 8010:8010
    networks:
      - axon-demo

networks:
  axon-demo:
    driver: bridge

When i run the following command docker-compose up, I get axon-server and discovery-service running.

I now run ProductService using the following file src/main/java/com/appsdeveloperblog/estore/ProductsService/ProductsServiceApplication.java which is under https://github.com/Naresh-Chaurasia/API-MicroServices-Kafka/tree/master/Microservices-CQRS-SAGA-Kafka/ProductsService.

It works fine.

The problem start when I try to run ProductService as a microservice, and it fails to connect to axon server. To do that I modify the docker-compose.yml as follows:

version: "3.8"

services:

  axon-server:
    image: axoniq/axonserver
    container_name: axon-server
    ports:
      - 8124:8124
      - 8024:8024
    networks:
      - axon-demo

  discovery-service:
    build:
      context: ./DiscoveryService
    container_name: discovery-service
    ports:
      - 8010:8010
    networks:
      - axon-demo

  product-service:
    build:
      context: ./ProductsService
    ports:
      - 8090:8090
    depends_on:
      - axon-server
      - discovery-service
    networks:
      - axon-demo

networks:
  axon-demo:
    driver: bridge

Now if I try to run docker-compose up, I get the following error:

product-service_1    | 2021-08-20 03:06:27.973  INFO 1 --- [@29db04f6c0a4-0] i.a.a.c.impl.AxonServerManagedChannel    : Requesting connection details from localhost:8124
product-service_1    | 2021-08-20 03:06:30.004  WARN 1 --- [@29db04f6c0a4-0] i.a.a.c.impl.AxonServerManagedChannel    : Connecting to AxonServer node [localhost:8124] failed: UNAVAILABLE: io exception

I have gone through the following link, Spring Boot Microservices are unable to connect to Axon Server, which looks like similar problem but still not able to fix my problem.

Please guide.

Thanks.

2 Answers

I made the following changes and it works fine now.

In the file ProductsService\src\main\resources\application.properties

Old Entry: eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka

New Entry: eureka.client.serviceUrl.defaultZone = http://discovery-service:8010/eureka

Added the following line in the above file: axon.axonserver.servers=axon-server:8124

In the File: Microservices-CQRS-SAGA-Kafka\docker-compose.yml

Old Entry: version: "3.8"

New Entry: version: "2"

Added following code in yml file

   product-service:
    build:
      context: ./ProductsService
    ports:
      - 8090:8090
    networks:
      - axon-demo

I have also checked in the code in git. The micro services can talk to each other, and connect to axon server and the problem reported earlier is resolved.

Thanks.

Just a thought. Try to add to each service in application.properties

axon.axonserver.servers=localhost:8124

and to each service which connects to axon-server in docker-compose.yml in environment variables section

axon-server:
    image: axoniq/axonserver
    container_name: axon-server
    ports:
      - 8124:8124
      - 8024:8024

product-service:
    ...
    environment:
      AXON_AXONSERVER_SERVERS: axon:8124
Related