Enabling the Eureka server as a Discovery Service server

Let's see the following main Spring Boot application class:

package com.dineshonjava.eurekaserver; 
 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 
 
@SpringBootApplication 
@EnableEurekaServer 
public class EurekaServerApplication { 
 
   public static void main(String[] args) { 
         SpringApplication.run(EurekaServerApplication.class, args); 
   } 
} 

If you run this main application class, it will start the Eureka Server. This server has a home page with a UI. This server also has HTTP API endpoints for the normal Eureka functionality under /eureka/*. By default, every Eureka server is also a Eureka client. So you can also disable this default client registry with the Eureka server by setting registerWithEureka to false.

Let's see the following application.yml file for your Eureka server:

server: 
  port: 8761 
 
eureka: 
  instance: 
    hostname: localhost 
  client: 
    registerWithEureka: false 
    fetchRegistry: false 
    serviceUrl: 
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

As you can see, the application.yml file is a configuration file to configure the properties in YAML format. The server.port property defines the server port for Eureka; here we are configuring this application port to 8761, and it is the default one for Eureka servers. We are also configuring the Eureka server instance's hostname to localhost. We are telling the built-in Eureka client not to register with itself, because this application should be acting as a server. And the serviceUrl is pointing to the same host as the local instance.

Finally, we can point our browser to http://localhost:8761 to view the Eureka dashboard as follows:

As you can see, currently we don't have any registered service instances. We will discuss this later, but at the moment, we can see basic indicators, such as status and health indicators.

Now, let's move on to the next section to create a Eureka client and also create a REST service that registers itself at the registry server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.124