<dependency> <groupId>com.nepxion</groupId> <artifactId>discovery-plugin-strategy-starter-service-sentinel</artifactId> <version>${discovery.version}</version> </dependency> <dependency> <groupId>com.nepxion</groupId> <artifactId>discovery-plugin-strategy-sentinel-starter-nacos</artifactId> <!-- <artifactId>discovery-plugin-strategy-sentinel-starter-apollo</artifactId> --> <version>${discovery.version}</version> </dependency>
@RestController @ConditionalOnProperty(name = DiscoveryConstant.SPRING_APPLICATION_NAME, havingValue = "discovery-guide-service-b") public class BFeignImpl extends AbstractFeignImpl implements BFeign { private static final Logger LOG = LoggerFactory.getLogger(BFeignImpl.class); @Override @SentinelResource(value = "sentinel-resource", blockHandler = "handleBlock", fallback = "handleFallback") public String invoke(@PathVariable(value = "value") String value) { value = doInvoke(value); LOG.info("調用路徑:{}", value); return value; } public String handleBlock(String value, BlockException e) { return value + "-> B server sentinel block, cause=" + e.getClass().getName() + ", rule=" + e.getRule() + ", limitApp=" + e.getRuleLimitApp(); } public String handleFallback(String value) { return value + "-> B server sentinel fallback"; } }
1. Nacos的Key格式:Group為元數據中配置的[組名],Data Id為[服務名]-[規則類型] 2. Apollo的Key格式:[組名]-[服務名]-[規則類型]
[ { "resource": "sentinel-resource", "limitApp": "default", "grade": 1, "count": 1, "strategy": 0, "refResource": null, "controlBehavior": 0, "warmUpPeriodSec": 10, "maxQueueingTimeMs": 500, "clusterMode": false, "clusterConfig": null } ]
[ { "resource": "sentinel-resource", "limitApp": "default", "count": 2, "timeWindow": 10, "grade": 0, "passCount": 0 } ]
[ { "resource": "sentinel-resource", "limitApp": "discovery-guide-service-a", "strategy": 0 } ]
[ { "resource": null, "limitApp": null, "highestSystemLoad": -1.0, "highestCpuUsage": -1.0, "qps": 200.0, "avgRt": -1, "maxThread": -1 } ]
[ { "resource": "sentinel-resource", "limitApp": "default", "grade": 1, "paramIdx": 0, "count": 1, "controlBehavior": 0, "maxQueueingTimeMs": 0, "burstCount": 0, "durationInSec": 1, "paramFlowItemList": [], "clusterMode": false } ]
spring.application.strategy.service.sentinel.request.origin.key=n-d-service-id
[ { "resource": "sentinel-resource", "limitApp": "discovery-guide-service-a", "strategy": 0 } ]
spring.application.strategy.service.sentinel.request.origin.key=n-d-service-group
[ { "resource": "sentinel-resource", "limitApp": "my-group", "strategy": 0 } ]
spring.application.strategy.service.sentinel.request.origin.key=n-d-service-version
[ { "resource": "sentinel-resource", "limitApp": "1.0", "strategy": 0 } ]
spring.application.strategy.service.sentinel.request.origin.key=n-d-service-region
[ { "resource": "sentinel-resource", "limitApp": "dev", "strategy": 0 } ]
spring.application.strategy.service.sentinel.request.origin.key=n-d-service-address
[ { "resource": "sentinel-resource", "limitApp": "192.168.0.88:8081,192.168.0.88:8082", "strategy": 0 } ]
// 版本號+用戶名,實現組合式熔斷 public class MyServiceSentinelRequestOriginAdapter extends DefaultServiceSentinelRequestOriginAdapter { @Override public String parseOrigin(HttpServletRequest request) { String version = request.getHeader(DiscoveryConstant.N_D_SERVICE_VERSION); String user = request.getHeader("user"); return version + "&" + user; } }
@Bean public ServiceSentinelRequestOriginAdapter ServiceSentinelRequestOriginAdapter() { return new MyServiceSentinelRequestOriginAdapter(); }
[ { "resource": "sentinel-resource", "limitApp": "1.0&zhangsan", "strategy": 0 } ]
分享題目:如何基于Nacos和Sentinel,實現灰度路由和流量防護一體化
文章出自:http://vcdvsql.cn/article38/pcdcpp.html
成都網站建設公司_創新互聯,為您提供網站設計、響應式網站、品牌網站建設、移動網站建設、面包屑導航、云服務器
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯