1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

基于F版的一些适配性调整

This commit is contained in:
theonefx
2020-04-03 10:38:16 +08:00
parent c579109d2a
commit 0db3b26fd6
69 changed files with 412 additions and 2640 deletions

View File

@@ -16,18 +16,11 @@
package com.alibaba.cloud.examples;
import java.util.Collections;
import com.alibaba.cloud.circuitbreaker.sentinel.SentinelCircuitBreakerFactory;
import com.alibaba.cloud.circuitbreaker.sentinel.SentinelConfigBuilder;
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.Customizer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@@ -54,18 +47,6 @@ public class ServiceApplication {
return new JsonFlowRuleListConverter();
}
@Bean
public Customizer<SentinelCircuitBreakerFactory> defaultConfig() {
return factory -> {
factory.configureDefault(
id -> new SentinelConfigBuilder().resourceName(id)
.rules(Collections.singletonList(new DegradeRule(id)
.setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
.setTimeWindow(10)))
.build());
};
}
public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
}

View File

@@ -19,7 +19,6 @@ package com.alibaba.cloud.examples;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@@ -33,9 +32,6 @@ public class TestController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private CircuitBreakerFactory circuitBreakerFactory;
@GetMapping("/hello")
@SentinelResource("resource")
public String hello() {
@@ -58,17 +54,4 @@ public class TestController {
return restTemplate.getForObject("http://www.taobao.com/test", String.class);
}
@GetMapping("/slow")
public String slow() {
return circuitBreakerFactory.create("slow").run(() -> {
try {
Thread.sleep(500L);
}
catch (InterruptedException e) {
e.printStackTrace();
}
return "slow";
}, throwable -> "fallback");
}
}