亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Spring cloud gateway工作流程原理解析

瀏覽:69日期:2023-09-07 09:18:58

spring cloud gateway的包結構(在Idea 2019.3中展示)

Spring cloud gateway工作流程原理解析

這個包是spring-cloud-gateway-core.這里是真正的spring-gateway的實現(xiàn)的地方.

為了證明,我們打開spring-cloud-starter-gateway的pom文件

<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-gateway-core</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> </dependencies>

除了cloud-start,starter-webflux就是cloud-gateway-core.所以后面我們就分析

cloud-gateway-core這個jar包.

Spring cloud gateway工作流程原理解析

其中actuate中定義了GatewayControllerEndpoint,它提供了對外訪問的接口.

// TODO: Flush out routes without a definition @GetMapping('/routes') public Flux<Map<String, Object>> routes() { return this.routeLocator.getRoutes().map(this::serialize); } @GetMapping('/routes/{id}') public Mono<ResponseEntity<Map<String, Object>>> route(@PathVariable String id) { //...... }//以下方法是繼承于父類,抽象類AbstractGatewayControllerEndpoint @PostMapping('/refresh') public Mono<Void> refresh() { this.publisher.publishEvent(new RefreshRoutesEvent(this)); return Mono.empty(); } @GetMapping('/globalfilters') public Mono<HashMap<String, Object>> globalfilters() { return getNamesToOrders(this.globalFilters); } @GetMapping('/routefilters') public Mono<HashMap<String, Object>> routefilers() { return getNamesToOrders(this.GatewayFilters); } @GetMapping('/routepredicates') public Mono<HashMap<String, Object>> routepredicates() { return getNamesToOrders(this.routePredicates); } @PostMapping('/routes/{id}') @SuppressWarnings('unchecked') public Mono<ResponseEntity<Object>> save(@PathVariable String id, @RequestBody RouteDefinition route) {} @DeleteMapping('/routes/{id}') public Mono<ResponseEntity<Object>> delete(@PathVariable String id) { return this.routeDefinitionWriter.delete(Mono.just(id)).then(Mono.defer(() -> Mono.just(ResponseEntity.ok().build()))).onErrorResume(t -> t instanceof NotFoundException, t -> Mono.just(ResponseEntity.notFound().build())); } @GetMapping('/routes/{id}/combinedfilters') public Mono<HashMap<String, Object>> combinedfilters(@PathVariable String id) { // TODO: missing global filters }

config包里定義了一些Autoconfiguration和一些properties.讀取配置文件就在這里完成.

Spring cloud gateway工作流程原理解析

我們這里看一下GatewayProperties.java

@ConfigurationProperties('spring.cloud.gateway')@Validatedpublic class GatewayProperties { /** * List of Routes. */ @NotNull @Valid private List<RouteDefinition> routes = new ArrayList<>(); /** * List of filter definitions that are applied to every route. */ private List<FilterDefinition> defaultFilters = new ArrayList<>(); private List<MediaType> streamingMediaTypes = Arrays .asList(MediaType.TEXT_EVENT_STREAM, MediaType.APPLICATION_STREAM_JSON); #該類包括三個屬性,路由列表,默認過濾器列表和MediaType列表.路由列表中的路由定義RouteDefinition. 過濾器中定義的FilterDefinition.

discovery定義了注冊中心的一些操作.

event定義了一系列事件,都繼承自ApplicationEvent.

filter定義了spring gateway實現(xiàn)的一些過濾器,包括gatewayfilter,globalfilter.

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Spring
相關文章:
主站蜘蛛池模板: 免费成人黄色大片 | 欧美蜜臀 | 99精品热视频这里只有精品7 | 欧美在线视频 一区二区 | 成年人网站黄色 | 黑人爱爱视频 | 96国产精品| 视频福利网 | 国产啪爱视频精品免视 | 久久免费成人 | 成人精品视频 成人影院 | 国产成人综合网 | 成年女人毛片免费观看不卡 | 永久免费不卡在线观看黄网站 | 99久久久久国产 | 免费观看成人羞羞视频网站观看 | 久久中文字幕视频 | 亚洲欧洲一二三区机械有限公司 | 国产精品亚洲一区二区在线观看 | 天天色影网 | 国产精品美女在线观看 | 色接久久| 欧美亚洲偷图色综合91 | 国产青草视频在线观看 | 国产精品永久免费自在线观看 | 国产在线观看午夜不卡 | 欧美一级毛片高清免费观看 | 午夜社区| 97久久天天综合色天天综合色 | 香蕉97超级碰碰碰免费公 | 黄色网络在线观看 | 欧美精品黄页免费高清在线 | 中国一级特黄真人毛片免费看 | 欧美人人草| 日韩美在线 | 一级做a爰片久久毛片免费看 | 欧美日韩国产综合视频一区二区三区 | 俺去鲁婷婷六月色综合 | 欧美大片a一级毛片视频 | 99精品久久秒播无毒不卡 | 中文字幕亚洲综合 |