久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

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

Spring cloud gateway工作流程原理解析

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

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

Spring cloud gateway工作流程原理解析

這個包是spring-cloud-gateway-core.這里是真正的spring-gateway的實現的地方.

為了證明,我們打開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實現的一些過濾器,包括gatewayfilter,globalfilter.

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

標簽: Spring
相關文章:
主站蜘蛛池模板: 精品1区| 亚州精品成人 | 欧美在线视频一区 | 国产精品视频专区 | 欧美污污| 国产视频观看 | 求av网址 | 2018自拍偷拍 | 成人免费小视频 | 在线99 | 午夜窝窝 | 天天操,夜夜操 | 日韩高清中文字幕 | 不卡一区二区三区四区 | 亚洲天堂一区 | 亚洲午夜av | www日本视频| www.久久精品视频 | 亚洲精品在线视频 | 91偷拍精品一区二区三区 | 欧美精品在线不卡 | 97人人看 | 在线观看免费av网 | 免费v片在线观看 | 成人免费av| 国产精品18hdxxxⅹ在线 | 午夜激情免费看 | 亚洲人成网站999久久久综合 | 日日爱夜夜操 | 欧美国产精品一区二区 | 亚洲精美视频 | 污色视频在线观看 | 中文字幕在线免费视频 | 中文字幕av在线播放 | 国产精品久久久久久久岛一牛影视 | 九色在线 | 男人的天堂久久 | ririsao久久精品一区 | 久色| 久久久久一区二区三区 | 国产成人av一区二区三区 |