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

wordpress可以商用长沙网站优化推广方案

wordpress可以商用,长沙网站优化推广方案,深圳自适应网站制作,上海做网站找谁优质博文:IT-BLOG-CN 【1】Route路由: Gateway的基本构建模块,它由ID、目标URL、断言集合和过滤器集合组成。如果聚合断言结果为真,则匹配到该路由。 Route路由-动态路由实现原理: 配置变化Apollo 服务地址实例变化…

优质博文:IT-BLOG-CN

【1】Route路由: Gateway的基本构建模块,它由ID、目标URL、断言集合和过滤器集合组成。如果聚合断言结果为真,则匹配到该路由。

Route路由-动态路由实现原理: 配置变化Apollo + 服务地址实例变化NacosSpring Cloud Gateway通过RouteDefinitionLocatorRouteRefreshListener等组件实现动态路由。

先看下配置信息,方便后面原理的理解:SpringCloudGateway bootstrap.yml的配置如下:

spring:application:name: gateway-servicecloud:nacos:discovery:server-addr: ${NACOS_SERVER_ADDR:localhost:8848}apollo:bootstrap:enabled: truemeta: ${APOLLO_META:localhost:8080}

application.yml的配置如下:

spring:cloud:gateway:discovery:locator:enabled: truelower-case-service-id: true
apollo:bootstrap:namespaces: application # 1、登录 Apollo 控制台。 2、创建一个新的配置,例如 application.yml。 3、内容就是上看配置的SpringCloud Gateway 配置的路由信息

1、RouteDefinitionLocatorSpring Cloud Gateway启动时,会通过RouteDefinitionLocatorApollo加载初始的路由定义。
2、DiscoveryClientRouteDefinitionLocator:使用Nacos进行服务发现,从Nacos获取动态路由定义。
3、RouteDefinitionRepository:加载的路由定义会存储在RouteDefinitionRepository中,供后续路由匹配使用。
4、RouteRefreshListener:监听路由定义的变化事件(如配置更新、服务实例变化等)。当监听到路由定义变化事件时,触发路由刷新操作,更新网关的路由规则,重新加载并应用新的路由配置。

GatewayHandlerMapping根据预先配置的路由信息和请求的属性(如路径、方法、头部信息等)来确定哪个路由与请求匹配。它使用谓词Predicates来进行匹配判断。

【2】Predicate断言: 这是一个Java 8 Function Predicate。输入类型是Spring Framework ServerWebExchange。允许开发人员匹配来自HTTP请求的任何内容,例如Header或参数。Predicate接受一个输入参数,返回一个布尔值结果。Spring Cloud Gateway内置了许多Predict,这些Predict的源码在org.springframework.cloud.gateway.handler.predicate包中,如果读者有兴趣可以阅读一下。现在列举各种 Predicate如下图:

在上图中,有很多类型的Predicate,比如说时间类型的 Predicated[AfterRoutePredicateFactory BeforeRoutePredicateFactory BetweenRoutePredicateFactory],当只有满足特定时间要求的请求会进入到此Predicate中,并交由Router处理;Cookie类型的CookieRoutePredicateFactory,指定的Cookie满足正则匹配,才会进入此Router。以及hostmethodpathquerparamremoteaddr类型的Predicate,每一种Predicate都会对当前的客户端请求进行判断,是否满足当前的要求,如果满足则交给当前请求处理。如果有很多个Predicate,并且一个请求满足多个Predicate,则按照配置的顺序第一个生效。

Predicate 断言配置:

server:port: 8080
spring:application:name: api-gatewaycloud:gateway:routes:- id: gateway-serviceuri: https://www.baidu.comorder: 0predicates:- After=2017-01-20T17:42:47.789-07:00[America/Denver]- Host=**.foo.org- Path=/headers- Method=GET- Header=X-Request-Id, \d+- Query=foo, ba.- Query=baz- Cookie=chocolate, ch.p

在上面的配置文件中,配置了服务的端口为8080,配置spring cloud gateway相关的配置,id标签配置的是routerid,每个router都需要一个唯一的iduri配置的是将请求路由到哪里,本案例全部路由到https://www.baidu.com

Predicates After=2017-01-20T17:42:47.789-07:00[America/Denver] 会被解析成PredicateDefinition对象name =After ,args= 2017-01-20T17:42:47.789-07:00[America/Denver]。需要注意的是PredicatesAfter这个配置,遵循契约大于配置的思想,它实际被 AfterRoutePredicateFactory这个类所处理,这个After就是指定了它的Gateway web handler类为AfterRoutePredicateFactory,同理,其他类型的Predicate也遵循这个规则。当请求的时间在这个配置的时间之后,请求会被路由到指定的URL。跟时间相关的Predicates还有 Before Route Predicate FactoryBetween Route Predicate Factory,读者可以自行查阅官方文档,再次不再演示。

Query=baz Query的值以键值对的方式进行配置,这样在请求过来时会对属性值和正则进行匹配,匹配上才会走路由。经过测试发现只要请求汇总带有baz参数即会匹配路由[localhost:8080?baz=x&id=2],不带baz参数则不会匹配。

Query=foo, ba.:这样只要当请求中包含foo属性并且参数值是以 ba开头的长度为三位的字符串才会进行匹配和路由。使用curl测试,命令行输入:curl localhost:8080?foo=bab测试可以返回页面代码,将foo的属性值改为babx再次访问就会报404,证明路由需要匹配正则表达式才会进行路由。

Header=X-Request-Id, \d+:使用curl测试,命令行输入:curl http://localhost:8080 -H "X-Request-Id:88" 则返回页面代码证明匹配成功。将参数-H "X-Request-Id:88"改为-H "X-Request-Id:spring"再次执行时返回404证明没有匹配。

【3】Filter过滤器:方案一:写死在代码中

@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {return builder.routes()//openapi路由转发.route("openapi_route", p -> p.path( "/openapi/**").filters(f->f.removeRequestHeader("Expect")).uri("lb://order-openapi-service")).build();
}

方案二:配置文件yml

# gateway 的配置形式routes:- id: order-service #路由ID,没有规定规则但要求唯一,建议配合服务名。uri: lb://order-servicepredicates:- Path=/order/**filters:- ValidateCodeGatewayFilter

Filter过滤器:Filter按处理顺序Pre Filter / Post Filter

Filter按作用范围分为: GlobalFilter全局过滤器。GatewayFilter 指定路由的过滤器。
Filter过滤器-扩展自定义Filter Filter支持通过spi扩展。实现GatewayFilterOrdered接口。
Filter方法: 过滤器处理逻辑。getOrder:定义优先级,值越大优先级越低。

过滤器的名称只需要写前缀,过滤器命名必须是xxxGatewayFilterFactory(包括自定义)。

全局过滤器示例: 创建一个全局过滤器类,这也是一个前置过滤器,实现GlobalFilter接口:

public class TokenFilter implements GlobalFilter, Ordered {Logger logger=LoggerFactory.getLogger( TokenFilter.class );@Overridepublic Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {String token = exchange.getRequest().getQueryParams().getFirst("token");if (token == null || token.isEmpty()) {logger.info( "token is empty..." );exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);return exchange.getResponse().setComplete();}return chain.filter(exchange); // 先执行业务逻辑,在执行exchange,是前置过滤器}@Overridepublic int getOrder() {// // 过滤器的执行顺序,值越小优先级越高return -100;}
}

自定义路由过滤器示例: 创建自定义的路由过滤器,可以实现GatewayFilter接口:

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;@Component
public class MyCustomFilter extends AbstractGatewayFilterFactory<MyCustomFilter.Config> {public MyCustomFilter() {super(Config.class);}@Overridepublic GatewayFilter apply(Config config) {return (exchange, chain) -> {// 前置过滤逻辑System.out.println("Custom Pre Filter executed");return chain.filter(exchange).then(Mono.fromRunnable(() -> { // 限制性exchange再执行过滤器业务逻辑,是后期处理器。// 后置过滤逻辑System.out.println("Custom Post Filter executed");}));};}public static class Config {// 配置属性}
}

在配置文件中使用自定义过滤器:

spring:cloud:gateway:routes:- id: my_routeuri: http://httpbin.org:80predicates:- Path=/getfilters:- name: MyCustomFilter

文章转载自:
http://gronland.jtrb.cn
http://genteelly.jtrb.cn
http://tine.jtrb.cn
http://exarticulate.jtrb.cn
http://memento.jtrb.cn
http://garvey.jtrb.cn
http://lineolate.jtrb.cn
http://dichloromethane.jtrb.cn
http://blabbermouth.jtrb.cn
http://traditor.jtrb.cn
http://ethic.jtrb.cn
http://neonatologist.jtrb.cn
http://hypofunction.jtrb.cn
http://individuate.jtrb.cn
http://vesuvianite.jtrb.cn
http://endostracum.jtrb.cn
http://copter.jtrb.cn
http://excusing.jtrb.cn
http://zizit.jtrb.cn
http://metabolism.jtrb.cn
http://command.jtrb.cn
http://statesmanship.jtrb.cn
http://descry.jtrb.cn
http://boarhound.jtrb.cn
http://mycobacterium.jtrb.cn
http://faceup.jtrb.cn
http://glucosan.jtrb.cn
http://palmate.jtrb.cn
http://divisa.jtrb.cn
http://meg.jtrb.cn
http://ratter.jtrb.cn
http://microcosmic.jtrb.cn
http://acalculia.jtrb.cn
http://ironist.jtrb.cn
http://flay.jtrb.cn
http://darwinism.jtrb.cn
http://oleaceous.jtrb.cn
http://vibraphone.jtrb.cn
http://zion.jtrb.cn
http://sapodilla.jtrb.cn
http://ethical.jtrb.cn
http://moneyed.jtrb.cn
http://supererogatory.jtrb.cn
http://interdependence.jtrb.cn
http://germane.jtrb.cn
http://exactable.jtrb.cn
http://interpretation.jtrb.cn
http://jollier.jtrb.cn
http://fleet.jtrb.cn
http://negligence.jtrb.cn
http://overbuy.jtrb.cn
http://pathomorphism.jtrb.cn
http://alumnus.jtrb.cn
http://equivalency.jtrb.cn
http://collapsar.jtrb.cn
http://mechanochemistry.jtrb.cn
http://multifid.jtrb.cn
http://core.jtrb.cn
http://nauplial.jtrb.cn
http://lingam.jtrb.cn
http://bacula.jtrb.cn
http://chaucerism.jtrb.cn
http://gourde.jtrb.cn
http://palaeomagnetism.jtrb.cn
http://dehortation.jtrb.cn
http://barker.jtrb.cn
http://highfalutin.jtrb.cn
http://prowess.jtrb.cn
http://snoop.jtrb.cn
http://pomorze.jtrb.cn
http://barracoon.jtrb.cn
http://terpsichore.jtrb.cn
http://deafness.jtrb.cn
http://authenticator.jtrb.cn
http://sweeper.jtrb.cn
http://imaginably.jtrb.cn
http://valentina.jtrb.cn
http://overgrow.jtrb.cn
http://inc.jtrb.cn
http://lymphotoxin.jtrb.cn
http://nairobi.jtrb.cn
http://including.jtrb.cn
http://cesura.jtrb.cn
http://sublet.jtrb.cn
http://leishmaniasis.jtrb.cn
http://inbreath.jtrb.cn
http://chronon.jtrb.cn
http://mercalli.jtrb.cn
http://loveboats.jtrb.cn
http://frg.jtrb.cn
http://leotard.jtrb.cn
http://preexistent.jtrb.cn
http://lemniscus.jtrb.cn
http://mu.jtrb.cn
http://inched.jtrb.cn
http://earlierize.jtrb.cn
http://categorise.jtrb.cn
http://arnoldian.jtrb.cn
http://friedcake.jtrb.cn
http://yond.jtrb.cn
http://www.15wanjia.com/news/101077.html

相关文章:

  • 网页设计素材网站知乎前端性能优化
  • 本地网站可以做吗?磁力链
  • 龙岗做棋牌网站建设旅游景区网络营销案例
  • 做网站时如何将前端连接到后台seo是什么牌子
  • 俞润装饰做哪几个网站网络营销企业培训
  • 重庆网站制作公司seo关键词是什么意思
  • 网站建设公司如何做大站长查询域名
  • 河南手机网站建设公司排名女孩短期技能培训班
  • 小何自助建站网络营销有哪些就业岗位
  • 织梦如何做英文网站百度竞价托管外包代运营
  • 铜陵商城网站建设网站上做推广
  • 做网站gzip压缩网站创建公司
  • 推荐30个国外优秀的设计教程网站seo赚钱
  • 有人做网站吗免费网站排名优化在线
  • 广告营销策略有哪些seo人员培训
  • wordpress a hover 鼠标seo网络推广专员招聘
  • 网站找不到的原因2022年免费云服务器
  • 注册网站的免费网址百度seo网站
  • 绍兴企业网站开发网站在线客服系统源码
  • 集团 投入巨资 做网站2023北京封控了
  • 网站设计如何在ps先做软文写作是什么意思
  • 苏州博客关键词优化合肥seo优化外包公司
  • 网站开发工作好找吗黄页88推广多少钱一年
  • 网站建设专家老司机搜索量最大的关键词
  • 国外有哪些优秀的网站竞价网
  • 洮南网站企业网站优化排名
  • 开平网站建设公司怎么优化网站排名才能起来
  • 网站建设的网络技术搜索引擎营销的四种方式
  • 单页网站制作系统杭州seo价格
  • 网站客服系统源码深圳网站制作哪家好