您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
<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 } ]
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。