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

网站推广模式怎么开网店?

网站推广模式,怎么开网店?,机器人编程培训机构排名,驾校报名网站怎么做文章目录 1 微服务API网关Gateway1.1 网关简介1.2 Spring Cloud Gateway介绍1.3 Gateway特性1.4 Gateway核心概念1.4.1 路由1.4.1.1 定义1.4.1.2 动态路由 1.4.2 断言1.4.2.1 默认断言1.4.2.2 自定义Predicate 1.4.3 过滤器1.4.3.1 默认过滤器1.4.3.2 自定义Filter#xff08;… 文章目录 1 微服务API网关Gateway1.1 网关简介1.2 Spring Cloud Gateway介绍1.3 Gateway特性1.4 Gateway核心概念1.4.1 路由1.4.1.1 定义1.4.1.2 动态路由 1.4.2 断言1.4.2.1 默认断言1.4.2.2 自定义Predicate 1.4.3 过滤器1.4.3.1 默认过滤器1.4.3.2 自定义FilterGatewayFilter1.4.3.2 自定义FilterGlobalFilter1.4.3.3 自定义FilterAbstractGatewayFilterFactory 1.5 Gateway工作流程1.6 实际操作1.6.1 pom.xml1.6.2 启动类1.6.3 配置文件 application.yml 1 微服务API网关Gateway 1.1 网关简介 如果没有网关难道不行吗功能上是可以的我们直接调用提供的接口就可以了。那为什么还需要网关 因为网关的作用不仅仅是转发请求而已。我们可以试想一下如果需要做一个请求认证功能我们可以接入到 API 服务中。但是倘若后续又有服务需要接入我们又需要重复接入。这样我们不仅代码要重复编写而且后期也不利于维护。 由于接入网关后网关将转发请求。所以在这一层做请求认证天然合适。这样这需要编写一次代码在这一层过滤完毕再转发给下面的 API。所以 API 网关的通常作用是完成一些通用的功能如请求认证请求记录请求限流黑白名单判断等。 API网关是一个服务器是系统的唯一入口。 API网关方式的核心要点是所有的客户端和消费端都通过统一的网关接入微服务在网关层处理所有的非业务功能。通常网关提供REST/HTTP的访问API。 1.2 Spring Cloud Gateway介绍 Spring Cloud Gateway 是 Spring Cloud 的新一代API网关基于WebFlux框架实现它旨在为微服务架构提供一种简单而有效的统一的API路由管理方式。 Spring Cloud Gateway作为Spring Cloud生态系统中的网关目标是替代Netflix ZUUL具有更好的性能、更强的扩展性、以及更丰富的功能特性其不仅提供统一的路由方式并且基于Filter链的方式提供了网关基本的功能例如:安全监控/埋点限流等。 1.3 Gateway特性 Spring Cloud Gateway特性 基于Spring Framework 5 Project Reactor和Spring Boot 2.0动态路由能够匹配任何请求属性可以对路由指定 Predicate 和 Filter集成Hystrix断路器集成 Spring Cloud DiscoveryClient 服务发现功能易于编写的Predicate和Filter请求限流支持路径重写 1.4 Gateway核心概念 1.4.1 路由 1.4.1.1 定义 路由(Route)是网关最基础的部分路由信息由一个ID一个目标URI一组断言和过滤器组成。路由断言Predicate用于匹配请求过滤器 Filter 用于修改请求和响应。如果断言为true则说明请求URI和配置匹配则执行路由。 spring:cloud:gateway:# 定义多个路由routes:# 一个路由route的id- id: path_route# 该路由转发的目标URIuri: https://example.org# 路由条件集合predicates:- Path/test/**# 过滤器集合filters:- AddRequestHeaderX-Request-Id, 1024- AddRequestParametercolor, red1.4.1.2 动态路由 网关接收外部请求按照一定的规则将请求转发给其他服务或者应用。如果站在服务调用的角度网关就扮演着服务消费者的角色此时如果再来看看服务调用的目标URI配置就会很自然的发现一个问题服务提供者调用的地址是写死的即网关没有动态的发现服务这就涉及到了服务的自动发现问题以及发现服务后所涉及到的服务调用的负载均衡的问题。 可以通过Nacos或者Eureka注册中心动态发现服务通过Ribbon进行服务调用的负载均衡。同样Gateway也可以整合Nacos或者EurekaRibbon从而实现动态路由的功能。 想要使用动态路由的功能首先要整合注册中心这里以Nacos为例 pom依赖 !--SpringCloud ailibaba nacos -- dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId /dependency配置文件 spring:application:name: cloud-gatewaycloud:nacos:discovery:server-addr: localhost:8848gateway:routes:#路由的ID没有固定规则但要求唯一建议配合服务名- id: config_route#匹配后提供服务的路由地址, 这里lb之后跟的是要调用的服务名称uri: lb://nacos-provider-8002# 断言路径相匹配的条件predicates:- Path/routeconfig/rest/**此时当id为config_route的路由规则匹配某个请求后在调用该请求对应的服务时就会从nacos注册中心自动发现服务并在服务调用的时候实现负载均衡。 1.4.2 断言 断言(Predicate)参考Java8 中的断言 Predicate 用于实现请求匹配逻辑例如匹配路径、请求头、请求参数等。请求与断言匹配则执行该路由。 在Gateway中有一些的内置Predicate Factory有了这些Pridicate Factory在运行时Gateway 会自动根据需要创建其对应的 Pridicate 对象测试路由条件。 1.4.2.1 默认断言 Gateway提供的断言有Path 路由断言After 路由断言Cookie 路由断言Header 路由断言 Host 路由断言 Method 路由断言 Path 路由断言 Factory 根据请求路径匹配的路由条件工厂 spring:cloud:gateway:routes:- id: path_routeuri: https://example.orgpredicates:# 如果可以匹配的PathPattern有多个则每个路径模式以分开- Path/red/{segment},/blue/{segment}After 路由断言 Factory 在指定日期时间之后发生的请求都将被匹配 spring:cloud:gateway:routes:- id: after_routeuri: https://example.orgpredicates:- After2017-01-20T17:42:47.789-07:00[America/Denver]Cookie 路由断言 Factory Cookie 路由断言 Factory有两个参数cookie名称和正则表达式。请求包含此cookie名称且正则表达式为真的将会被匹配。 spring:cloud:gateway:routes:- id: cookie_routeuri: https://example.orgpredicates:- Cookiechocolate, ch.pHeader 路由断言 Factory Header 路由断言 Factory有两个参数header名称和正则表达式。请求包含此header名称且正则表达式为真的将会被匹配。 spring:cloud:gateway:routes:- id: header_routeuri: https://example.orgpredicates:- HeaderX-Request-Id, \dHost 路由断言 Factory Host 路由断言 Factory包括一个参数host name列表。使用Ant路径匹配规则 . 作为分隔符。 spring:cloud:gateway:routes:- id: host_routeuri: https://example.orgpredicates:- Host**.somehost.org,**.anotherhost.orgMethod 路由断言 Factory Method 路由断言 Factory只包含一个参数需要匹配的HTTP请求方式 spring:cloud:gateway:routes:- id: method_routeuri: https://example.orgpredicates:- MethodGET1.4.2.2 自定义Predicate 可以自定义Predicate来实现复杂的路由匹配规则 实现自定义 Predicate 工厂 通过HostRoutePredicateFactory创建Predicate进行路由判断 Component public class MyHostRoutePredicateFactory extends AbstractRoutePredicateFactoryMyHostRoutePredicateFactory.Config {public MyHostRoutePredicateFactory() {// Config 类作为 Predicate 的配置参数类super(Config.class);}public static class Config {// 路由匹配规则private String hostName;public String getHostName() {return hostName;}public void setHostName(String hostName) {this.hostName hostName; }}// 生成一个 Predicate 实例Overridepublic PredicateServerWebExchange apply(Config config) {// 实现匹配逻辑return exchange - {// 根据config实现匹配判断 String host exchange.getRequest().getURI().getHost();// 匹配配置中的域名return host.equals(config.getHostName());};} }使用 RouteLocator locator new RouteLocatorBuilder(router).routes().route(test_route, r - r.path(/test).filters(f - f.filter(new MyHostRoutePredicateFactory.Config(www.test.com))).uri(http://localhost:8080)).build();1.4.3 过滤器 过滤器(Filter) 指的是Spring框架中GatewayFilter的实例使用过滤器可以在请求被路由前后对请求进行修改 1.4.3.1 默认过滤器 配置文件中添加过滤器 filters filters:- AddRequestHeadername,zs #请求头添加name:zs- AddRequestParametercolor,blue #请求参数添加color:blue- AddResponseHeaderphone,973345344 #响应头添加phone:973345344- PrefixPath/mypath #添加路径前缀/mypath- StripPrefixn #删除路径前缀n个Spring Cloud Gateway内置的多种过滤器类例如: AddRequestHeader GatewayFilter在请求头中添加参数PrefixPath GatewayFilter请求路径前缀Hystrix GatewayFilter断路器RateLimit GatewayFilter限流Retry GatewayFilter重试 1.4.3.2 自定义FilterGatewayFilter 可以通过实现GatewayFilter和Ordered接口自定义Filter来实现请求处理逻辑: Component public class TokenFilter implements GatewayFilter, Ordered {Overridepublic MonoVoid filter(ServerWebExchange exchange, GatewayFilterChain chain) {//请求处理逻辑log.info(请求路径: exchange.getRequest().getPath());ServerHttpRequest request exchange.getRequest();MultiValueMapString, HttpCookie cookies request.getCookies();ListHttpCookie tokens cookies.get(access_token);if (tokens null || tokens.size() 0) {throw new RuntimeException(少了cookie);}return chain.filter(exchange);}Overridepublic int getOrder() {return 0; } }1.4.3.2 自定义FilterGlobalFilter public class MyFilter implements GlobalFilter {Overridepublic MonoVoid filter(ServerWebExchange exchange, GatewayFilterChain chain) {ServerHttpRequest request exchange.getRequest();ServerHttpResponse response exchange.getResponse();return null;} }1.4.3.3 自定义FilterAbstractGatewayFilterFactory 通过继承AbstractGatewayFilterFactory来实现 public class DemoGatewayFilterFactory extends AbstractGatewayFilterFactoryDemoGatewayFilterFactory.Config {Overridepublic GatewayFilter apply(Config config) {return null;}//Config 静态内部类负责指定网关的参数static class Config{private String arg1;} }注意DemoGatewayFilterFactory 的命名方式由Demo GatewayFilterFactory组成 其中Demo是自己起名字GatewayFilterFactory是固定的。 范型中的Config是我们待会要用到的静态内部类用于声明过滤器中传递的参数 在Spring Cloud Gateway中自定义的过滤器会在全局过滤器链中生效不需要显式配置在路由配置中。这是因为AbstractGatewayFilterFactory类已经实现了GatewayFilterFactory接口并且通过Spring的自动装配机制将其注册到全局过滤器链中并且可以在任何路由上生效。 需要注意的是在全局过滤器链中的顺序是根据Spring Bean加载顺序决定的。可以通过设置Order注解或实现Ordered接口来控制自定义过滤器在全局过滤器链中的顺序。 1.5 Gateway工作流程 客户端向 Spring Cloud Gateway发出请求然后在Gateway Handler Mapping中找到与请求相匹配的路由将其发送到 Gateway Web Handler。Handler再通过指定的过滤器链来对请求进行过滤处理最后发送到我们实际的服务执行业务逻辑然后返回。 过滤器链被虚线分隔是因为过滤器既可以在转发请求前拦截请求也可以在请求处理之后对响应进行拦截处理。 1.6 实际操作 1.6.1 pom.xml dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId /dependency1.6.2 启动类 SpringBootApplication EnableEurekaClient public class GatewayApplication {public static void main(String[] args) {SpringApplication.run(GatewayApplication.class, args);} }1.6.3 配置文件 application.yml spring: application:name: cloud-gateway cloud:gateway:routes:# 路由的ID没有固定规则但要求唯一建议配合服务名- id: config_route# 匹配后提供服务的路由地址uri: http://ityouknow.com# 断言路径相匹配的条件predicates:- Path/routeconfig/rest/**- id: header_routeuri: http://ityouknow.compredicates:- HeaderX-Request-Id, \d参考连接 https://mp.weixin.qq.com/s/LY66FPCajHkzXJUFlfSNYg https://blog.csdn.net/h1774733219/article/details/124384527 https://blog.csdn.net/qq_46203643/article/details/127150590
文章转载自:
http://www.morning.zzgkk.cn.gov.cn.zzgkk.cn
http://www.morning.hkchp.cn.gov.cn.hkchp.cn
http://www.morning.hbxnb.cn.gov.cn.hbxnb.cn
http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn
http://www.morning.qpmmg.cn.gov.cn.qpmmg.cn
http://www.morning.rpjr.cn.gov.cn.rpjr.cn
http://www.morning.mrfgy.cn.gov.cn.mrfgy.cn
http://www.morning.qkqhr.cn.gov.cn.qkqhr.cn
http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn
http://www.morning.qttft.cn.gov.cn.qttft.cn
http://www.morning.xrlwr.cn.gov.cn.xrlwr.cn
http://www.morning.yqwsd.cn.gov.cn.yqwsd.cn
http://www.morning.zpfqh.cn.gov.cn.zpfqh.cn
http://www.morning.swdnr.cn.gov.cn.swdnr.cn
http://www.morning.xkgyh.cn.gov.cn.xkgyh.cn
http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn
http://www.morning.qmbpy.cn.gov.cn.qmbpy.cn
http://www.morning.hhqjf.cn.gov.cn.hhqjf.cn
http://www.morning.zrnph.cn.gov.cn.zrnph.cn
http://www.morning.wpxfk.cn.gov.cn.wpxfk.cn
http://www.morning.kdnbf.cn.gov.cn.kdnbf.cn
http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn
http://www.morning.wmmqf.cn.gov.cn.wmmqf.cn
http://www.morning.bhxzx.cn.gov.cn.bhxzx.cn
http://www.morning.fnkcg.cn.gov.cn.fnkcg.cn
http://www.morning.dangaw.com.gov.cn.dangaw.com
http://www.morning.rlns.cn.gov.cn.rlns.cn
http://www.morning.myrmm.cn.gov.cn.myrmm.cn
http://www.morning.bhbxd.cn.gov.cn.bhbxd.cn
http://www.morning.shawls.com.cn.gov.cn.shawls.com.cn
http://www.morning.qkcyk.cn.gov.cn.qkcyk.cn
http://www.morning.jjmrx.cn.gov.cn.jjmrx.cn
http://www.morning.kbdrq.cn.gov.cn.kbdrq.cn
http://www.morning.kqglp.cn.gov.cn.kqglp.cn
http://www.morning.wftrs.cn.gov.cn.wftrs.cn
http://www.morning.fbmjw.cn.gov.cn.fbmjw.cn
http://www.morning.zljqb.cn.gov.cn.zljqb.cn
http://www.morning.rbsmm.cn.gov.cn.rbsmm.cn
http://www.morning.swzpx.cn.gov.cn.swzpx.cn
http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn
http://www.morning.elsemon.com.gov.cn.elsemon.com
http://www.morning.zqmdn.cn.gov.cn.zqmdn.cn
http://www.morning.xnqwk.cn.gov.cn.xnqwk.cn
http://www.morning.rrms.cn.gov.cn.rrms.cn
http://www.morning.zpyh.cn.gov.cn.zpyh.cn
http://www.morning.xhqr.cn.gov.cn.xhqr.cn
http://www.morning.cwskn.cn.gov.cn.cwskn.cn
http://www.morning.bbrf.cn.gov.cn.bbrf.cn
http://www.morning.mftzm.cn.gov.cn.mftzm.cn
http://www.morning.kzslk.cn.gov.cn.kzslk.cn
http://www.morning.tdttz.cn.gov.cn.tdttz.cn
http://www.morning.lizimc.com.gov.cn.lizimc.com
http://www.morning.cfhwn.cn.gov.cn.cfhwn.cn
http://www.morning.hbxnb.cn.gov.cn.hbxnb.cn
http://www.morning.lgkbn.cn.gov.cn.lgkbn.cn
http://www.morning.xxwhz.cn.gov.cn.xxwhz.cn
http://www.morning.kztts.cn.gov.cn.kztts.cn
http://www.morning.bdgb.cn.gov.cn.bdgb.cn
http://www.morning.tcylt.cn.gov.cn.tcylt.cn
http://www.morning.qtzqk.cn.gov.cn.qtzqk.cn
http://www.morning.drfrm.cn.gov.cn.drfrm.cn
http://www.morning.sxbgc.cn.gov.cn.sxbgc.cn
http://www.morning.gygfx.cn.gov.cn.gygfx.cn
http://www.morning.qcymf.cn.gov.cn.qcymf.cn
http://www.morning.xjkfb.cn.gov.cn.xjkfb.cn
http://www.morning.lstmg.cn.gov.cn.lstmg.cn
http://www.morning.lnnc.cn.gov.cn.lnnc.cn
http://www.morning.qxnns.cn.gov.cn.qxnns.cn
http://www.morning.hdrsr.cn.gov.cn.hdrsr.cn
http://www.morning.rlbg.cn.gov.cn.rlbg.cn
http://www.morning.jhzct.cn.gov.cn.jhzct.cn
http://www.morning.bgdk.cn.gov.cn.bgdk.cn
http://www.morning.nmpdm.cn.gov.cn.nmpdm.cn
http://www.morning.zrhhb.cn.gov.cn.zrhhb.cn
http://www.morning.rmlz.cn.gov.cn.rmlz.cn
http://www.morning.jlxqx.cn.gov.cn.jlxqx.cn
http://www.morning.klyzg.cn.gov.cn.klyzg.cn
http://www.morning.mnclk.cn.gov.cn.mnclk.cn
http://www.morning.rjjys.cn.gov.cn.rjjys.cn
http://www.morning.rfbq.cn.gov.cn.rfbq.cn
http://www.tj-hxxt.cn/news/282502.html

相关文章:

  • 装饰公司网站方案个体工商户注册查询
  • 贵阳做网站方舟网络北京科技网站建设公司
  • 浙江省住房与城乡建设部网站wordpress 文件说明
  • 类似 wordpress 建站做的比较好的二手交易网站有哪些
  • 北京网站建设 一流建设手机银行的网站
  • 网站建设 个体经营范围聊城网站制作公司
  • 电子商务的网站开发开发app需要什么设备
  • 网站网店建设河北省 建设执业注册中心网站
  • 移动论坛网站模板免费微信网站制作平台
  • 深圳哪家网站建设好网站做子页面怎么做的
  • 做旅游攻略网站网页制作app手机版
  • 网站建设在哪里招聘中科诚建建设工程有限公司网站
  • 大港建站公司网站 设计案例
  • ifront做原型控件的网站小学网站模板下载
  • 中国icp备案网站浏览器无法访问wordpress报503
  • 做电子元器件销售什么网站好外贸自建站如何收款
  • 深圳网站设计吧建筑公司跟建设公司有什么区别
  • 南京做网站南京乐识最优门窗网站模板
  • 淘宝做网站费用网站名称怎么填写
  • 哈尔滨模板建站源码安卓移动开发
  • html网站设计实验报告阿里云网站建设教程视频
  • 安卓手机应用市场一个网站的seo优化有哪些
  • 重庆公司网站 技术支持vue做pc网站
  • 网站建设需要个体营业执照吗wordpress 回复 验证码
  • 天津老区建设促进会网站直播软件开发需要多少钱
  • 福州网站建设 网络服务现在建设网站都用什么软件
  • 网站的域名分为哪些关键词网站建设
  • 中企业网站建设网站 502错误
  • 网站开发环境lmnp网站风格规划
  • 网站建设模板成功案例微信号30元一个自动发货