How to build an Eureka service registry
This article is about how to build an Eureka service registration center. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
First create a Maven project, named eureka-server, and configure the dependency information for Eureka in pom.xml, as shown below.
Org.springframework.bootspring-boot-starter-parent2.0.6.RELEASEorg.springframework.cloudspring-cloud-starter-netflix-eureka-serverorg.springframework.cloudspring-cloud-dependenciesFinchley.SR2pomimport
Create a startup class, EurekaServerApplication, with the following code.
@ EnableEurekaServer@SpringBootApplicationpublic static void main (String [] args) {SpringApplication.run (EurekaServer Application.class, args);}}
The startup class mentioned here is almost exactly the same as the Spring Boot we talked about before, except that there is an @ EnableEurekaServer annotation to turn on EurekaServer.
Next, create an application.properties properties file under src/main/resources and add the following configuration:
Spring.application.name=eureka-server
Server.port=8761
# since the application is a registry, it is set to false, which means that you do not register yourself with the registry
Eureka.client.register-with-eureka=false
# since the registry is responsible for maintaining service instances, it does not need to retrieve services, so it is also set to false
Eureka.client.fetch-registry=false
Eureka.client.register-with-eureka must be configured as false, otherwise it will register itself as a client and report an error.
Then run EurekaServerApplication directly to start our registry service. If we configure port 8761 in application.properties, we can access it directly through http://localhost:8761/ to the browser, and then we will see the Web console provided by Eureka.
The above is how to build the Eureka service registration center. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.