What is micro service?
A single application is divided into a group of small service components, each of which runs on its own process. The components interact with each other through lightweight mechanisms such as Restful API. These services are based on business capability and deployed independently by automated deployment mechanism. In addition, these services can be used. Research and development in different languages, using different technologies to store data.
What is Spring Cloud?
Spring Cloud provides developers with tools to quickly build distributed systems, including configuration management, service discovery, circuit breaker, routing, load balancing, micro-agent, event bus, global lock, decision campaign, distributed session and so on.
Spring Cloud is through a center: Eureka (registry), and different service s communicate through rpc.
Below is a record of the Spring Book integration process Spring Cloud!
Registry:
Use annotations
@EnableEurekaServer
Startup class:
package io.ymq.example.eureka.server; 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); } }
Add corresponding dependencies:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency>
Additionally, add dependency management configuration to pom
<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>
application.yml configuration:
eureka: instance: hostname: localhost client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ spring: application: name: eureka-service server: port: 8888
eureka.client.registerWithEureka: Indicates whether to register oneself to Eureka Server by default to true.
eureka.client.fetchRegistry: Represents whether registration information is obtained from Eureka Server by default to true.
eureka.client.serviceUrl.defaultZone: Set the address that interacts with Eureka Server, which is required for both query and registration services. The default is http://localhost:8761/eureka; multiple addresses can be used and separated.
Then start the registry.
Browser access http://localhost:8888/
You can see that the registry has started!
At this point, the red box part of the graph indicates that there is no Service service.