mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
update sentinel examples
This commit is contained in:
parent
49a6e1e5e2
commit
5995687dd5
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
n=1
|
||||
while [ $n -le 10 ]
|
||||
do
|
||||
echo `curl -s http://localhost:18083/test`
|
||||
let n++
|
||||
done
|
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
n=1
|
||||
while [ $n -le 10 ]
|
||||
do
|
||||
echo `curl -s http://localhost:18083/index`
|
||||
let n++
|
||||
done
|
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
n=1
|
||||
while [ $n -le 10 ]
|
||||
do
|
||||
echo `curl -s http://localhost:18083/sleep`
|
||||
let n++
|
||||
done
|
@ -3,6 +3,7 @@ package org.springframework.cloud.alibaba.cloud.examples;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.alibaba.cloud.examples.ConsumerApplication.EchoService;
|
||||
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
@ -28,6 +29,13 @@ public class ConsumerApplication {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@LoadBalanced
|
||||
@Bean
|
||||
@SentinelRestTemplate
|
||||
public RestTemplate restTemplate1() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ConsumerApplication.class, args);
|
||||
}
|
||||
|
@ -18,18 +18,52 @@ public class TestController {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate1;
|
||||
|
||||
@Autowired
|
||||
private EchoService echoService;
|
||||
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
// @PostConstruct
|
||||
// public void init() {
|
||||
// restTemplate1.setErrorHandler(new ResponseErrorHandler() {
|
||||
// @Override
|
||||
// public boolean hasError(ClientHttpResponse response) throws IOException {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleError(ClientHttpResponse response) throws IOException {
|
||||
// System.err.println("handle error");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
@RequestMapping(value = "/echo-rest/{str}", method = RequestMethod.GET)
|
||||
public String rest(@PathVariable String str) {
|
||||
return restTemplate.getForObject("http://service-provider/echo/" + str,
|
||||
String.class);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/index", method = RequestMethod.GET)
|
||||
public String index() {
|
||||
return restTemplate1.getForObject("http://service-provider", String.class);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/test", method = RequestMethod.GET)
|
||||
public String test() {
|
||||
return restTemplate1.getForObject("http://service-provider/test", String.class);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sleep", method = RequestMethod.GET)
|
||||
public String sleep() {
|
||||
return restTemplate1.getForObject("http://service-provider/sleep", String.class);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/notFound-feign", method = RequestMethod.GET)
|
||||
public String notFound() {
|
||||
return echoService.notFound();
|
||||
|
@ -10,4 +10,8 @@ spring.cloud.sentinel.eager=true
|
||||
|
||||
spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json
|
||||
spring.cloud.sentinel.datasource.ds1.file.data-type=json
|
||||
spring.cloud.sentinel.datasource.ds1.file.rule-type=flow
|
||||
spring.cloud.sentinel.datasource.ds1.file.rule-type=flow
|
||||
|
||||
spring.cloud.sentinel.datasource.ds2.file.file=classpath: degraderule.json
|
||||
spring.cloud.sentinel.datasource.ds2.file.data-type=json
|
||||
spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade
|
@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"resource": "GET:http://service-provider/test",
|
||||
"count": 0.5,
|
||||
"grade": 1,
|
||||
"timeWindow": 30
|
||||
},
|
||||
{
|
||||
"resource": "GET:http://service-provider",
|
||||
"count": 0.5,
|
||||
"grade": 1,
|
||||
"timeWindow": 10
|
||||
},
|
||||
{
|
||||
"resource": "GET:http://service-provider/sleep",
|
||||
"count": 20.0,
|
||||
"grade": 0,
|
||||
"timeWindow": 30
|
||||
}
|
||||
]
|
@ -3,6 +3,8 @@ package org.springframework.cloud.alibaba.cloud.examples;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@ -22,6 +24,27 @@ public class ProviderApplication {
|
||||
|
||||
@RestController
|
||||
class EchoController {
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public ResponseEntity index() {
|
||||
return new ResponseEntity("index error", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/test", method = RequestMethod.GET)
|
||||
public ResponseEntity test() {
|
||||
return new ResponseEntity("error", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sleep", method = RequestMethod.GET)
|
||||
public String sleep() {
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
|
||||
public String echo(@PathVariable String string) {
|
||||
return "hello Nacos Discovery " + string;
|
||||
|
Loading…
x
Reference in New Issue
Block a user