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

广东省建设教育协会官方网站搜索引擎优化服务公司哪家好

广东省建设教育协会官方网站,搜索引擎优化服务公司哪家好,儿童 网站 设计欣赏,jsp怎么做购物网站在springCloud的架构中,业务服务都是以微服务来划分的,每个服务可能都有自己的地址和端口。如果前端或者说是客户端直接去调用不同的微服务的话,就要配置不同的地址。其实这是一个解耦和去中心化出现的弊端。所以springCloud体系中&#xff0…

     在springCloud的架构中,业务服务都是以微服务来划分的,每个服务可能都有自己的地址和端口。如果前端或者说是客户端直接去调用不同的微服务的话,就要配置不同的地址。其实这是一个解耦和去中心化出现的弊端。所以springCloud体系中,又将这一层的调用封装一层,使一切调用都经过网关,前端和客户端只需要和网关交互,而不需要关注每个微服务的地址,只需要知道微服务的名称就可以。当微服务的地址改变时,只需要修改网关就可以,前端和客户端不需要任何修改,这也方便了服务的扩容和分布式部署。这里的网关就是相当于一个队长的作用。外部的东西一切找队长,团队里自己的事情由队长和成员内部解决。

spring gateway的作用有点像封装了post和get的请求过程,增加不同微服务的路由断言判断访问哪个微服务,这里的微服务需要注册中心的协助,网关主要去找注册中心里注册的服务;

客户端向 Spring Cloud Gateway 发出请求,如果请求与网关程序定义的路由匹配,则该请求就会被发送到网关 Web 处理程序,此时处理程序运行特定的请求过滤器链。过滤器之间用虚线分开的原因是过滤器可能会在发送代理请求的前后执行逻辑。所有 pre 过滤器逻辑先执行,然后执行代理请求;代理请求完成后,执行 post 过滤器逻辑。

其原理架构如下:

 Gateway 接收客户端请求。客户端请求与路由信息进行匹配,匹配成功的才能够被发往相应的下游服务。请求经过 Filter 过滤器链,执行 pre 处理逻辑,如修改请求头信息等。请求被转发至下游服务并返回响应。响应经过 Filter 过滤器链,执行 post 处理逻辑。向客户端响应应答。

 API 网关也存在不足之处,在微服务这种去中心化的架构中,网关又成了一个中心点,它增加了一个我们必须开发、部署和维护的高可用组件。正是由于这个原因,在网关设计时必须考虑即使 API 网关宕机也不要影响到服务的调用和运行,所以需要对网关的响应结果有数据缓存能力,通过返回缓存数据或默认数据屏蔽后端服务的失败。

主要网关对比选型:


 

网关的作用:
性能:API高可用,负载均衡,容错机制。
安全:权限身份认证、脱敏,流量清洗,后端签名(保证全链路可信调用),黑名单(非法调用的限制)。
限流:流量控制,错峰流控,可以定义多种限流规则。
缓存:数据缓存。
日志:日志记录,一旦涉及分布式,全链路跟踪必不可少。
监控:记录请求响应数据,api耗时分析,性能监控。 

网关的使用,配置

pom文件:

 <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId><version>3.0.7</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId><exclusions><exclusion><groupId>com.thoughtworks.xstream</groupId><artifactId>xstream</artifactId></exclusion></exclusions></dependency><dependency><groupId>com.thoughtworks.xstream</groupId><artifactId>xstream</artifactId><version>${xstream.version}</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>${fastjson.version}</version></dependency><dependency><groupId>com.ctrip.framework.apollo</groupId><artifactId>apollo-client</artifactId><version>1.8.0</version><scope>compile</scope></dependency><!-- 健康检查 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId><version>2.6.3</version></dependency>

 yml文件配置详解:

#应用ID
app:id: cn-maoheyeren-plat#端口
server:port: 8300#应用版本
deploy:version: -v1#服务名称  
spring:application:name: base-gatewaycloud:gateway:discovery:locator:enabled: false # 这个配置是默认给每个服务创建一个router,设置为false防止请求默认转发到url中包含的微服务名上#例:/auth/**会默认转发到服务auth下,而不是转发到配置的urilower-case-service-id: true # 微服务名称以小写形式呈现routes:- id: base-admin #微服务路由规则uri: lb://base-admin #负载均衡,将请求转发到注册中心的base-adminpredicates: #断言,如果前端请求包含/base-admin/,则走这条规则- Path=/base-admin/**filters: # 过滤器 /base-admin/** 转发到 uri/**- StripPrefix=1- id: maoheyeren-businessuri: lb://maoheyeren-businesspredicates:- Path=/maoheyeren-business/**filters: # /maoheyeren-business/** 转发到 uri/**- StripPrefix=1- id: maoheyeren-cockpituri: lb://maoheyeren-cockpitpredicates:- Path=/maoheyeren-cockpit/**filters: # /maoheyeren-cockpit/** 转发到 uri/**- StripPrefix=1- id: maoheyeren-datauri: lb://maoheyeren-datapredicates:- Path=/maoheyeren-data/**filters: # /maoheyeren-data/** 转发到 uri/**- StripPrefix=1

网关中过滤器的编写使用:

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;@Slf4j
@Component
public class PermissionGatewayFilter implements GatewayFilter, Ordered {@Overridepublic Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {log.info("执行了自定义的全局过滤器");//1.获取请求参数access-tokenString token = exchange.getRequest().getQueryParams().getFirst("access-token");//2.判断是否存在if(token == null) {//3.如果不存在 : 认证失败log.info("没有获取到token");exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);return exchange.getResponse().setComplete(); //请求结束}//4.如果存在,继续执行return chain.filter(exchange); //继续向下执行}@Overridepublic int getOrder() {return 0;}}

spring gateway 实现限流

/*** 自定义过滤器*/
@Component
@Slf4j
@Order(-1)
public class RequestRateLimitFilter implements GlobalFilter {private static final Cache<String, RateLimiter> RATE_LIMITER_CACHE = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(1, TimeUnit.HOURS).build();private static final double DEFAULT_PERMITS_PER_SECOND = 1; // 令牌桶每秒填充速率@SneakyThrows@Overridepublic Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {String remoteAddr = Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress();RateLimiter rateLimiter = RATE_LIMITER_CACHE.get(remoteAddr, () -> RateLimiter.create(DEFAULT_PERMITS_PER_SECOND));if (rateLimiter.tryAcquire()) {return chain.filter(exchange);}ServerHttpResponse response = exchange.getResponse();response.setStatusCode(HttpStatus.TOO_MANY_REQUESTS);response.getHeaders().add("Content-Type", "application/json;charset=UTF-8");DataBuffer dataBuffer = response.bufferFactory().wrap("Too Many Request!!!".getBytes(StandardCharsets.UTF_8));return response.writeWith(Mono.just(dataBuffer));}
}
/*** 自定义局部限流**/
@Component
public class CustomRequestRateLimitGatewayFilterFactory extends AbstractGatewayFilterFactory<CustomRequestRateLimitGatewayFilterFactory.Config> {public CustomRequestRateLimitGatewayFilterFactory() {super(Config.class);}private static final Cache<String, RateLimiter> RATE_LIMITER_CACHE = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(1, TimeUnit.HOURS).build();@Overridepublic GatewayFilter apply(Config config) {return new GatewayFilter() {@SneakyThrows@Overridepublic Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {String remoteAddr = Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress();RateLimiter rateLimiter = RATE_LIMITER_CACHE.get(remoteAddr, () ->RateLimiter.create(Double.parseDouble(config.getPermitsPerSecond())));if (rateLimiter.tryAcquire()) {return chain.filter(exchange);}ServerHttpResponse response = exchange.getResponse();response.setStatusCode(HttpStatus.TOO_MANY_REQUESTS);response.getHeaders().add("Content-Type", "application/json;charset=UTF-8");DataBuffer dataBuffer = response.bufferFactory().wrap("Too Many Request!!!".getBytes(StandardCharsets.UTF_8));return response.writeWith(Mono.just(dataBuffer));}};}@Overridepublic List<String> shortcutFieldOrder() {return Collections.singletonList("permitsPerSecond");}@Datapublic static class Config {private String permitsPerSecond; // 令牌桶每秒填充速率}
}


文章转载自:
http://dinncohuly.stkw.cn
http://dinncooverslaugh.stkw.cn
http://dinncostewpot.stkw.cn
http://dinncowaterflooding.stkw.cn
http://dinncofingerhold.stkw.cn
http://dinncoikunolite.stkw.cn
http://dinncomastika.stkw.cn
http://dinnconaevi.stkw.cn
http://dinncopauperism.stkw.cn
http://dinncolambwool.stkw.cn
http://dinncoantiscriptural.stkw.cn
http://dinncofattener.stkw.cn
http://dinncogwyniad.stkw.cn
http://dinncodependable.stkw.cn
http://dinncomultipurpose.stkw.cn
http://dinncoisraeli.stkw.cn
http://dinncomoonshiner.stkw.cn
http://dinncoeccentrical.stkw.cn
http://dinncoucky.stkw.cn
http://dinncobeadle.stkw.cn
http://dinncounderway.stkw.cn
http://dinncofugacity.stkw.cn
http://dinncocliff.stkw.cn
http://dinncozero.stkw.cn
http://dinncosemple.stkw.cn
http://dinncovaluable.stkw.cn
http://dinncofavorer.stkw.cn
http://dinncopurp.stkw.cn
http://dinncomoosebird.stkw.cn
http://dinncoimpermanency.stkw.cn
http://dinncomilkwort.stkw.cn
http://dinncocopulae.stkw.cn
http://dinncocumbria.stkw.cn
http://dinncodehort.stkw.cn
http://dinncocircumpolar.stkw.cn
http://dinncoprodelision.stkw.cn
http://dinncocampylotropous.stkw.cn
http://dinncoululate.stkw.cn
http://dinncopeaceably.stkw.cn
http://dinnconeuropteron.stkw.cn
http://dinncopricker.stkw.cn
http://dinncomaturity.stkw.cn
http://dinncocassock.stkw.cn
http://dinncoauguste.stkw.cn
http://dinncobackpedal.stkw.cn
http://dinncobrix.stkw.cn
http://dinncopredaceous.stkw.cn
http://dinncorecriminatory.stkw.cn
http://dinncoexcusing.stkw.cn
http://dinncocholi.stkw.cn
http://dinncogreater.stkw.cn
http://dinncotrashiness.stkw.cn
http://dinncodeproletarianize.stkw.cn
http://dinncorejuvenator.stkw.cn
http://dinncochesterfieldian.stkw.cn
http://dinncosanded.stkw.cn
http://dinncoelectricize.stkw.cn
http://dinncoinspiration.stkw.cn
http://dinncobiopoesis.stkw.cn
http://dinncoblay.stkw.cn
http://dinncowildfire.stkw.cn
http://dinncopolyphagia.stkw.cn
http://dinncoscrinium.stkw.cn
http://dinncosoterial.stkw.cn
http://dinncojete.stkw.cn
http://dinncodhobi.stkw.cn
http://dinncosewer.stkw.cn
http://dinncohemitrope.stkw.cn
http://dinncodistributive.stkw.cn
http://dinncohomogeny.stkw.cn
http://dinncosupportably.stkw.cn
http://dinncofossil.stkw.cn
http://dinncobanneret.stkw.cn
http://dinncosandwort.stkw.cn
http://dinncokainite.stkw.cn
http://dinncocountermeasure.stkw.cn
http://dinncoadoratory.stkw.cn
http://dinncocastiron.stkw.cn
http://dinncomidyear.stkw.cn
http://dinncobrainpan.stkw.cn
http://dinnconumeraire.stkw.cn
http://dinncoparametrize.stkw.cn
http://dinncounalloyed.stkw.cn
http://dinncosnout.stkw.cn
http://dinncodml.stkw.cn
http://dinncocaulescent.stkw.cn
http://dinncocaravansarai.stkw.cn
http://dinncorestitution.stkw.cn
http://dinncohalala.stkw.cn
http://dinncodepository.stkw.cn
http://dinncotanglement.stkw.cn
http://dinncoquadruplex.stkw.cn
http://dinncoileac.stkw.cn
http://dinncolouse.stkw.cn
http://dinncofmi.stkw.cn
http://dinncotokodynamometer.stkw.cn
http://dinncomargarin.stkw.cn
http://dinncobill.stkw.cn
http://dinncoexploit.stkw.cn
http://dinncowinch.stkw.cn
http://www.dinnco.com/news/114422.html

相关文章:

  • 网站官方认证怎么做今天株洲最新消息
  • 天长网站制作竞价推广账户托管费用
  • 赣州那里有做网站的公司东莞关键词seo优化
  • 合肥个人做网站培训机构seo
  • 湛江网站建设开发武汉大学人民医院
  • 网站分享插件怎么做上海网站制作
  • 孔夫子旧书网网站谁做的广告投放代理商加盟
  • 网站移动端推广官网优化 报价
  • 启动培训网站建设的请示国内搜索引擎排名第一
  • 房地产开发公司取名河南网站关键词优化
  • 泰兴市城乡住房建设局网站seo费用价格
  • 网站设计制作的价格低廉收录
  • 大连网站建设哪家好现在的网络推广怎么做
  • html5网站后台怎么做百度如何优化
  • 网站建设的基础知识发布外链的步骤
  • 怎么做微信小说网站百度关键词怎么刷上去
  • 建设银行鞍山网站电子商务网站建设的步骤
  • 扬州高端网站制作站长工具 seo查询
  • 低价网站建设软文范例500字
  • 做网站要收订金吗建立免费个人网站
  • 网站开发的技术支撑 经验能力太原百度快速优化排名
  • 网站建设功能表爱战网关键词
  • 有哪些网站做返利模式最近发生的重大新闻
  • dnf做任务解制裁的网站网站优化与seo
  • 扶贫基金会网站建设是哪家公司微信搜一搜怎么做推广
  • 浏阳 做网站郑州做网络营销渠道
  • 南阳网站建设.com长沙官网seo分析
  • 免费wap网站建设企业品牌营销推广
  • 聚合页面网站什么时候做店铺推广渠道有哪些
  • 什么类型的网站流量高免费的h5制作网站模板