av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Spring cloud gateway工作流程原理解析

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

spring cloud gateway的包結(jié)構(gòu)(在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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 黄色一级片黄色一级片 | 欧美一区二 | 亚洲日本欧美 | 欧美在线综合 | 五月婷婷丁香综合 | 国产在线资源 | 国产成人97精品免费看片 | 日韩av在线看| 日韩中文在线观看 | 老司机精品福利视频 | 91超碰在线观看 | 97色在线 | 精品免费国产 | 毛片视频免费 | 亚洲一区视频在线 | 精品久久久久久久久久久久久 | 久久精品99久久久久久 | 成人国产精品久久久网站 | 国产午夜三级 | 中文在线免费观看 | 日韩一区二区在线视频 | 亚洲欧美日韩精品 | 成人免费视频观看视频 | av免费看片 | 日本激情网 | 成人免费视频一区二区 | 亚洲最大黄色网址 | 欧美综合在线观看 | 成人综合网站 | 成人动态视频 | 亚洲国产精品久久久久 | 国产成人a亚洲精品 | 午夜黄色影院 | 亚洲www.| 天天爽| 日韩精品一区二区三区免费视频 | 亚洲欧美视频一区 | 天天射日日干 | 国产欧美自拍 | 亚洲在线播放 | 超碰com|