refactor sentinel examples (#3144)
refactor: modified Sentinel OpenFeign & RestTemplate examplespull/3152/head
parent
5ab4f22e8e
commit
73a071535e
@ -1,23 +0,0 @@
|
||||
server:
|
||||
port: 18087
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: service-consumer
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
sentinel:
|
||||
transport:
|
||||
dashboard: 127.0.0.1:8081
|
||||
|
||||
feign:
|
||||
sentinel:
|
||||
enabled: true
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: '*'
|
@ -1,16 +0,0 @@
|
||||
server:
|
||||
port: 18088
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: service-provider
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: '*'
|
7
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-openfeign-example/src/main/java/com/alibaba/cloud/examples/OpenFeignApplication.java
7
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-openfeign-example/src/main/java/com/alibaba/cloud/examples/OpenFeignApplication.java
@ -0,0 +1 @@
|
||||
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.examples.configuration;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* @author raozihao
* @author <a href="mailto:zihaorao@gmail.com">Steve</a>
*/
@Component
public class EchoServiceFallbackFactory implements FallbackFactory<HttpbinClientFallback> {
@Override
public HttpbinClientFallback create(Throwable throwable) {
return new HttpbinClientFallback(throwable);
}
}
|
31
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-openfeign-example/src/main/java/com/alibaba/cloud/examples/configuration/HttpbinClient.java
31
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-openfeign-example/src/main/java/com/alibaba/cloud/examples/configuration/HttpbinClient.java
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2013-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples.configuration;
|
||||
|
||||
|
||||
/**
|
||||
* When the service is blown, the fallback operation is performed.
|
||||
*
|
||||
* @author raozihao
|
||||
*/
|
||||
public class HttpbinClientFallback implements HttpbinClient {
|
||||
|
||||
@Override
|
||||
public String delay() {
|
||||
return "delay degrade by sentinel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String status500() {
|
||||
return "500 degrade by sentinel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return "get degrade by sentinel";
|
||||
}
|
||||
|
||||
private Throwable throwable;
|
||||
|
||||
HttpbinClientFallback(Throwable throwable) {
|
||||
this.throwable = throwable;
|
||||
}
|
||||
}
|
24
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-openfeign-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java
24
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-openfeign-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java
@ -0,0 +1,24 @@
|
||||
server:
|
||||
port: 18087
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: openfeign-example
|
||||
cloud:
|
||||
sentinel:
|
||||
transport:
|
||||
dashboard: 127.0.0.1:8081
|
||||
# Don't support run in jar by using configuration file method now, refer to https://github.com/alibaba/spring-cloud-alibaba/issues/3033
|
||||
# datasource:
|
||||
# ds1.file:
|
||||
# file: "classpath: degraderule.json"
|
||||
# ruleType: "degrade"
|
||||
# dataType: "json"
|
||||
# ds2.file:
|
||||
# file: "classpath: flowrule.json"
|
||||
# ruleType: "flow"
|
||||
# dataType: "json"
|
||||
|
||||
feign:
|
||||
sentinel:
|
||||
enabled: true
|
@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"resource": "GET:https://httpbin.org/status/500",
|
||||
"count": 1,
|
||||
"grade": 2,
|
||||
"minRequestAmount": 1,
|
||||
"timeWindow": 30
|
||||
},
|
||||
{
|
||||
"resource": "GET:https://httpbin.org/delay/3",
|
||||
"count": 1,
|
||||
"grade": 0,
|
||||
"slowRatioThreshold": 0.1,
|
||||
"minRequestAmount": 1,
|
||||
"timeWindow": 30
|
||||
}
|
||||
]
|
@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"resource": "GET:https://httpbin.org/get",
|
||||
"controlBehavior": 0,
|
||||
"count": 1,
|
||||
"grade": 1,
|
||||
"limitApp": "default",
|
||||
"strategy": 0
|
||||
}
|
||||
]
|
9
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-resttemplate-example/src/main/java/com/alibaba/cloud/examples/RestTemplateApplication.java
9
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-resttemplate-example/src/main/java/com/alibaba/cloud/examples/RestTemplateApplication.java
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2013-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.examples.configuration;
|
||||
|
||||
|
||||
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
|
||||
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author raozihao
|
||||
* @author <a href="mailto:zihaorao@gmail.com">Steve</a>
|
||||
*/
|
||||
@Configuration
|
||||
public class RestTemplateConfiguration {
|
||||
|
||||
@LoadBalanced
|
||||
@Bean
|
||||
@SentinelRestTemplate
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
27
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/controller/EchoController.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-resttemplate-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java
27
spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/controller/EchoController.java → spring-cloud-alibaba-examples/sentinel-example/sentinel-resttemplate-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java
@ -0,0 +1,19 @@
|
||||
server:
|
||||
port: 18088
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: sentinel-resttemplate-example
|
||||
# Don't support run in jar by using configuration file method now, refer to https://github.com/alibaba/spring-cloud-alibaba/issues/3033
|
||||
# cloud:
|
||||
# sentinel:
|
||||
# datasource:
|
||||
# ds1.file:
|
||||
# file: "classpath: degraderule.json"
|
||||
# ruleType: "degrade"
|
||||
# dataType: "json"
|
||||
# ds2.file:
|
||||
# file: "classpath: flowrule.json"
|
||||
# ruleType: "flow"
|
||||
# dataType: "json"
|
||||
|
@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"resource": "GET:https://httpbin.org/status/500",
|
||||
"count": 1,
|
||||
"grade": 2,
|
||||
"minRequestAmount": 1,
|
||||
"timeWindow": 30
|
||||
},
|
||||
{
|
||||
"resource": "GET:https://httpbin.org/delay/3",
|
||||
"count": 1,
|
||||
"grade": 0,
|
||||
"slowRatioThreshold": 0.1,
|
||||
"minRequestAmount": 1,
|
||||
"timeWindow": 30
|
||||
}
|
||||
]
|
@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"resource": "GET:https://httpbin.org/get",
|
||||
"controlBehavior": 0,
|
||||
"count": 1,
|
||||
"grade": 1,
|
||||
"limitApp": "default",
|
||||
"strategy": 0
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue