AxonIQ/axon-server-se

Spring Boot Microservices are unable to connect to Axon Server

alibehzadian opened this issue · 1 comments

I have a Spring Boot microservices project with three microservices to test saga pattern for distributed transactions management.

When I run Axon Server locally with java -jar axonserver.jar and spring boot microservices with mvn spring-boot:run, everything is ok and I can see all microservices in Axon Server dashboard.

I have added Docker file for microservices and a docker-compose.yml into project to run the whole project with docker-compose. Here is my docker-compose.yml file:

version: '3.8'

services:
  ##
  ## Axon Server
  ##
  axonserver:
    image: axoniq/axonserver
    hostname: axonserver
    container_name: axonserver
    volumes:
      - type: bind
        source: ./data
        target: /data
      - type: bind
        source: ./events
        target: /eventdata
      - type: bind
        source: ./config
        target: /config
        read_only: true
    ports:
      - '8024:8024'
      - '8124:8124'
      - '8224:8224'
    networks:
      - axon-demo      

  ##
  ## Order Service
  ## 
  order-service:
    container_name: "order-service"
    build:
      context: ./order-service
    environment:
      - "AXONSERVER_HOST:axonserver:8124"      
    ports:
      - "8080:8080"
    depends_on:
      - axonserver
    networks:
      - axon-demo      

  ##
  ## Payment Service
  ##
  payment-service:
    container_name: "payment-service"
    build:
      context: ./payment-service
    ports:
      - "8081:8081"
    depends_on:
      - axonserver
    networks:
      - axon-demo      

  ##
  ## Shipping Service
  ##
  shipping-service:
    container_name: "shipping-service"
    build:
      context: ./shipping-service
    ports:
      - "8082:8082"
    depends_on:
      - axonserver
    networks:
      - axon-demo      

networks:
  axon-demo:
    driver: bridge 

I also added axon-server to application.properties of all microservices as below:

axon.axonserver.servers=${AXONSERVER_HOST:localhost:8124}
## OR
axon.axonserver.servers=axonserver 
## OR
axon.axonserver.servers=axonserver:8124

axonserver.properties located in ./config:

axoniq.axonserver.name=axonserver
axoniq.axonserver.hostname=axonserver

After running docker-compose up --build command, microservices are unable to connect to the Axon server and I get this error:

order-service       | 2021-07-10 15:01:01.199  WARN 1 --- [rverConnector-0] o.a.a.c.AxonServerConnectionManager      : Connecting to AxonServer node localhost:8124 failed: UNAVAILABLE: io exception

My question is why microservices are looking for axon server in localhost:8124 that is obviously wrong and is against their configurations in application.properties.

Ali,
I have also replied to your Stackoverflow question:
Your properties file contains the following:

axon.axonserver.servers=${AXONSERVER_HOST:axonserver:8124}

Please try it without the ":8124":

axon.axonserver.servers=${AXONSERVER_HOST:axonserver}

I think Spring boot is confused by the double ":". Port 8124 is the default for Axon Server connections, so you can leave it out without problems.