I’m working on a Spring Boot microservices application and have dockerized all the services. While all the services appear to be running, I’m encountering an issue when trying to access the endpoints via the API Gateway.
Error Message:
{
"timestamp": "2024-06-24T14:01:32.938+00:00",
"path": "/departments",
"status": 503,
"error": "Service Unavailable",
"requestId": "1a88ca39-1"
}
Problem Description:
The Eureka server (service-registry) only registers the API Gateway and not the other services (department-service
, employee-service
, and project-service
). This makes me think that the API Gateway can’t find the services, or the services are not set up correctly to fetch the configuration from the config-server
which is other independent service.
Configuration Files:
Service Registry (Eureka) Config:
server:
port: 8761
spring:
application:
name: service-registry
eureka:
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://service-registry:8761/eureka/
API Gateway Config:
server:
port: 8060
eureka:
client:
serviceUrl:
defaultZone: http://service-registry:8761/eureka/
spring:
application:
name: api-gateway
cloud:
gateway:
routes:
- id: employee-service
uri: lb://employee-service
predicates:
- Path=/employees/**
- id: department-service
uri: lb://department-service
predicates:
- Path=/departments/**
- id: project-service
uri: lb://project-service
predicates:
- Path=/projects/**
Department Config:
spring:
application:
name: department-service
config:
import: "optional:configserver:http://config-server:8088"
Employee and Project Config is just same with department just different app name:
Config Server Config:
server:
port: 8088
spring:
application:
name: config-server
profiles:
active: native
cloud:
config:
server:
native:
search-locations: classpath:/config
Config Server Department Config:
eureka:
client:
serviceUrl:
defaultZone: http://service-registry:8761/eureka/
spring:
application:
name: department-service
datasource:
url: jdbc:jdbc:postgresql://postgres:5432/microservice_comp_data
username: postgres
password: password
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
server:
error:
include-message: always
port: 8081
management:
tracing:
sampling:
probability: 1.0
Config Server Employee and Project is just same with department just different app name:
Docker Compose:
version: '3.8'
services:
config-server:
build:
context: ./config-server
ports:
- "8088:8088"
service-registry:
build:
context: ./service-registry
ports:
- "8761:8761"
depends_on:
- config-server
department-service:
build:
context: ./department-service
ports:
- "8081:8081"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/microservice_comp_data
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: password
depends_on:
- service-registry
- postgres
employee-service:
build:
context: ./employee-service
ports:
- "8082:8082"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/microservice_comp_data
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: password
depends_on:
- department-service
project-service:
build:
context: ./project-service
ports:
- "8083:8083"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/microservice_comp_data
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: password
depends_on:
- employee-service
api-gateway:
build:
context: ./api-gateway
ports:
- "8060:8060"
depends_on:
- service-registry
postgres:
image: postgres:latest
container_name: postgres-container
environment:
POSTGRES_DB: microservice_comp_data
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports:
- "5431:5432"
zipkin:
image: openzipkin/zipkin
ports:
- "9411:9411"
I’ve double-checked the configurations and logs, but I can’t seem to pinpoint the issue. Any guidance on what might be wrong or how to properly configure these microservices would be greatly appreciated.