Why Need of Naming Server
Suppose if we are using Ribbon than it needs a configured if any new server comes up
suppose currently only 2 server was there 8001 and 8000 as given below application .properties file only configured with two server now for any new server like 8002 comes up as we didnt configured into the application properties file
currency-exchange-service.ribbon.listOfServers=http://localhost:8000,http://localhost:8001
So for dynamicaly increase and decreasing we need naming server(EurekaNamingServer)
All the instances of All Microservices would register with naming server, that is called service Registration
whenever service want to talk to another service like CurrencyCalculationService wants to talk to the CurrencyExchangeService, what would do, it would talk to the NameServer, and it would ask the NameServer what are the instances of the currencyExchangeService that are currently running? This is called Service Discovery
- Service Registration: All Microservice Register with Eureka naming server
- Service Discovery: Asking to the Eureka Naming server and ask How many Service running for specific service is known as service Discovery
spring.application.name=netflix-eureka-naming-server
server.port=8761
Step 3: add @EnableEurekaServer in main class for Enabling Eureka Server
@SpringBootApplication
@EnableEurekaServer
public class NetflixEurekaNamingServerApplication {
public static void main(String[] args) {
SpringApplication.run(NetflixEurekaNamingServerApplication.class, args);
}
}
<?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.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.khan.microserservices</groupId>
<artifactId>netflix-eureka-naming-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>netflix-eureka-naming-server</name>
<description>netflix eureka naming server</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</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>
<configuration>
<image>
<builder>paketobuildpacks/builder-jammy-base:latest</builder>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
Comments
Post a Comment