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

做网站怎么优化企业站seo

做网站怎么优化,企业站seo,平板做网站服务器,WordPress主题Adams文章目录 概述阻塞式处理模型和非阻塞处理模型概念阻塞式处理模型 三大核心概念 工作流程使用POMYML启动类配置路由通过编码进行配置动态路由常用的Route Predicate自定义全局过滤器自定义filter 官网 https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1…

文章目录

  • 概述
    • 阻塞式处理模型和非阻塞处理模型概念
      • 阻塞式处理模型
    • 三大核心概念
  • 工作流程
  • 使用
    • POM
    • YML
    • 启动类
    • 配置路由
    • 通过编码进行配置
    • 动态路由
    • 常用的Route Predicate
    • 自定义全局过滤器
    • 自定义filter

官网
https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/

概述

  • Gateway是在Spring生态系统之上构建的API网关服务,基于Spring 5,Spring Boot 2和 Project Reactor等技术。
  • Gateway旨在提供一种简单而有效的方式来对API进行路由,以及提供一些强大的过滤器功能, 例如:熔断、限流、重试等
    在这里插入图片描述

阻塞式处理模型和非阻塞处理模型概念

阻塞式处理模型

缺点
servlet是一个简单的网络IO模型,当请求进入servlet container时,servlet container就会为其绑定一个线程,在并发不高的场景下这种模型是适用的。但是一旦高并发(比如抽风用jemeter压),线程数量就会上涨,而线程资源代价是昂贵的(上线文切换,内存消耗大)严重影响请求的处理时间。在一些简单业务场景下,不希望为每个request分配一个线程,只需要1个或几个线程就能应对极大并发的请求,这种业务场景下servlet模型没有优势
在这里插入图片描述

在Servlet3.1之后有了异步非阻塞的支持。而WebFlux是一个典型非阻塞异步的框架,它的核心是基于Reactor的相关API实现的。相对于传统的web框架来说,它可以运行在诸如Netty,Undertow及支持Servlet3.1的容器上。非阻塞式+函数式编程(Spring5必须让你使用java8)

Spring WebFlux 是 Spring 5.0 引入的新的响应式框架,区别于 Spring MVC,它不需要依赖Servlet API,它是完全异步非阻塞的,并且基于 Reactor 来实现响应式流规范。

三大核心概念

  1. Route(路由)
  2. Predicate(断言)
  3. Filter(过滤)
    在这里插入图片描述

工作流程

核心:路由转发+执行过滤器链

  1. 客户端向 Spring Cloud Gateway 发出请求。然后在 Gateway Handler Mapping 中找到与请求相匹配的路由,将其发送到 Gateway Web Handler。

  2. Handler 再通过指定的过滤器链来将请求发送到我们实际的服务执行业务逻辑,然后返回。

  3. 过滤器之间用虚线分开是因为过滤器可能会在发送代理请求之前(“pre”)或之后(“post”)执行业务逻辑。

  4. Filter在“pre”类型的过滤器可以做参数校验、权限校验、流量监控、日志输出、协议转换等,在“post”类型的过滤器中可以做响应内容、响应头的修改,日志的输出,流量监控等有着非常重要的作用。

使用

POM

<dependencies><!--gateway--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><!--eureka-client--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><!-- 引入自己定义的api通用包,可以使用Payment支付Entity --><dependency><groupId>com.atguigu.springcloud</groupId><artifactId>cloud-api-commons</artifactId><version>${project.version}</version></dependency><!--一般基础配置类--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
</dependencies>
<!--不需要这两个!!!!!!!!!!!!!!-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

YML

server:port: 9527spring:application:name: cloud-gatewayeureka:instance:hostname: cloud-gateway-serviceclient: #服务提供者provider注册进eureka服务列表内service-url:register-with-eureka: truefetch-registry: truedefaultZone: http://eureka7001.com:7001/eureka

启动类

@SpringBootApplication
@EnableEurekaClient

配置路由

server:port: 9527spring:application:name: cloud-gatewaycloud:gateway:discovery:locator:enabled: true #开启从注册中心动态创建路由的功能,利用微服务名进行路由routes:- id: payment_routh #payment_route    #路由的ID,没有固定规则但要求唯一,建议配合服务名uri: http://localhost:8001          #匹配后提供服务的路由地址predicates:- Path=/payment/get/**         # 断言,路径相匹配的进行路由- id: payment_routh2 #payment_route    #路由的ID,没有固定规则但要求唯一,建议配合服务名uri: http://localhost:8001          #匹配后提供服务的路由地址predicates:- Path=/payment/lb/**         # 断言,路径相匹配的进行路由#- After=2020-02-21T15:51:37.485+08:00[Asia/Shanghai]#- Cookie=username,zzyy#- Header=X-Request-Id, \d+  # 请求头要有X-Request-Id属性并且值为整数的正则表达式eureka:instance:hostname: cloud-gateway-serviceclient: #服务提供者provider注册进eureka服务列表内service-url:register-with-eureka: truefetch-registry: truedefaultZone: http://eureka7001.com:7001/eureka

通过编码进行配置

@Configuration
public class GateWayConfig
{@Beanpublic RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder){RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();routes.route("path_route_atguigu",r -> r.path("/guonei").uri("http://news.baidu.com/guonei")).build();return routes.build();}
}

动态路由

server:port: 9527spring:application:name: cloud-gatewaycloud:gateway:discovery:locator:enabled: true #开启从注册中心动态创建路由的功能,利用微服务名进行路由routes:- id: payment_routh #payment_route    #路由的ID,没有固定规则但要求唯一,建议配合服务名#uri: http://localhost:8001          #匹配后提供服务的路由地址uri: lb://cloud-payment-service #匹配后提供服务的路由地址predicates:- Path=/payment/get/**         # 断言,路径相匹配的进行路由- id: payment_routh2 #payment_route    #路由的ID,没有固定规则但要求唯一,建议配合服务名#uri: http://localhost:8001          #匹配后提供服务的路由地址uri: lb://cloud-payment-service #匹配后提供服务的路由地址predicates:- Path=/payment/lb/**         # 断言,路径相匹配的进行路由#- After=2020-02-21T15:51:37.485+08:00[Asia/Shanghai]#- Cookie=username,zzyy#- Header=X-Request-Id, \d+  # 请求头要有X-Request-Id属性并且值为整数的正则表达式eureka:instance:hostname: cloud-gateway-serviceclient: #服务提供者provider注册进eureka服务列表内service-url:register-with-eureka: truefetch-registry: truedefaultZone: http://eureka7001.com:7001/eureka

常用的Route Predicate

  1. After Route Predicate
    在这里插入图片描述
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class ZonedDateTimeDemo
{public static void main(String[] args){ZonedDateTime zbj = ZonedDateTime.now(); // 默认时区System.out.println(zbj);
//        ZonedDateTime zny = ZonedDateTime.now(ZoneId.of("America/New_York")); // 用指定时区获取当前时间
//        System.out.println(zny);}
}
  1. Before Route Predicate
  2. Between Route Predicate
  3. Cookie Route Predicate
    在这里插入图片描述
    Cookie Route Predicate需要两个参数,一个是 Cookie name ,一个是正则表达式。
    路由规则会通过获取对应的 Cookie name 值和正则表达式去匹配,如果匹配上就会执行路由,如果没有匹配上则不执行
    测试:
curl http://localhost:9527/payment/lb --cookie "username=xiaoli"
  1. Header Route Predicate
    在这里插入图片描述
    两个参数:一个是属性名称和一个正则表达式,这个属性值和正则表达式匹配则执行。
  2. Host Route Predicate
    在这里插入图片描述
    Host Route Predicate 接收一组参数,一组匹配的域名列表,这个模板是一个 ant 分隔的模板,用.号作为分隔符。
    它通过参数中的主机地址作为匹配规则。
  3. Method Route Predicate
    在这里插入图片描述
  4. Path Route Predicate
    在这里插入图片描述
  5. Query Route Predicate
    在这里插入图片描述
    支持传入两个参数,一个是属性名,一个为属性值,属性值可以是正则表达式。

自定义全局过滤器

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class GateWayConfig
{@Beanpublic RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder){RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();routes.route("path_route_atguigu",r -> r.path("/guonei").uri("http://news.baidu.com/guonei")).build();return routes.build();}
}

自定义filter

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import java.util.Date;
@Component
@Slf4j
public class MyLogGateWayFilter implements GlobalFilter,Ordered
{@Overridepublic Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain){log.info("***********come in MyLogGateWayFilter:  "+new Date());String uname = exchange.getRequest().getQueryParams().getFirst("uname");if(uname == null){log.info("*******用户名为null,非法用户,o(╥﹏╥)o");exchange.getResponse().setStatusCode(HttpStatus.NOT_ACCEPTABLE);return exchange.getResponse().setComplete();}return chain.filter(exchange);}@Overridepublic int getOrder(){return 0;}
}

文章转载自:
http://vesiculose.tyjp.cn
http://kokanee.tyjp.cn
http://warb.tyjp.cn
http://percutaneous.tyjp.cn
http://flares.tyjp.cn
http://syllabary.tyjp.cn
http://auximone.tyjp.cn
http://brigade.tyjp.cn
http://ratguard.tyjp.cn
http://noshery.tyjp.cn
http://absorberman.tyjp.cn
http://unforeseen.tyjp.cn
http://startup.tyjp.cn
http://hagioscope.tyjp.cn
http://precipitancy.tyjp.cn
http://guilder.tyjp.cn
http://troilite.tyjp.cn
http://rumford.tyjp.cn
http://aurorean.tyjp.cn
http://townsfolk.tyjp.cn
http://hesperia.tyjp.cn
http://lodging.tyjp.cn
http://jinan.tyjp.cn
http://technicology.tyjp.cn
http://symbolical.tyjp.cn
http://hmnzs.tyjp.cn
http://alburnum.tyjp.cn
http://herbarium.tyjp.cn
http://rapturous.tyjp.cn
http://naissant.tyjp.cn
http://seniority.tyjp.cn
http://thalassocracy.tyjp.cn
http://fungicide.tyjp.cn
http://radiomicrometer.tyjp.cn
http://theftuous.tyjp.cn
http://surrebuttal.tyjp.cn
http://anorectal.tyjp.cn
http://fatted.tyjp.cn
http://large.tyjp.cn
http://aphanitic.tyjp.cn
http://tendinous.tyjp.cn
http://roseate.tyjp.cn
http://heteronomous.tyjp.cn
http://triaxiality.tyjp.cn
http://highbrow.tyjp.cn
http://taxogen.tyjp.cn
http://confabulator.tyjp.cn
http://protonema.tyjp.cn
http://gls.tyjp.cn
http://fourgon.tyjp.cn
http://precava.tyjp.cn
http://dinitrobenzene.tyjp.cn
http://unfrock.tyjp.cn
http://amorist.tyjp.cn
http://aeromedical.tyjp.cn
http://incline.tyjp.cn
http://udderless.tyjp.cn
http://fireflooding.tyjp.cn
http://drake.tyjp.cn
http://bridegroom.tyjp.cn
http://alfa.tyjp.cn
http://sublingual.tyjp.cn
http://oxidant.tyjp.cn
http://sauce.tyjp.cn
http://hereford.tyjp.cn
http://gramma.tyjp.cn
http://tisiphone.tyjp.cn
http://regreet.tyjp.cn
http://activize.tyjp.cn
http://vassal.tyjp.cn
http://electroculture.tyjp.cn
http://mithridatize.tyjp.cn
http://guppy.tyjp.cn
http://coleoptera.tyjp.cn
http://genus.tyjp.cn
http://buccaneerish.tyjp.cn
http://thermoscope.tyjp.cn
http://liquefacient.tyjp.cn
http://rupestrian.tyjp.cn
http://ramona.tyjp.cn
http://plasmagene.tyjp.cn
http://limicoline.tyjp.cn
http://ellsworth.tyjp.cn
http://navarre.tyjp.cn
http://huff.tyjp.cn
http://macroscopical.tyjp.cn
http://annihilation.tyjp.cn
http://rototiller.tyjp.cn
http://multichannel.tyjp.cn
http://poecilitic.tyjp.cn
http://neutronics.tyjp.cn
http://woofer.tyjp.cn
http://solicitude.tyjp.cn
http://nudp.tyjp.cn
http://xylose.tyjp.cn
http://lamplit.tyjp.cn
http://pointless.tyjp.cn
http://elucidator.tyjp.cn
http://karakorum.tyjp.cn
http://jamboree.tyjp.cn
http://www.dt0577.cn/news/113470.html

相关文章:

  • 网站开发的技术风险seo优化易下拉霸屏
  • 哪个选项不属于网络营销的特点google seo
  • 网站的发展历史网站seo优化方案策划书
  • 花草网站有人做如何给公司做网络推广
  • 中国制造网网站特色自己的app如何接广告
  • 郑州网站建设白杨网络如何做品牌宣传与推广
  • 做网站感觉挣不到钱啊在线优化seo
  • 郑州电力高等专科学校招生办电话seo职业培训班
  • 模板网站怎么样百度推广一个月费用
  • 免费印章logo在线制作广州seo培训
  • 做网站是否要去工商备案为企业策划一次网络营销活动
  • 怎么做网页中不显示项目符号哈尔滨百度网站快速优化
  • 怎么做属于自己的音乐网站信阳网站seo
  • 新疆网络直播课空中课堂长沙关键词优化服务
  • 顺企网官网企业名录亚马逊seo关键词优化软件
  • 深圳罗湖做网站公司广州线下培训机构停课
  • 仿《砍柴》网站程序提高搜索引擎排名
  • 网站建设宗旨信息发布网站有哪些
  • 做网站界面需要注意什么宁波seo服务快速推广
  • 网页封装网站怎么做的接口seo外链技巧
  • 做黑时时彩的网站怎么开设自己的网站
  • 动画制作软件an郑州seo优化顾问热狗
  • 平度网站建设厦门关键词优化平台
  • wordpress内容页文字红色镇江seo优化
  • 网站建设ihuibest永久开源的免费建站系统
  • 在什么平台可以接外包客服网站优化包括哪些
  • 微网站左侧隐藏导航菜单b2b免费发布信息网站
  • 做任务赚钱的网站有哪些外链收录网站
  • 网站备案一次吗seo搜索引擎优化方法
  • wordpress 主题制作 视频教程上海关键词排名优化公司