网站开发运维机构设置简书网站开发

pingmian/2025/10/8 10:43:49/文章来源:
网站开发运维机构设置,简书网站开发,珠海医疗网站建设公司排名,网站建设办公软件销售技巧简介#xff1a; 前言 掌门1对1精耕在线教育领域#xff0c;近几年业务得到了快速发展#xff0c;但同时也遭遇了“成长的烦恼”。随着微服务数量不断增加#xff0c;流量进一步暴增#xff0c;硬件资源有点不堪重负#xff0c;那么#xff0c;如何实现更好的限流熔断…简介 前言 掌门1对1精耕在线教育领域近几年业务得到了快速发展但同时也遭遇了“成长的烦恼”。随着微服务数量不断增加流量进一步暴增硬件资源有点不堪重负那么如何实现更好的限流熔断降级等流量防护措施这个课题就摆在了掌门人的面前。由于 Spring Cloud 体系已经演进到第二代第一代的 Hystrix 限流熔断降级组件已经不大适合现在的业务逻辑和规模同时它目前被 Spring Cloud 官方置于维护模式将不再向前发展。 如何选择一个更好的限流熔断降级组件经过对 Alibaba Sentinel、Resilience4j、Hystrix 等开源组件做了深入的调研和比较最终选定 Alibaba Sentinel 做微服务体系 Solar 中的限流熔断降级必选组件。 Sentinel 简介 阿里巴巴中间件部门开发的新一代以流量为切入点从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性的分布式系统的流量防卫兵。它承接了阿里巴巴近10年的双十一大促流量的核心场景例如秒杀即突发流量控制在系统容量可以承受的范围、消息削峰填谷、集群流量控制、实时熔断下游不可用应用等。 它具有非常丰富的开源生态 它和 Hystrix 相比有如下差异 摘自官网 Sentinel Roadmap 关于 Sentinel 如何使用它的技术实现原理怎样等官方文档或者民间博客、公众号文章等可以提供非常详尽且有价值的材料这些不在本文的讨论范围内就不一一赘述。笔者尝试结合掌门1对1现有的技术栈以及中间件一体化的战略并着眼于强大的 Spring Cloud Alibaba 技术生态圈展开阐释。 Sentinel 深度集成 Apollo Sentinel 官方在 sentinel-datasource-apollo 模块中已经对 Apollo 做了一些扩展主要实现了 Sentinel 规则的读取和订阅逻辑。这些并不够我们需要对 Apollo 进行更深层次的集成。 摘自官网 在生产环境中使用 Sentinel Solar SDK 环境初始化 定制 EnvironmentPostProcessor 类实现如下 Sentinel Dashboard 的项目名称从 Apollo AppId 的维度进行展示根据环境 env 值读取相应的配置文件并访问对应环境的 Sentinel Dashboard 域名Sentinel Dashboard 在生产环境部署若干台 ECS 实例阿里云 SLB 做负载均衡实现对集群的水平扩展 public class SentinelClientEnvironmentPostProcessor implements EnvironmentPostProcessor {private final ResourceLoader resourceLoader new DefaultResourceLoader();private static final String DEFAULT_CLASSPATH_LOCATION classpath:/META-INF/app.properties;private static final String DEFAULT_LOCATION /META-INF/app.properties;private static final String DEFAULT_LOG_LOCATION /opt/logs/; Overridepublic void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {try {Resource appResource resourceLoader.getResource(DEFAULT_CLASSPATH_LOCATION);if (!appResource.exists()) {appResource resourceLoader.getResource(DEFAULT_LOCATION);}Properties appProperties new Properties();appProperties.load(new InputStreamReader(appResource.getInputStream()));String appId appProperties.getProperty(app.id);System.setProperty(project.name, appId);System.setProperty(csp.sentinel.log.dir, DEFAULT_LOG_LOCATION appId);Properties properties new Properties();String path isOSWindows() ? C:/opt/settings/server.properties : /opt/settings/server.properties;File file new File(path);if (file.exists() file.canRead()) {FileInputStream fis new FileInputStream(file);if (fis ! null) {try {properties.load(new InputStreamReader(fis, Charset.defaultCharset()));} finally {fis.close();}}}String idc properties.getProperty(idc);String location;String env System.getProperty(env);if (StringUtils.isEmpty(idc)) {if (!isBlank(env)) {env env.trim().toLowerCase();} else {env System.getenv(ENV);if (!isBlank(env)) {env env.trim().toLowerCase();} else {env properties.getProperty(env);if (!isBlank(env)) {env env.trim();} else {env Env.FAT.getEnv();}}}location classpath:/META-INF/sentinel- env .properties;} else {location classpath:/META-INF/sentinel- idc .properties;}Resource serverResource resourceLoader.getResource(location);properties.load(new InputStreamReader(serverResource.getInputStream()));for (String key : properties.stringPropertyNames()) {System.setProperty(key, properties.getProperty(key));}System.setProperty(CommonConstant.SENTINEL_VERSION_NAME, CommonConstant.SENTINEL_VERSION_VALUE);} catch (Exception e) {LOG.error(e.getMessage());}}private boolean isBlank(String str) {return Strings.nullToEmpty(str).trim().isEmpty();}private boolean isOSWindows() {String osName System.getProperty(os.name);return !isBlank(osName) osName.startsWith(Windows);} } 把 SentinelClientEnvironmentPostProcessor 类放置 \resources\META-INF\spring.factories 文件中内容为 org.springframework.boot.env.EnvironmentPostProcessor\ com.zhangmen.solar.component.sentinel.common.context.SentinelClientEnvironmentPostProcessor 在 \resources\META-INF 目录下定制环境配置文件文件名格式为 sentinel-{环境号}.properties 。下文以 dev 环境和 flow 流控配置其它规则配置请自行参考 Spring Cloud Alibaba Sentinel 的相关资料为样例。 sentinel-dev.properties spring.cloud.sentinel.transport.dashboard127.0.0.1:8080 spring.cloud.sentinel.datasource.ds.apollo.namespaceNameapplication spring.cloud.sentinel.datasource.ds.apollo.flowRulesKeysentinel.flowRules spring.cloud.sentinel.datasource.ds.apollo.ruleTypeflow ... Sentinel Dashboard 持久化改造 原生的 Sentinel Dashboard 在创建完规则后规则内容保存在服务的内存中当服务重启后所有的规则内容都会消失。因此在生产部署时需要考虑配置持久化并且使用 Apollo 动态规则的感知能力。 ① 向外暴露 Sentinel 规则的 Restful 接口 RestController RequestMapping(value /v2/flow) public class FlowControllerV2 {AutowiredQualifier(apolloFlowRuleProvider)private DynamicRuleProviderListFlowRuleEntity ruleProvider;AutowiredQualifier(apolloFlowRulePublisher)private DynamicRulePublisherListFlowRuleEntity rulePublisher;.... } ② 实现 Sentinel Apollo 规则提供 Component(apolloFlowRuleProvider) public class ApolloFlowRuleProvider extends BaseApolloRuleProviderFlowRuleEntity {Overridepublic ListFlowRuleEntity getRules(String appName) throws Exception {ListFlowRuleEntity flowRuleEntityList super.getRules(appName);if (!CollectionUtils.isEmpty(flowRuleEntityList)) {ListFlowRuleEntity flowRuleEntities JSONArray.parseArray(flowRuleEntityList.toString(), FlowRuleEntity.class);long id 1;for (FlowRuleEntity entity : flowRuleEntities) {entity.setId(id);entity.getClusterConfig().setFlowId(entity.getId());}return flowRuleEntities;} else {return null;}}Overrideprotected String getDataId() {return ApolloConfigUtil.getFlowDataId();} } ③ 实现 Sentinel Apollo 规则订阅 Component(apolloFlowRulePublisher) public class ApolloFlowRulePublisher extends BaseApolloRulePublisherListFlowRuleEntity {Overridepublic void publish(String app, String operator, ListFlowRuleEntity rules) throws Exception {if (!CollectionUtils.isEmpty(rules)) {for (int i 0; i rules.size(); i) {rules.get(i).setId((long) (i 1));rules.get(i).setApp(null);rules.get(i).setGmtModified(null);rules.get(i).setGmtCreate(null);rules.get(i).setIp(null);rules.get(i).setPort(null);rules.get(i).getClusterConfig().setFlowId((long) (i 1));}} else {rules null;}super.publish(app, operator, rules);}Overrideprotected String getDataId() {return ApolloConfigUtil.getFlowDataId();} } 上述代码实现了对 Apollo 配置读写操作。熟悉 Apollo 的同学应该知道这些操作需要基于 Apollo OpenApi 来操作动态感知能力的逻辑已经由 sentinel-datasource-apollo 模块实现。 Sentinel 集成 Skywalking 由于掌门1对1微服务技术栈落地的比较早鉴于历史的局限性当时没有更先进的技术可供选择除了 Hystrix 比较古老以外另一个技术栈的痛点是全链路监控中间件的改造也提上议事日程CAT 作为开源界老牌作品为公司底层全链路监控提供强有力的保障但随着技术的演进它逐渐已经不适合公司的未来发展方向经过对比最终选择 Skywalking 将作为它的替代者关于 Skywalking 的技术选型将在后面掌门1对1微服务体系 Solar 的公众号系列文章中会一一阐述。 业务系统要求对限流熔断降级实现全链路实时埋点并希望在 Skywalking 界面上提供限流熔断降级埋点的多维度统计。由于 Skywalking 实现了 OpenTracing 标准化协议那么以 OpenTracing 为桥梁通过 Solar SDK 输出 Sentinel 埋点到 Skywalking Server 不失为一个好的技术选择。下面简单扼要介绍一下基于 Sentinel InitFunc 的 SPI 机制实现埋点输出 Sentinel 将 ProcessorSlot 作为 SPI 接口进行扩展1.7.2 版本以前 SlotChainBuilder 作为 SPI 使得 Slot Chain 具备了扩展的能力。您可以自行加入自定义的 slot 并编排 slot 间的顺序从而可以给 Sentinel 添加自定义的功能。 摘自官网 Sentinel 工作主流程 抽象 Sentinel ProcessorSlot 埋点输出 Sentinel 的 ProcessorSlotEntryCallback 提供 onPass 和 onBlocked 两个方法毕竟限流熔断降级并不是常规的功能不会发生在大流量上面所以 onPass 上我们不做任何处理否则正常的调用去实现拦截将为产生大量的埋点数据会让 Skywalking Server 承受很大的性能压力所以 onBlocked 将是我们关注的重点它除了输出 Sentinel 本身的上下文参数之外也会输出微服务 Solar 指标参数主要包括 埋点 Span名称这里为 SENTINEL 在 Skywalking 全链路监控界面中用户可以非常容易的找到这个埋点服务所在的组名指服务的逻辑分组服务类型包括服务和网关网关也是一种特殊的服务 Sentinel 埋点可以支持在服务和网关上的输出服务的 APPID它为 Apollo 组件的范畴概念服务名它对应为 spring.application.name 的配置值服务实例所在的 IP 地址和 Port 端口服务版本号服务所在的区域服务所在的子环境 接下去是 Sentinel 层面的参数请自行参考 Sentinel 官方文档和源码了解其含义这里不做具体讲解。 public abstract class SentinelTracerProcessorSlotEntryCallbackS implements ProcessorSlotEntryCallbackDefaultNode {Overridepublic void onPass(Context context, ResourceWrapper resourceWrapper, DefaultNode param, int count, Object... args) throws Exception {}Overridepublic void onBlocked(BlockException e, Context context, ResourceWrapper resourceWrapper, DefaultNode param, int count, Object... args) {S span buildSpan();PluginAdapter pluginAdapter PluginContextAware.getStaticApplicationContext().getBean(PluginAdapter.class);outputSpan(span, DiscoveryConstant.SPAN_TAG_PLUGIN_NAME, context.getName());outputSpan(span, DiscoveryConstant.N_D_SERVICE_GROUP, pluginAdapter.getGroup());outputSpan(span, DiscoveryConstant.N_D_SERVICE_TYPE, pluginAdapter.getServiceType());String serviceAppId pluginAdapter.getServiceAppId();if (StringUtils.isNotEmpty(serviceAppId)) {outputSpan(span, DiscoveryConstant.N_D_SERVICE_APP_ID, serviceAppId);}outputSpan(span, DiscoveryConstant.N_D_SERVICE_ID, pluginAdapter.getServiceId());outputSpan(span, DiscoveryConstant.N_D_SERVICE_ADDRESS, pluginAdapter.getHost() : pluginAdapter.getPort());outputSpan(span, DiscoveryConstant.N_D_SERVICE_VERSION, pluginAdapter.getVersion());outputSpan(span, DiscoveryConstant.N_D_SERVICE_REGION, pluginAdapter.getRegion());outputSpan(span, DiscoveryConstant.N_D_SERVICE_ENVIRONMENT, pluginAdapter.getEnvironment());outputSpan(span, SentinelStrategyConstant.ORIGIN, context.getOrigin());outputSpan(span, SentinelStrategyConstant.ASYNC, String.valueOf(context.isAsync()));outputSpan(span, SentinelStrategyConstant.RESOURCE_NAME, resourceWrapper.getName());outputSpan(span, SentinelStrategyConstant.RESOURCE_SHOW_NAME, resourceWrapper.getShowName());outputSpan(span, SentinelStrategyConstant.RESOURCE_TYPE, String.valueOf(resourceWrapper.getResourceType()));outputSpan(span, SentinelStrategyConstant.ENTRY_TYPE, resourceWrapper.getEntryType().toString());outputSpan(span, SentinelStrategyConstant.RULE_LIMIT_APP, e.getRuleLimitApp());if (tracerSentinelRuleOutputEnabled) {outputSpan(span, SentinelStrategyConstant.RULE, e.getRule().toString());}outputSpan(span, SentinelStrategyConstant.CAUSE, e.getClass().getName());outputSpan(span, SentinelStrategyConstant.BLOCK_EXCEPTION, e.getMessage());outputSpan(span, SentinelStrategyConstant.COUNT, String.valueOf(count));if (tracerSentinelArgsOutputEnabled) {outputSpan(span, SentinelStrategyConstant.ARGS, JSON.toJSONString(args));}finishSpan(span);}protected abstract S buildSpan();protected abstract void outputSpan(S span, String key, String value);protected abstract void finishSpan(S span); } 整合 OpenTracing Skywalking 实现 SentinelTracerProcessorSlotEntryCallback 的三个核心方法 buildSpan - 创建 Skywalking 的埋点 Span 对象outputSpan - 输出相关埋点数据的键值对到 Skywalking 的埋点 Span 对象中finishSpan - 提交 Skywalking 的埋点 Span 对象到 Skywalking Server public class SentinelSkywalkingTracerProcessorSlotEntryCallback extends SentinelTracerProcessorSlotEntryCallbackSpan {private Tracer tracer new SkywalkingTracer();Overrideprotected Span buildSpan() {return tracer.buildSpan(SentinelStrategyConstant.SPAN_NAME).startManual();}Overrideprotected void outputSpan(Span span, String key, String value) {span.setTag(key, value);}Overrideprotected void finishSpan(Span span) {span.finish();} } 实现 Sentinel InitFunc SPI 扩展 实现 SPI 的扩展切入类 public class SentinelSkywalkingTracerInitFunc implements InitFunc {Overridepublic void init() throws Exception {StatisticSlotCallbackRegistry.addEntryCallback(SentinelSkywalkingTracerProcessorSlotEntryCallback.class.getName(), new SentinelSkywalkingTracerProcessorSlotEntryCallback());} } 把 SPI 的扩展切入类放置 \resources\META-INF\services\com.alibaba.csp.sentinel.init.InitFunc 文件中内容为 com.nepxion.discovery.plugin.strategy.sentinel.skywalking.monitor.SentinelSkywalkingTracerInitFunc 摘自 Nepxion Discovery 开源社区 对于 Sentinel 跟 Opentracing Skywalking Jaeger 的集成可参考 https://github.com/Nepxion/Discovery 中的 discovery-plugin-strategy-sentinel-starter-opentracing discovery-plugin-strategy-sentinel-starter-skywalking 等模块。 最终在 Skywalking 全链路界面上输出如下 全链路调用链中我们可以看到 solar-service-a 服务的链路上输出了 SENTINEL 埋点表示 solar-service-a 上发生了 Sentinel 限流熔断降级事件之一。 点击 SENTINEL 埋点在呼出的内容看板上我们可以看到 solar-service-a 服务发生了限流事件上面显示限流的规则和异常信息以及微服务 Solar 指标等一系列参数。 我们可以点击界面上边的【熔断查询】进行 Sentinel 相关数据的分析和统计 Sentinel 集成 InfluxDB Grafana 监控数据持久化到 InfluxDB ① Sentinel MetricFetcher 拉取数据 实现 Dashboard 服务端拉取 Sentinel 客户端即 Solar 微服务的监控数据 Component public class MetricFetcher {AutowiredQualifier(influxDBMetricRepository)private MetricsRepositoryMetricEntity metricStore;... } ② InfluxDB 实例初始化 Configuration public class InfluxDBAutoConfiguration {Value(${spring.influx.url})private String influxDBUrl;Value(${spring.influx.user})private String userName;Value(${spring.influx.password})private String password;Value(${spring.influx.database})private String database;Beanpublic InfluxDB influxDB() {InfluxDB influxDB null;try {influxDB InfluxDBFactory.connect(influxDBUrl, userName, password);influxDB.setDatabase(database).enableBatch(100, 1000, TimeUnit.MILLISECONDS);influxDB.setLogLevel(InfluxDB.LogLevel.NONE);} catch (Exception e) {LOG.error(e.getMessage());}return influxDB;} } ③ Sentinel 数据写入到 InfluxDB Component(influxDBMetricRepository) public class InfluxDBMetricRepository implements MetricsRepositoryMetricEntity {Autowiredprivate InfluxDB influxDB;Overridepublic void save(MetricEntity metric) {try {Point point createPoint(metric);influxDB.write(point);} catch (Exception e) {LOG.error(e.getMessage());}}Overridepublic void saveAll(IterableMetricEntity metrics) {if (metrics null) {return;}try {BatchPoints batchPoints BatchPoints.builder().build();metrics.forEach(metric - {Point point createPoint(metric);batchPoints.point(point);});influxDB.write(batchPoints);} catch (Exception e) {LOG.error(e.getMessage());}} } Grafana 界面展现监控数据 Sentinel Limit-App 熔断扩展 掌门1对1已经实现通过灰度蓝绿发布方式实现对流量的精确制导和调拨但为了进一步实施更安全的流量保障引入了基础指标和灰度蓝绿发布指标的熔断同时也支持业务自定义指标和组合指标的熔断。 通过对 Sentinel Limit-App机制的扩展并定制授权规则实现微服务 Solar 的熔断扩展。对于授权规则中涉及到的参数简要做如下说明 resource 为 SentinelResource 注解的 value 也可以是调用的 URL 路径值limitApp 如果有多个可以通过 , 分隔。特别注意下文为了描述简单只以单个为例strategy 为 0 表示白名单符合条件就放行流量 strategy 为 1 表示黑名单符合条件就限制流量。特别注意下文为了描述简单只以白名单为例 基础指标的熔断 通过 Http Header 自动携带下游服务的基础指标进行全链路传递的方式对下游调用实施基础指标的熔断。支持如下指标 ① 服务名 当 A 服务发送请求到 B 服务所携带的 A 服务名不满足条件该请求就会被 B 服务熔断。 B 服务增加配置项 spring.application.strategy.service.sentinel.request.origin.keyn-d-service-id B 服务增加授权规则 limitApp 为 A 服务名 [{resource: sentinel-resource,limitApp: a-service-id,strategy: 0} ] ② 服务的 APPID 当 A 服务发送请求到 B 服务所携带的 A 服务的 APPID 不满足条件该请求就会被 B 服务熔断。 B 服务增加配置项 spring.application.strategy.service.sentinel.request.origin.keyn-d-service-app-id B 服务增加授权规则 limitApp 为 A 服务的 APPID [{resource: sentinel-resource,limitApp: a-service-app-id,strategy: 0} ] ③ 服务实例所在的 IP 地址和 Port 端口 当 A 服务发送请求到 B 服务所携带的 A 服务的 IP 地址和 Port 端口不满足条件该请求就会被 B 服务熔断。 B 服务增加配置项 spring.application.strategy.service.sentinel.request.origin.keyn-d-service-address B 服务增加授权规则 limitApp 为 A 服务实例所在的 IP 地址和 Port 端口 [{resource: sentinel-resource,limitApp: a-ip:a-port,strategy: 0} ] 灰度蓝绿发布指标的熔断 通过 Http Header 自动携带下游服务的灰度蓝绿发布指标进行全链路传递的方式对下游调用实施灰度蓝绿发布指标的熔断。支持如下指标 ① 服务所在的组名 当 A 服务发送请求到 B 服务所携带的 A 服务的组名和 B 服务的组名不一致该请求就会被 B 服务熔断。 B 服务增加配置项 spring.application.strategy.service.sentinel.request.origin.keyn-d-service-group B 服务增加授权规则 limitApp 为 B 服务的组名 [{resource: sentinel-resource,limitApp: b-group,strategy: 0} ] ② 服务版本号 当 A 服务发送请求到 B 服务所携带的 A 服务的版本号和 B 服务的版本号不一致该请求就会被 B 服务熔断。 B 服务增加配置项 spring.application.strategy.service.sentinel.request.origin.keyn-d-service-version B 服务增加授权规则 limitApp 为 B 服务的版本号 [{resource: sentinel-resource,limitApp: b-version,strategy: 0} ] ③ 服务所在的区域 当 A 服务发送请求到 B 服务所携带的 A 服务的区域值和 B 服务的区域值不一致该请求就会被 B 服务熔断。 B 服务增加配置项 spring.application.strategy.service.sentinel.request.origin.keyn-d-service-region B 服务增加授权规则 limitApp 为 B 服务的区域值 [{resource: sentinel-resource,limitApp: b-region,strategy: 0} ] ④ 服务所在的子环境 当 A 服务发送请求到 B 服务所携带的 A 服务的子环境值和 B 服务的子环境值不一致该请求就会被 B 服务熔断。 B 服务增加配置项 spring.application.strategy.service.sentinel.request.origin.keyn-d-service-env B 服务增加授权规则 limitApp 为 B 服务的子环境值 [{resource: sentinel-resource,limitApp: b-env,strategy: 0} ] 业务自定义指标的熔断 通过 Http Header 携带下游服务的业务自定义指标进行全链路传递的方式对下游调用实施自定义指标的熔断。 当 A 服务发送请求到 B 服务所携带的 A 的自定义指标不满足条件该请求就会被 B 服务熔断。例如 A 服务把 userName 通过 Http Header 传递给 B 服务而 B 服务只接受 userName 为 zhangsan 的请求那么我们可以通过如下方式来解决 B 服务通过适配类实现 Sentinel Origin 值的解析 public class MyServiceSentinelRequestOriginAdapter extends AbstractServiceSentinelRequestOriginAdapter {Overridepublic String parseOrigin(HttpServletRequest request) {return request.getHeader(userName);} } B 服务的配置类里通过 Bean 方式进行适配类创建 Bean public ServiceSentinelRequestOriginAdapter ServiceSentinelRequestOriginAdapter() {return new MyServiceSentinelRequestOriginAdapter(); } B 服务增加授权规则 limitApp 为 zhangsan [{resource: sentinel-resource,limitApp: zhangsan,strategy: 0} ] 假如该方式仍未能满足业务场景业务系统希望根据 userName 获取 userType根据用户类型做统一熔断例如用户类型为 AUTH_USER 的请求才能放行其它都熔断那么我们可以把上面的例子修改如下 B 服务的适配类更改如下 public class MyServiceSentinelRequestOriginAdapter extends AbstractServiceSentinelRequestOriginAdapter {Overridepublic String parseOrigin(HttpServletRequest request) {String userName request.getHeader(userName);String userType getUserTypeByName(userName); return userType;} } B 服务的授权规则更改如下 [{resource: sentinel-resource,limitApp: AUTH_USER,strategy: 0} ] 组合指标的熔断 通过 Http Header 携带下游服务的业务自定义指标、基础指标或者灰度蓝绿发布指标进行全链路传递的方式对下游调用实施组合指标的熔断例如根据传入的微服务版本号 用户名组合在一起进行熔断。下面示例表示为下游服务版本为 1.0 且 userName 为 zhangsan同时满足这两个条件下所有服务的请求允许被放行否则被熔断。 B 服务的适配类更改如下 public class MyServiceSentinelRequestOriginAdapter extends AbstractServiceSentinelRequestOriginAdapter {Overridepublic String parseOrigin(HttpServletRequest request) {String version request.getHeader(DiscoveryConstant.N_D_SERVICE_VERSION);String userName request.getHeader(userName);return version userName;} } B 服务的授权规则更改如下 [{resource: sentinel-resource,limitApp: 1.0zhangsan,strategy: 0} ] Sentinel 网关流控实践 阐述网关流控实践的时候我们使用精确匹配的方式对某个服务的请求做限流控制为例对网关代理的 solar-service-a 服务的接口 /inspector/inspect 做限流控制为例。 API 分组管理 API 管理页面里添加 solar-service-a 并精确匹配串 /inspector/inspect 网关流控规则 在流控规则界面里配置相关的规则 最终在 Skywalking 全链路界面上输出如下跟 Solar 服务侧 Sentinel 埋点相似不一一阐述了 Sentinel 集群限流实践 我们采用 Sentinel 官方提供的嵌入式 Token Server 解决方案即服务集群中选择一个节点做为 Token Server 同时该节点也作为 Token Client 响应外部的请求的服务器。具体实现方式通过 Sentinel 实现预留的 SPI InitFunc 接口可以参考官方 sentinel-demo 模块下面的 sentinel-demo-cluster-embedded 。 public class SentinelApolloTokenClusterInitFunc implements InitFunc {Overridepublic void init() throws Exception {// Register client dynamic rule data source.initDynamicFlowRuleProperty();initDynamicParamRuleProperty();// Register token client related data source.// Token client common config:ClusterClientConfigInitializer.doInit();// Token client assign config (e.g. target token server) retrieved from assign map:ClusterClientAssignConfigInitializer.doInit();// Register token server related data source.// Register dynamic rule data source supplier for token server:ClusterRuleSupplierInitializer.doInit();// Token server transport config extracted from assign map:ServerTransportConfigInitializer.doInit();// Init cluster state property for extracting mode from cluster map data source.ClusterStateInitializer.doInit();// ServerFlowConfig 配置ServerFlowConfigInitializer.doInit();} } 把 SPI 的扩展切入类放置 \resources\META-INF\services\com.alibaba.csp.sentinel.init.InitFunc 文件中内容为 com.zhangmen.solar.sentinel.SentinelApolloTokenClusterInitFunc 作者介绍 任浩军掌门基础架构部研发经理。曾就职于平安银行、万达、惠普曾负责平安银行平台架构部 PaaS 平台基础服务框架研发。10 多年开源经历Github IDHaojunRenNepxion 开源社区创始人Nacos Group MemberSpring Cloud Alibaba  Nacos  Sentinel  OpenTracing Committer。 张彬彬掌门基础架构部架构师。主要负责公司微服务架构以及开源项目的开发和实践开源项目爱好者多年互联网开发经验。 非常感谢阿里巴巴 Sentinel 项目负责人宿何在落地过程中的支持和帮助。 监控 Java 中间件 API Nacos 开发工具 时序数据库 Sentinel 微服务 Spring 版权声明本文首发在云栖社区遵循云栖社区版权声明本文内容由互联网用户自发贡献版权归用户作者所有云栖社区不为本文内容承担相关法律责任。云栖社区已升级为阿里云开发者社区。如果您发现本文中有涉嫌抄袭的内容欢迎发送邮件至developer2020service.aliyun.com 进行举报并提供相关证据一经查实阿里云开发者社区将协助删除涉嫌侵权内容。 原文链接 本文为云栖社区原创内容未经允许不得转载。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/89894.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用cms快速搭建商业网站网页版梦幻西游谛听怎么获得

源起年初我们在找一款框架,希望它有如下几个特点:学习成本低只需要学.Net每年主推的技术栈和业务特性必须支持的中间件,给开发同学减负,只需要专注业务就好个人见解:一款好用的框架应该是补充,而不是颠覆或…

给网站做绝对路径wordpress 百度翻译

1、题目描述 【题目链接】 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 请注意 ,必须在不复制数组的情况下原地对数组进行操作。 示例 1: 输入: nums [0,1,0,3,12] 输出: [1,3,12,0,0] 示例…

做网站建设的目的到哪里学平面设计

图1 多普勒效应 1、径向速度 径向速度是作用于雷达或远离雷达的速度的一部分。 图2 不同的速度 2、喷气发动机调制 JEM是涡轮机的压缩机叶片的旋转的多普勒频率。 3、多普勒困境 最大无模糊范围需要尽可能低的PRF; 最大无模糊速度需要尽可能高的PRF&#xff1b…

网站设计开户女生网站开发

注解 什么是注解 Java 注解(Annotation)是 JDK 5.0 引入的一种元素,用于为 Java 代码提供元数据。元数据是关于数据的数据,它为代码提供附加信息,而这些信息并不直接参与到程序的逻辑中,但可以被编译器或…

辽宁建设工程信息网官网新网站是哪个常规网站服务器

选择Spring Boot主要是考虑到它既能兼顾Spring的强大功能,还能实现快速开发的便捷。我想大多数人也是出于这个原因选择了Spring Boot,如果不是特殊应用场景,就只需要在application.properties中完成一些属性配置就能开启各模块的应用。而不像传统的XML配…

计算机应用技术 网站开发免费ppt模板简约

在官方文档里面,修改标记的图形(symbol)的方法有三种: 一:ECharts 提供的标记类型有 ‘circle’, ‘rect’, ‘roundRect’, ‘triangle’, ‘diamond’, ‘pin’, ‘arrow’, ‘none’;例:sym…

西安seo网站建设单页

一、V2版本细节升级 1、YOLO-V2: 更快!更强 1.1 做的改进内容 1. YOLO-V2-Batch Normalization V2版本舍弃Dropout,卷积后每一层全部加入Batch Normalization网络的每一层的输入都做了归一化,收敛相对更容易经过Batch Norma…

免费源码下载网站网站开发字体的引用

5月26日上午,康佳之星携手青岛蓝谷管理局、斯坦福青岛研究院、海尔海创汇联合举办的第二届硅谷创新加速营第五讲顺利完成。斯坦福青岛研究院董事长的Claude Leglise先生做客直播间,为现场创业者、企业家讲授创业之路必修课:企业财务规划。本讲…

代运营网站建设仿站定制模板建站

前言 Java 是一门强大而广泛应用的编程语言,它的灵活性和跨平台特性使其成为许多开发者的首选。无论您是刚刚入门编程,还是已经有一些编程经验,掌握 Java 的基础知识都是构建更复杂程序的关键。 本学习笔记旨在帮助您深入了解 Java 编程语言…

外语网站开发asp网站防注入

数字图书馆是一个开放式的硬件和软件的集成平台,通过对技术和产品的集成,把当前大量的各种文献载体数字化,将它们组织起来在网上服务。从理论上讲,数字图书馆是一种引入管理和应用数字化技术的方法,它的主要特点有&…

网站美工建设意见h5开发环境搭建

前言 HTTP 具有相当优秀和方便的一面,然而 HTTP 并非只有好的一面,事物皆具两面性,它也是有不足之处的。例如: 通信使用明文(不加密),内容可能会被窃听。不验证通信方的身份,因此有可能会遭遇…

烟台专业做网站的公司app引流推广方法

1.查询mysql的存储执行目录(secure-file-priv是指定文件夹作为导出文件存放的地方)所以需要查询以下,不然会报1290错误 show variables like %secure%;2.查询并转存 SELECT * into outfile C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\zo…

网站建设流量从哪里来seo词库排行

1. 公共字段自动填充的作用 当我们开发一个项目时,我们可能会对几个字段重复的进行填写;例如:当我们在修改一个用户时,或者添加一个用户时,我们都需要将它的修改人、修改时间给赋值,如果我们每次就进行手动…

投诉网站制作临沭做网站

本文恩主要介绍了详解HTML5 录音的踩坑之旅,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望能帮助到大家。说实话,一开始都没接触过 HTML5 的 Audio API,而且要基于在我们…

phpcms做的网站备案期间 网站想正常

(请先看置顶博文)本博打开方式,请详读_liO_Oil的博客-CSDN博客_怎么把androidstudio卸载干净 前几天在编写代码的时候,突然要根据结构体的属性进行从小到大的排序,这即是我写这篇文章的导火索。 正如大家所知…

建网站有哪些文件夹wap网站现在还有什么用

乐观学习,乐观生活,才能不断前进啊!!! 我的主页:optimistic_chen 我的专栏:c语言 点击主页:optimistic_chen和专栏:c语言, 创作不易,大佬们点赞鼓…

盐城永祥建设有限公司网站宁波网站建设哪家比较好

当涉及到互联网性能和可用性优化时,DNS(Domain Name System)和CDN(Content Delivery Network)是两个至关重要的元素。它们各自发挥着关键作用,以确保用户能够快速、可靠地访问网站和应用程序。在本文中&…

天河网站建设企业科技公司名字大全

一.使用 Go 语言的开源框架Livego搭建流媒体服务器 1.Livego 框架的介绍 Go 语言拥有强大的 服务器性能 ,golang 在语言级别解决了 多进程并发 的问题,支持 多核 CPU均衡使用 ,支持 海量轻量级线程 ,所以非常适合做 流媒体服务器 .而 livego 是基于golang 开发的简单高效的…

意大利做包招工的网站邯郸市网

我无法将我的Web应用程序与MySQL 5.5.11后端部署到JBoss 5.我收到此错误:引起:java.lang.ClassNotFoundException:来自BaseClassLoader 262b2310的com.mysql.jdbc.Driver我在下面粘贴了我的堆栈跟踪.这就是我所做的……我将mysql-connector-…

网站建设公司工作岗位说明书南充移动网站建设

各位CSDN的uu们好呀,今天,小雅兰的内容是51单片机中的定时器以及按键控制LED流水灯模式&定时器时钟,下面,让我们进入51单片机的世界吧!!! 定时器 按键控制LED流水灯模式 定时器时钟 源代…