SpringCould (three) Zuul load balancing implementation

Zuul comes with Ribbon load balancing, which is enabled by default in the project configuration

First create a service center

Two clients

Service center and client creation: https://blog.csdn.net/qq_37203082/article/details/111031105

The configured service ID of the two clients must be the same

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8888/eureka/
server:
  port: 8889
spring:
  application:
    name: order-server

The test interface Url should also be the same, in order to output different content in the test

Client 1

@RestController
public class TestOrderController {

    @RequestMapping("orderTest")
    public String orderTest(){
        return "this is service 1 order";
    }
}

 Client 2

@RestController
public class TestOrderController {

    @RequestMapping("orderTest")
    public String orderTest(){
        return "this is service 2 order";
    }
}

A ZUUL gateway

The maven reference increases, and the remaining references are the same as the client

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

Start class, add annotation @EnableZuulProxy

@SpringBootApplication
@EnableZuulProxy
public class SpringCloudZuulApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudZuulApplication.class, args);
    }

}

Configuration file

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8888/eureka/
server:
  port: 8080
spring:
  application:
    name: zuul-server
zuul:
  routes:
    api-a:
      path: /server/**
      service-id: order-server

Effect of 4 services after startup

Test the interface, the same interface returns two results, which means that both clients have entered, and the polling strategy is used by default, so the two clients visit in turn to form two nodes

 

Startup sequence: service center, zuul gateway, client 1, client 2

Follow-up other strategies, and then add

 

Guess you like

Origin blog.csdn.net/qq_37203082/article/details/113482388