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

山西建设网站公司网页设计与网站建设的目的

山西建设网站公司,网页设计与网站建设的目的,广州网站建设oem,新手学网站建设看什么书好1. SpringCloud 与 SpringBoot的版本映射关系 在已有的Spring Boot项目中增加Spring Cloud,首先要确定使用的Spring Cloud的版本,这取决于项目使用的Spring Boot的版本 SpringCloud 与 SpringBoot的版本映射关系 如果两者的版本不兼容,再会…

1. SpringCloud 与 SpringBoot的版本映射关系

在已有的Spring Boot项目中增加Spring Cloud,首先要确定使用的Spring Cloud的版本,这取决于项目使用的Spring Boot的版本
SpringCloud 与 SpringBoot的版本映射关系

如果两者的版本不兼容,再会报: Spring Boot [2.x.x] is not compatible with this Spring Cloud release train

在这里插入图片描述

2. spring-cloud-gateway配置

Spring Cloud Gateway旨在提供一种简单而有效的方式来路由API服务,并为它们提供横切关注点,例如:安全性、监控/指标和弹性。

目前的版本信息:
在这里插入图片描述

2.1. 项目中如何包含spring-cloud-gateway

在项目中引入如下依赖:

		<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId><version>3.0.8</version></dependency>

注意:

  • 如果引入依赖,但不希望启用网关,请设置spring.cloud.gateway.enabled=false
  • Spring Cloud Gateway构建在Spring Boot 2Spring WebFluxProject Reactor之上,所以许多同步库(例如Spring DataSpring Security)和模式可能不适用
  • Spring Cloud Gateway需要Spring BootSpring Webflux提供的Netty Runtime。它不能在传统的Servlet容器中工作,也不能作为WAR构建。

2.2. 基本术语

  • Route 路由: 网关的基本组成部分。它由一个ID、一个目标URI、一组谓词和一组过滤器定义。如果聚合谓词为真,则匹配路由。
  • Predicate 谓词: 一个Java 8函数谓词。输入类型为Spring Framework ServerWebExchange,在编程时可以匹配HTTP请求中的任何内容,例如 headers 或参数。
  • Filter 过滤器: 使用特定工厂构造的GatewayFilter的实例,可以在发送下游请求之前或之后修改请求和响应。

2.3. 如何工作?

  1. 客户端向Spring Cloud Gateway发出请求。
  2. 如果网关处理程序映射确定请求与路由匹配,则将其发送到网关Web处理程序。
  3. 此处理程序通过特定于请求的过滤器链【filter chain】运行请求。
    • 过滤器用虚线分隔的原因是过滤器可以在发送代理请求之前和之后运行逻辑。
    • 执行所有“预”过滤器逻辑。然后发出代理请求。发出代理请求后,将运行“post”过滤器逻辑。
      在这里插入图片描述

2.4. 如何配置?

  • 路由谓词工厂 Route Predicate Factories 网关匹配路由作为Spring WebFlux HandlerMapping基础架构的一部分。Spring Cloud Gateway包括许多内置的路由谓词工厂。所有这些谓词都匹配HTTP请求的不同属性。可以将多个路由谓词工厂与逻辑和语句组合在一起。
  • Gateway 过滤器工厂 路由过滤器允许以某种方式修改传入的HTTP请求或传出的HTTP响应。路由过滤器的作用域是特定的路由。Spring Cloud Gateway包括许多内置的GatewayFilter工厂。

路由谓词配置示例

即在spring boot的配置文件如application.yml中配置,配置示例如下:

spring:cloud:gateway:routes:- id: after_routeuri: https://example.orgpredicates:- After=2017-01-20T17:42:47.789-07:00[America/Denver]- id: before_routeuri: https://example.orgpredicates:- Before=2017-01-20T17:42:47.789-07:00[America/Denver]- id: between_routeuri: https://example.orgpredicates:- Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]- id: cookie_routeuri: https://example.orgpredicates:- Cookie=chocolate, ch.p- id: header_routeuri: https://example.orgpredicates:- Header=X-Request-Id, \d+- id: host_routeuri: https://example.orgpredicates:- Host=**.somehost.org,**.anotherhost.org- id: method_routeuri: https://example.orgpredicates:- Method=GET,POST- id: path_routeuri: https://example.orgpredicates:- Path=/red/{segment},/blue/{segment}- id: query_routeuri: https://example.orgpredicates:- Query=red, gree.- id: remoteaddr_routeuri: https://example.orgpredicates:- RemoteAddr=192.168.1.1/24# The Weight Route Predicate Factory- id: weight_highuri: https://weighthigh.orgpredicates:- Weight=group1, 8- id: weight_lowuri: https://weightlow.orgpredicates:- Weight=group1, 2

路由过滤器配置示例

spring:cloud:gateway:routes:- id: add_request_header_routeuri: https://example.orgpredicates:- Path=/red/{segment}filters:- AddRequestHeader=X-Request-Red, Blue-{segment}- id: add_request_parameter_routeuri: https://example.orgpredicates:- Host: {segment}.myhost.orgfilters:- AddRequestParameter=foo, bar-{segment}- id: add_response_header_routeuri: https://example.orgpredicates:- Host: {segment}.myhost.orgfilters:- AddResponseHeader=foo, bar-{segment}- id: prefixpath_routeuri: https://example.orgfilters:- PrefixPath=/mypath- id: requestratelimiter_routeuri: https://example.orgfilters:- name: RequestRateLimiterargs:redis-rate-limiter.replenishRate: 10redis-rate-limiter.burstCapacity: 20redis-rate-limiter.requestedTokens: 1- id: prefixpath_routeuri: https://example.orgfilters:- RedirectTo=302, https://acme.org

代码配置示例

	@Beanpublic RouteLocator customRouteLocator(RouteLocatorBuilder builder) {//@formatter:offRouteLocator routeLocator = builder.routes().route("path_route", r -> r.path("/get").uri("http://httpbin.org")).route("host_route", r -> r.host("*.myhost.org").uri("http://httpbin.org")).route("rewrite_route", r -> r.host("*.rewrite.org").filters(f -> f.rewritePath("/foo/(?<segment>.*)","/${segment}")).uri("http://httpbin.org")).route("circuitbreaker_route", r -> r.host("*.circuitbreaker.org").filters(f -> f.circuitBreaker(c -> c.setName("slowcmd"))).uri("http://httpbin.org")).route("circuitbreaker_fallback_route", r -> r.host("*.circuitbreakerfallback.org").filters(f -> f.circuitBreaker(c -> c.setName("slowcmd").setFallbackUri("forward:/circuitbreakerfallback"))).uri("http://httpbin.org")).route("limit_route", r -> r.host("*.limited.org").and().path("/anything/**","/bnything/**").filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter()))).uri("http://httpbin.org")).route("websocket_route", r -> r.path("/echo").uri("ws://localhost:9000")).build();return routeLocator;}

3. Global Filter

GlobalFilter接口与GatewayFilter接口具有相同的签名。GlobalFilter是有条件地应用于所有路由的特殊过滤器。

当请求匹配路由时,过滤web处理程序将GlobalFilter的所有实例和GatewayFilter的所有路由特定实例添加到过滤器链中。这个组合过滤器链由org.springframework.core.Ordered接口排序,可以通过实现getOrder()方法来设置该接口。

接口示例

@Bean
public GlobalFilter customFilter() {return new CustomGlobalFilter();
}public class CustomGlobalFilter implements GlobalFilter, Ordered {@Overridepublic Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {log.info("custom global filter");return chain.filter(exchange);}@Overridepublic int getOrder() {return -1;}
}

4. 如何配置跨域CORS

spring:cloud:gateway:globalcors:cors-configurations:'[/**]':allowedOrigins: "https://docs.spring.io"allowedMethods:- GET

5. http超时配置

  • 全局配置
spring:cloud:gateway:httpclient:connect-timeout: 1000response-timeout: 5s
  • 特定路由配置
      - id: per_route_timeoutsuri: https://example.orgpredicates:- name: Pathargs:pattern: /delay/{timeout}metadata:response-timeout: 200connect-timeout: 200
import static org.springframework.cloud.gateway.support.RouteMetadataUtils.CONNECT_TIMEOUT_ATTR;
import static org.springframework.cloud.gateway.support.RouteMetadataUtils.RESPONSE_TIMEOUT_ATTR;@Beanpublic RouteLocator customRouteLocator(RouteLocatorBuilder routeBuilder){return routeBuilder.routes().route("test1", r -> {return r.host("*.somehost.org").and().path("/somepath").filters(f -> f.addRequestHeader("header1", "header-value-1")).uri("http://someuri").metadata(RESPONSE_TIMEOUT_ATTR, 200).metadata(CONNECT_TIMEOUT_ATTR, 200);}).build();}

6. Actuator API

开启配置:spring.cloud.gateway.actuator.verbose.enabled=true
下表总结了Spring Cloud Gateway执行器端点(注意每个端点都以/actuator/gateway为基路径):

IDHTTP MethodDescription
globalfiltersGETDisplays the list of global filters applied to the routes.
routefiltersGETDisplays the list of GatewayFilter factories applied to a particular route.
refreshPOSTClears the routes cache.
routesGETDisplays the list of routes defined in the gateway.
routes/{id}GETDisplays information about a particular route.
routes/{id}POSTAdds a new route to the gateway.
routes/{id}DELETERemoves an existing route from the gateway.

附录

spring-cloud-gateway 在使用时,还有很多其它需要关注的,详见官方使用文档spring-cloud-gateway reference


文章转载自:

http://smKbKKQ6.dxhdn.cn
http://ruRegaFa.dxhdn.cn
http://EShDPjbs.dxhdn.cn
http://r2QWJ8DS.dxhdn.cn
http://MIJU7xgI.dxhdn.cn
http://GdAFXDkF.dxhdn.cn
http://YipGHuc4.dxhdn.cn
http://ie2xh3AI.dxhdn.cn
http://HSu4hFNW.dxhdn.cn
http://aL6Pjowf.dxhdn.cn
http://uKcDJ4wc.dxhdn.cn
http://TvSFEISd.dxhdn.cn
http://dZfzhqKf.dxhdn.cn
http://YAu2chPl.dxhdn.cn
http://xg8uPSAn.dxhdn.cn
http://4imhZzy5.dxhdn.cn
http://j1QUXkiF.dxhdn.cn
http://XW99JXr8.dxhdn.cn
http://yDAS8RxT.dxhdn.cn
http://cSKwQ7dM.dxhdn.cn
http://l50xpIqF.dxhdn.cn
http://7I2CRsE1.dxhdn.cn
http://wBrmRRxU.dxhdn.cn
http://2BX1TrO2.dxhdn.cn
http://WM0xrwSp.dxhdn.cn
http://bXxoFcdE.dxhdn.cn
http://pHNvAjDF.dxhdn.cn
http://GealMuA3.dxhdn.cn
http://NxhYQHs1.dxhdn.cn
http://bYLjfta4.dxhdn.cn
http://www.dtcms.com/wzjs/737451.html

相关文章:

  • 成品网站管系统黄山网站设计公司
  • 南宁网站建设云尚网络如何接单做网站
  • 自己做一个音乐网站怎么做重庆定制型网站建设
  • 网站制作需要多少费用制作网站软件免费
  • 重庆网站空间键词排名wordpress 集赞系统
  • 做网站怎么做wordpress 后台 模板
  • 怎么建设网站石家庄网站托管公司
  • 新网站seo技术wordpress全是博客
  • 化妆品销售网站的源代码腾讯云服务器学生
  • 上海个人网站备案wordpress post模板
  • 洛阳疾控最新通告今天谷歌搜索优化
  • 网站建设与网页设计心得体会wordpress 大型站
  • 商城网站做推广方案南昌网站制作代理商
  • 网站制作应用搭建个人主页
  • 中山 环保 骏域网站建设专家销客多分销小程序价格
  • 网站优化推广哪家好深喘旋磨做紧夹断妖精网站
  • 大网站服务器维护费用怎么制作ppt 教程
  • 企业网站建设费用属于什么科目平台推广方案模板
  • python手机编程软件长沙网站优化指导
  • 新河网站快排seo建筑网课平台
  • 山东 网站建设 公司太原市住房与城乡建设厅网站
  • 南阳理工网站建设私人可以有官方网址吗
  • 深圳网站建设 宝华大厦泰兴网页定制
  • 网站后台策划书2024年还会封城吗
  • 开网站需要哪些程序莆田网站建设方案优化
  • 什么样的资质做电子商务网站python 网站建设
  • 广东装饰公司网站建设国家企业信用信息查询系统
  • 建设银行 福州招聘网站湖北seo服务
  • 贵港市网站建设搭建企业网站公司
  • 专门做搞笑视频的网站遮罩层怎么做网页