Service Discovery
Service Discovery with Eureka
10-15 min
Service Discovery with Eureka
Service discovery is an essential component of a microservices architecture. Netflix Eureka makes it possible to manage service registration and discovery efficiently.
1. Eureka Server Configuration
1.1 Project Creation
curl https://start.spring.io/starter.tgz \
-d dependencies=cloud-eureka-server \
-d groupId=com.example \
-d artifactId=eureka-server \
-d name=eureka-server \
-d description=Eureka%20Server%20for%20Microservices \
-d packageName=com.example.eureka \
-d packaging=jar \
-d javaVersion=17 \
| tar -xzvf -
1.2 Server Configuration
# application.yml
server:
port: 8761
spring:
application:
name: eureka-server
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
1.3 High Availability Configuration
# application-peer1.yml
spring:
application:
name: eureka-server
profiles: peer1
server:
port: 8761
eureka:
instance:
hostname: peer1
client:
service-url:
defaultZone: http://peer2:8762/eureka/
---
# application-peer2.yml
spring:
application:
name: eureka-server
profiles: peer2
server:
port: 8762
eureka:
instance:
hostname: peer2
client:
service-url:
defaultZone: http://peer1:8761/eureka/
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion