Now just talk about different concept of configuration -
Eureka
also called passive service discovery
Task:
- Build and Run Spring cloud Eureka Server
- Build and Run and Configure a Eureka Client
Service Discovery
➤Microservices architecture results in large number of inter-service calls
➥this is challenging to configure
➤ How can one application easily find all of the other runtime dependencies
-manual configuration - not good
➤Service discovery provides a single 'lookup service'
clients register themselves,discover other registrants
- what could be possible solutions?
- Eureka,Consul,Zookeeper,SmartStack etc
Eureka -Service Discovery Server and client
➤Eureka provides a look up server
➥generally made highly available by multiple copies
➥copies replicate state of registered server
➤"Client" services register with Eureka
➥ provides metadata on host,port,health indicator ,URL ,etc.
➤Client services send heartbeat to Eureka
➥ Eureka removes services without any heartbeat
Creating Eureka Server
➤Multiple Eureka server should be running simultaneously
➥otherwise you will get many warnings in the log
there are share states and eureka server communicate with each other to share state
➥provides highly availability
➤ Each server should know url of each others
- can be provided by config server
- One server(JAR),multiple profiles
Shared states
⬈
Eureka Server ⟷ Eureka server ⟷ Eureka server
🔻 🔻 🔻
Region: us east Region: Us west Region: EU
Create a Spring Cloud Eureka Server and Client
➤ Create a new Spring Boot application.
➤ from spring cloud discovery select eureka server
below is the genrated pom for the same.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.demo</groupId>
<artifactId>lab-eureka-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lab-eureka-server</name>
<description>spring config server</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
➤Save an application.yml (or properties) file in the root of your classpath (src/main/resources recommended). Add the following key / values (use correct YAML formatting):
application.yml
---
# This default profile is used when running a single instance completely standalone:
spring:
profiles: default
server:
port: 8010
➤Save a bootstrap.yml file in the root of your classpath. Add the following key / values (use correct YAML formatting):
bootstrap.yml
---
# This default profile is used when running a single instance completely standalone:
spring:
profiles: default
server:
port: 8010
➤Save a bootstrap.yml file in the root of your classpath. Add the following key / values (use correct YAML formatting):
bootstrap.yml
---
spring:
application:
name: lab-eureka-server
➤Add @EnableEurekaServer to the Application class. Save. Start the server. Temporarily ignore the warnings about running a single instance (i.e. connection refused, unable to refresh cache, backup registry not implemented, etc.). Open a browser to http://localhost:8010 to see the server running.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.