1. Development of Eureka Server

(1) Create tensquare_eureka module
(2) Introducing a Spring Cloud version that relies on the parent project pom.xml

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.M9</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Note: It's the parent project's pom.xml
Tenquare_eureka module pom.xml introduces eureka-server

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

(2) Add application.yml

server:
  port: 6868 #Service Port
eureka:
  client:
    registerWithEureka: false #Whether to register oneself in Eureka service or not is in itself all that does not need to be registered.
    fetchRegistry: false #Whether to get registration information from Eureka
    serviceUrl: #The address where the Eureka client interacts with the Eureka server
      defaultZone: http://127.0.0.1:${server.port}/eureka/


(3) Writing startup classes
Create the package com.tensquare.eureka, and create classes under the package

@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServer.class, args);
    }
}

(4) Start running the startup class and enter it in the browser address bar http://localhost:6868/ The operation effect is as follows
Next:

In the main interface, system status is system information General Info is general information Instances currently registered with Eureka is a list of all micro services registered.

II. Service Registration

Register all microservices in Eureka so that all microservices can call each other.
(1) Adding dependencies to other micro-service modules

	  <dependency>
		  <groupId>org.springframework.cloud</groupId>
		  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
	  </dependency>

(2) Modify the application.yml for each microservice and add the configuration for registering the eureka service

eureka:
  client:
    service-url:
      defaultZone: http://localhost:6868/eureka
  instance:
    prefer-ip-address: true

(3) Modify the startup class of each service class and add annotations

@EnableEurekaClient

(4) Start the test: Start each micro-service and you will find that you can see these micro-clothes in the registration list of eureka
Yes.

There are nine in all.

3. Feign implements calls between services

  1. Introduction to Feign
    Feign is a tool to simplify Java HTTP client development (java-to-http client-binder), inspired by Retrofit, JAXRS-2.0 and WebSocket. The original intention of Feign is to reduce the complexity of uniformly binding Denominator to HTTP API without distinguishing whether it is restful or not.
  2. Quick Experience
    Now we are asking and answering the method of invoking basic micro services (querying labels according to ID)
    (1) Adding dependencies to tensquare_qa module
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-openfeign</artifactId>
      </dependency>

(2) Modify the startup class of tensquare_qa module and add annotations

@EnableDiscoveryClient
@EnableFeignClients

(3) Create com.tensquare.qa.client package in tensquare_qa module and create interface under the package

@FeignClient("tensquare-base")
public interface LabelClient {
    @RequestMapping(value="/label/{id}", method = RequestMethod.GET)
    public Result findById(@PathVariable("id") String id);
}

@ The FeignClient annotation is used to specify which service to invoke the function from. Note that the name in the annotation is consistent with the name of the invoked service and cannot contain underscores.

@ The Request Mapping annotation is used for address mapping of the invoked microservice. Note that the @PathVariable annotation must specify the parameter name, otherwise an error will occur

(5) Modifying ProblemController of tensquare_qa module

	@Autowired
	private LabelClient labelClient;
	@RequestMapping(value = "/label/{labelid}")
	public Result findLabelById(@PathVariable String labelid){
		Result result = labelClient.findById(labelid);
		return result;
	}

(6) Testing: http://localhost:9003/problem/label/1 See label information

3. Load Balancing
Test: Open multiple basic micro services at the same time to see if they are invoked in turn.
Modifying findById Method of LabelController in Tenquare_base Project

@RequestMapping(value="/{id}", method = RequestMethod.GET)
	public Result findById(@PathVariable String id){
		System.out.println("No.1");
		return new Result(true,StatusCode.OK,"query was successful",labelService.findById(id) );
}

After starting the basic micro-service, modify the port and output information, and start the basic micro-service again.
Start the Q&A microservice, and the browser executes http://localhost:9003/problem/label/1 to see if it starts in turn.