Micro Services feign load balancing and service calls the downgrade

First, load balancing:

  feign has integrated ribbon, the service1, service2 start multiple instances of different ports can automatically load balancing

  idea:

    application.yml中server.port: ${port:8080}

    edit configure -> vm options in -Dport = 8080, a plurality of copy startup configuration, port modifications, start to achieve the same final configuration application launching different ports

Second, service degradation

  1, rely on the introduction of sentinel

     <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

  2, open feign the sentinel configuration

feign:
  sentinel:
    enabled: true

  3, create a fallback classes that implement the interface corresponding to the client

@Component
public class UserClientFallback implements UserClient {
    public String getName() {
        return "fallback, 默认姓名";
    }

    public String getAddress () {
         return "fallback, the default address" ;
    }
}

  4, class designated fallback

@FeignClient(value = "service1", fallback = UserClientFallback.class)

Note: The offline functionality can be simulated by the collapse event service instance nacos registry

  

Guess you like

Origin www.cnblogs.com/dongbo/p/12207209.html