- Overview
- What is Service Discovery?
- Quick Start
- Repository Structure
- Configuration Details
- How Microservices Connect
- Monitoring & Health Checks
- Troubleshooting
- Production Deployment
- Team Workflow
This repository contains the Eureka Service Discovery Server for the Yushan web novel platform. It acts as a centralized registry where all microservices register themselves and discover each other dynamically.
Without a service registry:
β User Service needs to know Content Service is at 192.168.1.100:8082
β If Content Service moves to 192.168.1.105:8082, everything breaks
β Hard to scale services (can't run multiple instances easily)
With Eureka:
β
User Service asks: "Where is content-service?"
β
Eureka responds: "Here are all available instances"
β
Automatic load balancing across multiple instances
β
Services can move/scale without manual configuration
Think of Eureka as a phone book for microservices:
-
Registration: When a service starts, it calls Eureka and says:
- "Hi! I'm
analytics-serviceand I'm available at192.168.1.100:8083"
- "Hi! I'm
-
Discovery: When a service needs to call another service:
- User Service: "Hey Eureka, where is
content-service?" - Eureka: "It's at
192.168.1.105:8082"
- User Service: "Hey Eureka, where is
-
Health Monitoring: Services send heartbeats every 30 seconds
- If Eureka doesn't receive a heartbeat, it removes the dead service
-
Load Balancing: If multiple instances exist:
- Eureka returns all available instances
- Client automatically distributes requests
- Java 21 (LTS) installed
- Maven 3.6+ or use the included Maven wrapper
- Docker & Docker Compose (optional, recommended)
# Clone the repository
git clone https://github.com/yourorg/yushan-platform-service-registry.git
cd yushan-platform-service-registry
# Start Eureka Server
docker-compose up -d
# View logs
docker-compose logs -f eureka-server
# Verify it's running
open http://localhost:8761# Clone the repository
git clone https://github.com/yourorg/yushan-platform-service-registry.git
cd yushan-platform-service-registry
# Run with Maven wrapper
./mvnw spring-boot:run
# Or with installed Maven
mvn spring-boot:run-
Dashboard: Open http://localhost:8761
- You should see the Eureka dashboard
- Initially, no services will be registered
-
Health Check:
curl http://localhost:8761/actuator/health
Expected response:
{"status":"UP"}
yushan-platform-service-registry/
βββ README.md # This file
βββ pom.xml # Maven configuration
βββ .gitignore # Git ignore rules
βββ Dockerfile # Docker image definition
βββ docker-compose.yml # Docker orchestration
βββ mvnw # Maven wrapper (Unix)
βββ mvnw.cmd # Maven wrapper (Windows)
βββ .mvn/ # Maven wrapper files
βββ src/
βββ main/
βββ java/
β βββ com/yushan/registry/
β βββ ServiceRegistryApplication.java # Main application
βββ resources/
βββ application.yml # Eureka configuration
| Setting | Value | Purpose |
|---|---|---|
server.port |
8761 | Standard Eureka port |
eureka.client.register-with-eureka |
false | Registry doesn't register with itself |
eureka.client.fetch-registry |
false | Registry doesn't fetch from itself |
eureka.server.enable-self-preservation |
false (dev) | Remove dead services quickly |
eureka.server.eviction-interval-timer-in-ms |
10000 | Check for dead services every 10s |
- Development: Disabled (removes dead services immediately)
- Production: MUST be enabled (handles network issues gracefully)
In your microservice's pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>In your microservice's application.yml:
spring:
application:
name: analytics-service # β οΈ IMPORTANT: This is your service name!
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/ # Eureka server URL
fetch-registry: true # Fetch other services
register-with-eureka: true # Register this service
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 30 # Send heartbeat every 30s
lease-expiration-duration-in-seconds: 90 # Remove if no heartbeat for 90sAdd annotation to your main application class:
@SpringBootApplication
@EnableDiscoveryClient // β Add this annotation
public class AnalyticsServiceApplication {
public static void main(String[] args) {
SpringApplication.run(AnalyticsServiceApplication.class, args);
}
}@FeignClient(name = "content-service") // Use service name from Eureka
public interface ContentClient {
@GetMapping("/api/novels/{id}")
NovelDTO getNovel(@PathVariable("id") Long id);
}Usage:
@Service
public class AnalyticsService {
@Autowired
private ContentClient contentClient;
public void analyzeNovel(Long novelId) {
// Feign automatically discovers content-service from Eureka
NovelDTO novel = contentClient.getNovel(novelId);
// ... your logic
}
}Access: http://localhost:8761
What You'll See:
- Instances currently registered with Eureka: List of all active services
- General Info: Eureka server status and configuration
- Instance Info: Detailed information about each service
- Status (UP/DOWN)
- IP Address
- Port
- Last heartbeat time
# Check Eureka server health
curl http://localhost:8761/actuator/health
# Check specific service (example)
curl http://localhost:8761/eureka/apps/ANALYTICS-SERVICE# View container health status
docker ps
# View detailed health logs
docker inspect yushan-eureka-registrySymptoms:
- Service starts successfully
- Eureka dashboard shows no registered instances
Solutions:
- Verify
@EnableDiscoveryClientannotation exists - Check
eureka.client.serviceUrl.defaultZonepoints to correct URL - Ensure Eureka server is running: http://localhost:8761
- Check application logs for connection errors
- Verify network connectivity (especially in Docker)
# Check if service can reach Eureka
curl http://localhost:8761/eureka/apps
# View service logs
docker-compose logs -f [service-name]Symptoms:
- Service appears in Eureka but status is DOWN
- Red status indicator in dashboard
Solutions:
- Check service health endpoint:
curl http://[service-ip]:[service-port]/actuator/health
- Verify firewall rules allow traffic on service port
- Check if service is actually running:
docker ps # or ps aux | grep java
- Review heartbeat configuration:
eureka: instance: lease-renewal-interval-in-seconds: 30
Symptoms:
- Dead services still appear in Eureka
- Requests fail because service no longer exists
Solutions:
- Check if self-preservation mode is enabled:
eureka: server: enable-self-preservation: false # Development only
- Adjust eviction interval:
eureka: server: eviction-interval-timer-in-ms: 10000 # Check every 10s
- Restart Eureka server to clear cache:
docker-compose restart eureka-server
Symptoms:
Port 8761 is already in use
Solutions:
- Find process using port 8761:
# macOS/Linux lsof -i :8761 # Windows netstat -ano | findstr :8761
- Kill the process or use a different port:
# application.yml server: port: 8762 # Change to different port
Symptoms:
- Container exits immediately
docker psshows no eureka-server
Solutions:
- View container logs:
docker-compose logs eureka-server
- Check if port is already mapped:
docker ps -a
- Rebuild image:
docker-compose down docker-compose build --no-cache docker-compose up -d
eureka:
server:
enable-self-preservation: trueWhy? Prevents removing services during network issues.
Protect the Eureka dashboard with authentication:
Add dependency to pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>Configure in application.yml:
spring:
security:
user:
name: admin
password: ${EUREKA_PASSWORD} # Use environment variableUpdate clients:
eureka:
client:
serviceUrl:
defaultZone: http://admin:${EUREKA_PASSWORD}@eureka-server:8761/eureka/Run 2-3 Eureka servers for redundancy:
Eureka Server 1:
eureka:
client:
serviceUrl:
defaultZone: http://eureka-server-2:8761/eureka/,http://eureka-server-3:8761/eureka/Eureka Server 2:
eureka:
client:
serviceUrl:
defaultZone: http://eureka-server-1:8761/eureka/,http://eureka-server-3:8761/eureka/Eureka Server 3:
eureka:
client:
serviceUrl:
defaultZone: http://eureka-server-1:8761/eureka/,http://eureka-server-2:8761/eureka/Replace localhost with actual hostnames or IPs:
eureka:
instance:
hostname: eureka.yushan.com # Production hostname
prefer-ip-address: falseAdd resource constraints in docker-compose.yml:
services:
eureka-server:
# ... other config
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M# 1. Clone the registry repository
git clone https://github.com/yourorg/yushan-platform-service-registry.git
cd yushan-platform-service-registry
# 2. Start Eureka (keep it running)
docker-compose up -d
# 3. Verify it's working
open http://localhost:8761-
Start Eureka (if not already running):
cd yushan-platform-service-registry docker-compose start -
Start your microservice (it will auto-register):
cd yushan-analytics-service ./mvnw spring-boot:run -
Check registration:
- Open http://localhost:8761
- Your service should appear in the list
-
Stop services at end of day:
# Stop your microservice (Ctrl+C) # Stop Eureka (optional) cd yushan-platform-service-registry docker-compose stop
# 1. Pull latest changes
git pull origin main
# 2. Rebuild Docker image
docker-compose down
docker-compose build --no-cache
docker-compose up -d
# 3. Verify
open http://localhost:8761 βββββββββββββββββββββββββββββββ
β Eureka Service Registry β
β localhost:8761 β
ββββββββββββββββ¬βββββββββββββββ
β
ββββββββββββββββ΄βββββββββββββββ
β Service Registration & β
β Discovery Layer β
ββββββββββββββββ¬βββββββββββββββ
β
ββββββββββββ¬ββββββββββββββββΌββββββββββββββββ¬βββββββββββ
β β β β β
βΌ βΌ βΌ βΌ βΌ
ββββββββββ βββββββββββ ββββββββββββββ ββββββββββββ ββββββββββββ
β User β β Content β β Engagement β βGamifica- β βAnalytics β
βService β β Service β β Service β β tion β β Service β
β :8081 β β :8082 β β :8084 β β Service β β :8083 β
ββββββββββ βββββββββββ ββββββββββββββ β :8085 β ββββββββββββ
β β β ββββββββββββ β
ββββββββββββ΄βββββββββββββββ΄βββββββββββββββββββββββββββ
Inter-service Communication
(via Feign Clients)
Flow:
- All services register with Eureka on startup
- Services send heartbeat every 30 seconds
- When Service A needs Service B:
- A asks Eureka: "Where is service-b?"
- Eureka returns: "service-b is at IP:PORT"
- A calls B using that address
- If Service B crashes or moves, Eureka updates automatically
- Spring Cloud Netflix: https://spring.io/projects/spring-cloud-netflix
- Eureka Documentation: https://cloud.spring.io/spring-cloud-netflix/reference/html/
- Service Discovery Pattern: https://microservices.io/patterns/service-registry.html
- Docker Compose: https://docs.docker.com/compose/
- Check the Dashboard: http://localhost:8761
- View Logs:
# Docker docker-compose logs -f eureka-server # Maven tail -f logs/spring.log
- Check Health:
curl http://localhost:8761/actuator/health
- Contact Team:
- Slack: #yushan-platform-dev
- Email: platform-team@yushan.com
This project is licensed under the MIT License - see the LICENSE file for details.
- Netflix OSS for Eureka
- Spring Cloud Team for the integration
- Yushan Platform Team for building awesome microservices!
Made with β€οΈ by Yushan Platform Team
Last Updated: October 2025