Spring系列学习之Spring Cloud Gateway API网关路由规则设置

英文原文:Spring Cloud Gateway

目录

概述

特性

入门

快速开始

学习

文档

指南

 示例


概述

该项目提供了一个用于在Spring MVC之上构建API网关的库。 Spring Cloud Gateway旨在提供一种简单而有效的方式来路由到API,并为他们提供横切关注点,例如:安全性,监控/指标和弹性。

特性

Spring Cloud Gateway功能:

  •      基于Spring Framework 5,Project Reactor和Spring Boot 2.0构建
  •      能够匹配任何请求属性上的路由。
  •      谓词和过滤器特定于路线。
  •      Hystrix断路器集成。
  •      Spring Cloud DiscoveryClient集成
  •      易于编写谓词和过滤器
  •      请求率限制
  •      路径重写

入门



@SpringBootApplication
public class DemogatewayApplication {
	@Bean
	public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
		return 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("hystrix_route", r -> r.host("*.hystrix.org")
				.filters(f -> f.hystrix(c -> c.setName("slowcmd")))
				.uri("http://httpbin.org"))
			.route("hystrix_fallback_route", r -> r.host("*.hystrixfallback.org")
				.filters(f -> f.hystrix(c -> c.setName("slowcmd").setFallbackUri("forward:/hystrixfallback")))
				.uri("http://httpbin.org"))
			.route("limit_route", r -> r
				.host("*.limited.org").and().path("/anything/**")
				.filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter())))
				.uri("http://httpbin.org"))
			.build();
	}
}

要运行您自己的网关,请使用spring-cloud-starter-gateway依赖项。

快速开始

使用Spring Initializr引导您的应用程序。

学习

文档

每个Spring项目都有自己的; 它详细解释了如何使用项目功能以及使用它们可以实现的功能。

2.1.0 RC3 PRE CURRENTReference Doc. API Doc. 
2.0.3 SNAPSHOT CURRENTReference Doc. API Doc. 
2.0.2 CURRENT GAReference Doc. API Doc. 
1.0.3 SNAPSHOT CURRENTReference Doc. API Doc. 
1.0.2 CURRENT GAReference Doc. API Doc. 

指南

该指南旨在在15-30分钟内完成,提供快速,实用的说明,用于为Spring的任何开发任务构建入门应用程序。

 示例

尝试一些例子:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值