Spring cloud Eureka instance code for service registration and discovery of spring cloud
@H_ 502_ 1 @ I. Introduction to spring cloud
Spring cloud is a microservice architecture development tool based on the implementation of springboot. It provides a simple development method for configuration management, service governance, circuit breaker, intelligent routing, micro agent, control bus, global lock, decision election, distributed session and cluster state management involved in microservice architecture. Spring cloud includes several subprojects (which may be added for many different open source products involved in Distributed Systems), as described below.
Spring cloud config: configuration management tool, spring cloud Netflix: core components, spring cloud bus: events, message bus, etc.
@H_ 502_ 1 @ II. Spring cloud Eureka
Spring cloud Eureka is a part of the spring cloud Netflix microservice suite. It is secondary encapsulated based on netflixeeureka and is mainly responsible for completing the service governance function in the microservice architecture. Spring cloud adds spring boot style automatic configuration to Eureka. We can easily integrate the microservice application built by spring boot with Eureka service governance system by simply introducing dependency and annotation configuration.
Service governance is the core and basic module in the microservice architecture. It is mainly used to realize the automatic registration and discovery of each microservice instance.
@H_ 502_ 1 @ III. examples
(1) Tool: IntelliJ idea
(2) Create a new empty project
(3) Create a new Eureka server module named Eureka server
Right click the project - > create module - > select spring initialir - > fill in the project name. Next - > select Eureka server as shown in the figure:
(3-1)pom.xml
(3-2)application.yml
Note: Eureka client. Register with Eureka: because the application is a registry, it is set to false, which means that it does not register itself with the registry. eureka. client. Fetch registry: since the registry is responsible for maintaining service instances, it does not need to retrieve services, so it is also set to false.
(3-3) entrance class
(3-4) Startup Test
After completing the above configuration, start the application and access http://localhost:5555/ 。 You can see the Eureka information panel as shown in the figure below. The instances currently registered with Eureka column is empty, indicating that the registry has not registered any services.
(4) After the registered service provider completes the construction of the service registry, next we try to add an existing spring boot application to Emeka's service governance system.
(5) Create a new Eureka client module named helloserver, which is the sub model of Eureka server
(6) Modify POM configuration of parent model and child model (6-1) pom.xml configuration of eurekaserver:
(6-2) all pom.xml of eurekaserver:
(6-3) pom.xml configuration of helloserver:
(6-4) all pom.xml configurations of helloserver:
(6-5) application.yml configuration of helloserver:
(6-6) startup class of helloserver:
(7) Start Eureka server and helloserver respectively, and test:
(7-1) access Eureka server: (you can clearly see the helloserver information)
(7-2) access helloserver:
(7-3) view the helloserver console information:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.