1 Service Discovery
# # About Service discovery
In the MicroServices architecture, Service Discovery (Discovery) is one of the key principles. Manually configuring each client or some form of convention is difficult and fragile. Spring Cloud provides several ways to implement service discovery, such as Eureka, Consul, Zookeeper.
Spring Cloud is best supported by Eureka, followed by Consul, the zookeeper.
2. Create a MAVEN project (Microservice-discovery-eureka) and add the following to the Pom.xml
<Projectxmlns= "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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <Artifactid>Microservice-discovery-eureka</Artifactid> <Packaging>Jar</Packaging> <Parent> <groupId>Com.xujin.study</groupId> <Artifactid>Microservice-spring-cloud</Artifactid> <version>0.0.1-snapshot</version> <RelativePath/> <!--Lookup parent from repository - </Parent> <Properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </Properties> <Dependencies> <Dependency> <groupId>Org.springframework.cloud</groupId> <Artifactid>Spring-cloud-starter-eureka-server</Artifactid> </Dependency> <Dependency> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-starter-security</Artifactid> </Dependency> </Dependencies></Project>
3. Create Startup Class Eurekaapplication
PackageCom.xujin.study;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;Importorg.springframework.cloud.netflix.eureka.server.enableeurekaserver;@ Springbootapplication@enableeurekaserver Public classeurekaapplication { Public Static voidMain (string[] args) {Springapplication.run (eurekaapplication.class, args); }}
4, Configuration Eureka
Server: port:8761 # Specifies the port of the Eureka Instance security: Basic: enabled:true User: name:root Password:rooteureka: instance: hostname:discovery # Specifies the host name of the Eureka instance client: Registerwitheureka:false fetchregistry:false serviceurl: defaultzone:http://${ security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/
5. After starting the project, visit: [http://127.0.0.1:8761/] Enter your configured user name and password to enter the Eureka page
Spring Cloud Micro-service architecture Eureka