Categories
microservices spring-boot

create netflix eureka discovery server using spring boot

Here we are going to create netflix eureka discovery server using spring boot

What is Discovery Server

Discovery server is an application which hold basic information like host name, port about all the micro-services.

What is Eureka

Eureka is the project name of Discovery server which is created by Netflix.

What is the annotation for discovery server
@EnableEurekaServer
Dependency
<parent>                                                             
  <groupId>org.springframework.boot</groupId>                        
  <artifactId>spring-boot-starter-parent</artifactId>                
  <version>2.2.6.RELEASE</version>                                   
  <relativePath /> <!-- lookup parent from repository -->            
</parent>   

<dependency>                                                         
  <groupId>org.springframework.cloud</groupId>                       
  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

<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>   
pom.xml

https://github.com/rkumar9090/discovery-server/blob/master/pom.xml

application.properties
server.port=8761
eureka.client.registerWithEureka= false
eureka.client.fetchRegistry= false
Main class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(DiscoveryServerApplication.class, args);
	}
}
How to create Discovery Server

Here we are going to create discovery server with the help of spring boot and with help of some annotation

Time needed: 30 minutes

Steps

  1. Spring Initializer

    Navigate to https://start.spring.io/create netflix eureka discovery server using spring boot

  2. Add Eureka Server Dependency

    In the dependency text box add eureka server as dependency

  3. Click on Generate

    Once you entered group id, artifact-id& dependency click on Generate

  4. Import the downloaded project in your favorite IDE

    Once you clicked Generate you project will download, after that you can import in your IDE

  5. Add @EnableEurekaServer in the main class

    Once you imported you project in IDE, Go to the Main class and add @EnableEurekaServer annotation

  6. Change application.properties

    Replace your application.properties with below content
    server.port=8761
    eureka.client.registerWithEureka= false
    eureka.client.fetchRegistry= false

  7. Build and Run

    Now you can run your application

  8. Testing

    Open browser and navigate to http://localhost:8761/create netflix eureka discovery server using spring boot

Register Spring boot with Eureka

Refer below article to register spring boot micro services with eureka discovery server
https://beginnersbug.com/register-spring-boot-micro-services-to-eureka-discovery/

Github

https://github.com/rkumar9090/discovery-server

Related Articles

register spring boot micro-services to eureka discovery