当前位置: 首页 > news >正文

上海由多少家网站建设公司长沙seo代理商

上海由多少家网站建设公司,长沙seo代理商,广告设计公司实践报告,购买一级域名做网站一.sentinel规则推送原理 1.原有内存规则存储原理 (1)dashborad中请求到服务器后,在controller中通过http把规则直接推送给client,client接收后把规则放入内存; 2.持久化推送规则原理 ![在这里插入代码片](https://img-blog.csdnimg.cn/1…

一.sentinel规则推送原理

1.原有内存规则存储原理

(1)dashborad中请求到服务器后,在controller中通过http把规则直接推送给client,client接收后把规则放入内存;

2.持久化推送规则原理

![在这里插入代码片](https://img-blog.csdnimg.cn/16a99e8e725a4eb6a7011f36ec7f70e0.png)

一.sentinel持久化改造

1.改造dashboard

(1)sentinel提供了持久化方案的数据源,将 test 这一行注释掉

<!-- for Nacos rule publisher sample --><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId><version>${sentinel.project.version}</version>
<!--            <scope>test</scope>--></dependency>

(2)引入nacos配置中心和注册中心

 <!-- Nacos注册中心 --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!-- Nacos配置中心 --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency>

(3)添加远程来取配置的bean

在这里插入图片描述

(3)添加从远程配置中心拉取规则

1./v1/flow/rules(GET)请求中把”从客户端内存获取规则配置“修改成”从远程配置中心获取规则配置“

![在这里插入图片描述](https://img-blog.csdnimg.cn/38054ed9356b4e40a355d45079590389.png在这里插入图片描述

2.从nacos中拉取配置,DynamicRuleProvider实现这个接口用来拉取配置的扩展接口,List泛型类list表示配置有多条FlowRuleEntity返回到控制台的实体信息,注入ConfigService配置中心的核心接口,这里从nacos拉到的数组对象是FlowRule,所以需要通过”FlowRuleEntity.fromFlowRule(appName,ip,port,rule))“转换成FlowRuleEntity;

![在这里插入图片描述](https://img-blog.csdnimg.cn/c1289d8c77364744a9cc509754fde0e1.png在这里插入图片描述

(4)将控制台添加的规则信息推送到nacos中

1./v1/flow/rule(POST)请求中把“发布规则到客户端内存中”修改成“发布规则到远程配置中心”

在这里插入图片描述
在这里插入图片描述

2.把dashboard服务内存中的配置推送到nacos中,DynamicRulePublisher实现这个接口用来推送配置的扩展接口,List泛型类list表示配置有多条FlowRuleEntity返回到控制台的实体信息,注入ConfigService配置中心的核心接口,这里推送打nacos中的对象是FlowRule,所以需要通过”NacosConfigUtil.convertToRule(rules)“转换成FlowRule;

在这里插入图片描述
在这里插入图片描述

(5)将控制台添加的规则信息推送到nacos中如果是Gateway网关则需要该如下两个类

![在这里插入图片描述](https://img-blog.csdnimg.cn/1ba449a40e5c4ae29b7c8a87a7714286.png
在这里插入图片描述

(5)注入nacos操作配置中心的核心bean ConfigService和FlowRuleEntity与FlowRule转换工具类

在这里插入图片描述

/** Copyright 1999-2018 Alibaba Group Holding Ltd.** 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**      http://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.csp.sentinel.dashboard.rule.nacos;import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigFactory;
import com.alibaba.nacos.api.config.ConfigService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.Properties;/*** @author Fox*/
@Configuration
public class NacosConfig {@Value("${spring.cloud.nacos.discovery.server-addr}")private String serverAddr;@Value("${spring.cloud.nacos.discovery.username}")private String username;@Value("${spring.cloud.nacos.discovery.password}")private String password;@Value("${spring.cloud.nacos.discovery.namespace:}")private String namespace;@Beanpublic ConfigService nacosConfigService() throws Exception {
//        return ConfigFactory.createConfigService(serverAddr);Properties properties = new Properties();properties.setProperty(PropertyKeyConst.SERVER_ADDR, serverAddr);properties.setProperty(PropertyKeyConst.USERNAME, username);properties.setProperty(PropertyKeyConst.PASSWORD, password);if (!StringUtils.isEmpty(namespace)) {properties.setProperty(PropertyKeyConst.NAMESPACE, namespace);}return ConfigFactory.createConfigService(properties);}}
/** Copyright 1999-2018 Alibaba Group Holding Ltd.** 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**      http://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.csp.sentinel.dashboard.rule.nacos;import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.RuleEntity;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;/*** @author Fox*/
public final class NacosConfigUtil {public static final String GROUP_ID = "SENTINEL_GROUP";public static final String FLOW_DATA_ID_POSTFIX = "-flow-rules";public static final String PARAM_FLOW_DATA_ID_POSTFIX = "-param-flow-rules";public static final String DEGRADE_DATA_ID_POSTFIX = "-degrade-rules";public static final String SYSTEM_DATA_ID_POSTFIX = "-system-rules";public static final String AUTHORITY_DATA_ID_POSTFIX = "-authority-rules";public static final String GATEWAY_FLOW_DATA_ID_POSTFIX = "-gateway-flow-rules";public static final String GATEWAY_API_DATA_ID_POSTFIX = "-gateway-api-rules";public static final String CLUSTER_MAP_DATA_ID_POSTFIX = "-cluster-map";/*** cc for `cluster-client`*/public static final String CLIENT_CONFIG_DATA_ID_POSTFIX = "-cc-config";/*** cs for `cluster-server`*/public static final String SERVER_TRANSPORT_CONFIG_DATA_ID_POSTFIX = "-cs-transport-config";public static final String SERVER_FLOW_CONFIG_DATA_ID_POSTFIX = "-cs-flow-config";public static final String SERVER_NAMESPACE_SET_DATA_ID_POSTFIX = "-cs-namespace-set";//超时时间public static final int READ_TIMEOUT = 3000;private NacosConfigUtil() {}/*** RuleEntity----->Rule* @param entities* @return*/public static String convertToRule(List<? extends RuleEntity> entities){return JSON.toJSONString(entities.stream().map(r -> r.toRule()).collect(Collectors.toList()));}/*** ApiDefinitionEntity----->ApiDefinition* @param entities* @return*/public static String convertToApiDefinition(List<? extends ApiDefinitionEntity> entities){return JSON.toJSONString(entities.stream().map(r -> r.toApiDefinition()).collect(Collectors.toList()));}/*** GatewayFlowRuleEntity----->GatewayFlowRule* @param entities* @return*/public static String convertToGatewayFlowRule(List<? extends GatewayFlowRuleEntity> entities){return JSON.toJSONString(entities.stream().map(r -> r.toGatewayFlowRule()).collect(Collectors.toList()));}}

(5)dashboard配置文件修改

1.添加bootstrap.yml配置文件

spring:cloud:nacos:discovery:server-addr: 127.0.0.1:8848username: nacospassword: nacosnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224c# group: DEFAULT_GROUPconfig:server-addr: 127.0.0.1:8848username: nacospassword: nacosnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224c# group: DEFAULT_GROUPfile-extension: yml  # 必须修改成对应尾序refresh-enabled: trueprofiles:active: devapplication:name: scm-sentinel-dashboard

2.nacos中添加scm-sentinel-dashboard-dev.yml配置文件,这里是将原来的application.properties配置放入到nacos配置中心中管理

server:port: 8099max-http-header-size: 10240tomcat:uri-encoding: UTF-8min-spare-threads: 50max-threads: 500max-connections: 3000accept-count: 10000connection-timeout: 12000servlet:encoding:force: truecharset: UTF-8enabled: truesession: cookie: name: sentinel_dashboard_cookie
logging: level: org: springframework: web: INFOfile:# name: ${user.home}/logs/csp/sentinel-dashboard.logname: /mnt/server-log/scm-sentinel-dashboard/sentinel-dashboard.logpattern: file: '%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n'
auth: filter: exclude-urls: /,/auth/login,/auth/logout,/registry/machine,/versionexclude-url-suffixes: htm,html,js,css,map,ico,ttf,woff,pngusername: sentinelpassword: sentinelsentinel: dashboard: version: '@project.version@'

2.改造client

1.gateway网关改造

(1)引入pom依赖

<!-- gateway接入sentinel  --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId><version>${spring.cloud.alibaba.version}</version></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId><version>${spring.cloud.alibaba.version}</version></dependency><!--sentinel持久化 --><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId><version>1.8.4</version></dependency>

(2)配置文件bootstrap.yml

spring:cloud:nacos:discovery:server-addr: 127.0.0.1:8848username: nacospassword: nacosnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224c# group: DEFAULT_GROUPconfig:server-addr: 127.0.0.1:8848username: nacospassword: nacosnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224c# group: DEFAULT_GROUPfile-extension: yml  # 必须修改成对应尾序refresh-enabled: trueshared-configs[0]:data-id: scm-gateway-sentinel.ymlrefresh: trueprofiles:active: devapplication:name: scm-open-gateway

(2)nacos中的配置文件scm-gateway-sentinel.yml,这里面的spring.application.name对象项目名称,注意rule-type表示流控类型

spring:cloud:nacos:sentinel:transport:dashboard: 127.0.0.1:8099# 该配置能够使dashboard主动发现该应用eager: truedatasource:gateway-api:nacos:server-addr: ${spring.cloud.nacos.discovery.server-addr}dataId: ${spring.application.name}-gateway-api-rulesgroupId: SENTINEL_GROUP   # 注意groupId对应Sentinel Dashboard中的定义namespace: ${spring.cloud.nacos.discovery.namespace}data-type: jsonrule-type: gw-api-groupflow-rules:nacos:server-addr: ${spring.cloud.nacos.discovery.server-addr}dataId: ${spring.application.name}-gateway-flow-rulesgroupId: SENTINEL_GROUP   # 注意groupId对应Sentinel Dashboard中的定义namespace: ${spring.cloud.nacos.discovery.namespace}data-type: jsonrule-type: flowdegrade-rules:nacos:server-addr: ${spring.cloud.nacos.discovery.server-addr}dataId: ${spring.application.name}-gateway-degrade-rulesgroupId: SENTINEL_GROUPnamespace: ${spring.cloud.nacos.discovery.namespace}data-type: jsonrule-type: degradeparam-flow-rules:nacos:server-addr: ${spring.cloud.nacos.discovery.server-addr}dataId: ${spring.application.name}-gateway-param-flow-rulesgroupId: SENTINEL_GROUPnamespace: ${spring.cloud.nacos.discovery.namespace}data-type: jsonrule-type: param-flowauthority-rules:nacos:server-addr: ${spring.cloud.nacos.discovery.server-addr}dataId: ${spring.application.name}-gateway-authority-rulesgroupId: SENTINEL_GROUPnamespace: ${spring.cloud.nacos.discovery.namespace}data-type: jsonrule-type: authoritysystem-rules:nacos:server-addr: ${spring.cloud.nacos.discovery.server-addr}dataId: ${spring.application.name}-gateway-system-rulesgroupId: SENTINEL_GROUPnamespace: ${spring.cloud.nacos.discovery.namespace}data-type: jsonrule-type: system

(3) rule-type: gw-api-group对应的是网关中的API管理,这里用来与流控规则中API分钟的API名称对应

在这里插入图片描述
在这里插入图片描述

2.普通服务改造

(1)添加pom依赖

 <!-- nacos服务注册与发现 --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!-- openfeign 远程调用 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency><!--sentinel --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId></dependency>

(1)添加bootstrap.yml流控规则nacoa配置和sentinel控制台连接配置

server:port: 8806spring:application:name: mall-user-sentinel-rule-push-demo  #微服务名称#配置nacos注册中心地址cloud:nacos:discovery:server-addr: 127.0.0.1:8848username: nacospassword: nacosnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224csentinel:transport:# 添加sentinel的控制台地址dashboard: 127.0.0.1:8099# 指定应用与Sentinel控制台交互的端口,应用本地会起一个该端口占用的HttpServer#port: 8719datasource:
#        ds1:   #名称自定义,唯一
#          nacos:
#            server-addr: 127.0.0.1:8848
#            dataId: ${spring.application.name}-flow
#            groupId: DEFAULT_GROUP
#            data-type: json
#            rule-type: flowflow-rules:nacos:server-addr: 127.0.0.1:8848dataId: ${spring.application.name}-flow-rulesgroupId: SENTINEL_GROUP   # 注意groupId对应Sentinel Dashboard中的定义namespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224cdata-type: jsonrule-type: flowdegrade-rules:nacos:server-addr: 127.0.0.1:8848dataId: ${spring.application.name}-degrade-rulesgroupId: SENTINEL_GROUPnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224cdata-type: jsonrule-type: degradeparam-flow-rules:nacos:server-addr: 127.0.0.1:8848dataId: ${spring.application.name}-param-flow-rulesgroupId: SENTINEL_GROUPnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224cdata-type: jsonrule-type: param-flowauthority-rules:nacos:server-addr: 127.0.0.1:8848dataId: ${spring.application.name}-authority-rulesgroupId: SENTINEL_GROUPnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224cdata-type: jsonrule-type: authoritysystem-rules:nacos:server-addr: 127.0.0.1:8848dataId: ${spring.application.name}-system-rulesgroupId: SENTINEL_GROUPnamespace: c5b4bd27-4a9c-487f-b3fb-c6a768ee224cdata-type: jsonrule-type: systemmain:allow-bean-definition-overriding: true#暴露actuator端点   http://localhost:8800/actuator/sentinel
management:endpoints:web:exposure:include: '*'feign:sentinel:enabled: true   #开启sentinel对feign的支持 默认false

3.持久化源码

(1)NacosDataSource:

1.NacosDataSource:自定义的nacos数据源类,继承了AbstractDataSource抽象类是sentinel的持久化数据源的父类,用于持久化扩展;
2.NacosDataSource.readSource()->configService.getConfig()方法读取nacos中的配置;
3.NacosDataSource 构造器-> this.configListener = new Listener() -> receiveConfigInfo()方法,当dashboard中改变配置后,dashboard服务会降配置先推送到nacos配置中心,然后nacos中的规则数据感知到变化后nacos配置中心会发布这个监听事件,此监听器就会监听到最新配置的变化然后更新本地缓存的配置达到实时更新的目的;(注意配置没用变化是不会触发监听事件)

(2)FlowRuleManager:流控规则管理类,负责加载流控规则;

(3)ConfigService是用来拿到nacos配置中心bean对象,使用configService.publishConfig()推送sentinel持久化数据到nacos中心;试用ConfigFactory.createConfigService(properties)创建ConfigService;


文章转载自:
http://dinncounemployed.tqpr.cn
http://dinncoceliac.tqpr.cn
http://dinncocompendium.tqpr.cn
http://dinncoabrogate.tqpr.cn
http://dinncophytozoon.tqpr.cn
http://dinncorhinopharynx.tqpr.cn
http://dinncorapid.tqpr.cn
http://dinncodreamscape.tqpr.cn
http://dinncodemographer.tqpr.cn
http://dinncofrcm.tqpr.cn
http://dinncoanionic.tqpr.cn
http://dinncobright.tqpr.cn
http://dinncoburgage.tqpr.cn
http://dinncodottiness.tqpr.cn
http://dinncotoothcomb.tqpr.cn
http://dinncosemihexagonal.tqpr.cn
http://dinncoalt.tqpr.cn
http://dinncointimism.tqpr.cn
http://dinncocelebrative.tqpr.cn
http://dinncotrainman.tqpr.cn
http://dinncocochlear.tqpr.cn
http://dinncoadjacence.tqpr.cn
http://dinncopattypan.tqpr.cn
http://dinncomakkoli.tqpr.cn
http://dinncocapsid.tqpr.cn
http://dinncoethanamide.tqpr.cn
http://dinncoanfractuous.tqpr.cn
http://dinnconeedful.tqpr.cn
http://dinncoanaheim.tqpr.cn
http://dinncocheliceral.tqpr.cn
http://dinncomegagamete.tqpr.cn
http://dinncoaccentuator.tqpr.cn
http://dinncoarmenoid.tqpr.cn
http://dinncodictation.tqpr.cn
http://dinncojaggy.tqpr.cn
http://dinncohomozygotic.tqpr.cn
http://dinncodischarge.tqpr.cn
http://dinncodecahedron.tqpr.cn
http://dinncodeathbed.tqpr.cn
http://dinncoundisturbedly.tqpr.cn
http://dinncokyoodle.tqpr.cn
http://dinncoduodenary.tqpr.cn
http://dinncotolley.tqpr.cn
http://dinncokinkajou.tqpr.cn
http://dinncomecometer.tqpr.cn
http://dinncouncorruptible.tqpr.cn
http://dinncoemptying.tqpr.cn
http://dinncokilobit.tqpr.cn
http://dinncononet.tqpr.cn
http://dinncovexillary.tqpr.cn
http://dinncomarguerite.tqpr.cn
http://dinncojailbird.tqpr.cn
http://dinncoredouble.tqpr.cn
http://dinncoaquosity.tqpr.cn
http://dinncocacographer.tqpr.cn
http://dinncokarnaugh.tqpr.cn
http://dinncooverabundance.tqpr.cn
http://dinncophilippians.tqpr.cn
http://dinncoflogging.tqpr.cn
http://dinncomonkey.tqpr.cn
http://dinncorenardite.tqpr.cn
http://dinncoapiece.tqpr.cn
http://dinncoglucocorticoid.tqpr.cn
http://dinncolifer.tqpr.cn
http://dinncosovnarkhoz.tqpr.cn
http://dinncospell.tqpr.cn
http://dinncocassandra.tqpr.cn
http://dinncoshemitic.tqpr.cn
http://dinncosubaverage.tqpr.cn
http://dinncoagana.tqpr.cn
http://dinncoinconnu.tqpr.cn
http://dinncominotaur.tqpr.cn
http://dinncoelding.tqpr.cn
http://dinncoutilitarianism.tqpr.cn
http://dinncobesotted.tqpr.cn
http://dinncodepict.tqpr.cn
http://dinncowedeling.tqpr.cn
http://dinncoplonko.tqpr.cn
http://dinncothunderstroke.tqpr.cn
http://dinncointuitional.tqpr.cn
http://dinncoyewk.tqpr.cn
http://dinncotickey.tqpr.cn
http://dinncofibroadenoma.tqpr.cn
http://dinncoshameful.tqpr.cn
http://dinncoactinozoan.tqpr.cn
http://dinncogoth.tqpr.cn
http://dinncoderepressor.tqpr.cn
http://dinncobursary.tqpr.cn
http://dinncozoetrope.tqpr.cn
http://dinncoimmanence.tqpr.cn
http://dinncotemperable.tqpr.cn
http://dinncohierarch.tqpr.cn
http://dinncohydrogasifier.tqpr.cn
http://dinncopronator.tqpr.cn
http://dinncosrs.tqpr.cn
http://dinncopettily.tqpr.cn
http://dinncoweathercoat.tqpr.cn
http://dinncohemizygous.tqpr.cn
http://dinncosyphilous.tqpr.cn
http://dinncoataxia.tqpr.cn
http://www.dinnco.com/news/2712.html

相关文章:

  • wordpress公众号登录谷歌seo排名优化
  • 土豆网网站开发源代码台州百度关键词排名
  • 做那个的网站交换友情链接平台
  • 招聘网站可以同时做两份简历吗热搜关键词
  • wordpress设置邮件提醒网站优化 推广
  • 做网站咋赚钱河南平价的seo整站优化定制
  • 视频网站系统开发淘客推广
  • 企业应该如何进行网站建设百度关键词推广可以自己做吗
  • 东莞凤岗网站建设制作广告公司职位
  • wordpress购物网站手机nba最新交易一览表
  • 网站建设女王节文案抖音关键词优化排名靠前
  • 2345浏览器电脑版网站关键词优化多少钱
  • 外包一个企业网站多少钱惠州seo建站
  • 论坛网站怎么做跳转有人百度看片吗
  • 燕郊疫情最新消息沈阳seo搜索引擎
  • 网站运营专员具体每天怎么做seo黑帽技术
  • 网站委托建设合同范本免费建站建站abc网站
  • 网站开发用哪个框架淘宝如何提升关键词排名
  • 谁会网站开发舆情分析系统
  • 有什么那个网站seo公司哪家好
  • 销售网站制作电话百度一下你就知道百度官网
  • php网站建设案例教程网络推广平台软件
  • 应用公园app制作平台网站推广及seo方案
  • 网站建设3000字竞价排名的弊端
  • 青岛网站建设与管理电商代运营公司十强
  • 企业网站分析百度排名怎么做
  • 自己的网站怎么做隐藏内容站内seo和站外seo区别
  • 金华网站建设公司求职seo服务
  • 网站制作方案垂直领域获客windows7优化大师
  • 做网站龙头想学网络营销怎么学