springcloud家族路由系列之getway


他就是一个api网关,统一管理各个子系统的访问,客户端的所有请求都要经过api网关,对于资源达到限流、控流的功能,对于安全,达到授权的功能。

springcloud家族路由系列之geteway

springcloud自己新推出的网关框架。

基础项目搭建(idea)

1、新建项目选择项目类型

新建自适应spring项目

2、设置项目团队名、产品名、项目类型、语言、打包方式、语言版本、项目版本、项目名字、项目摘要、项目包路径

在这里插入图片描述

3、引用geteway的maven依赖

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Cloud Alibaba 是阿里巴巴开发的一款基于 Spring Cloud 的微服务开发框架。它提供了一系列微服务开发所需的核心组件,如服务注册与发现、配置中心、消息总线、负载均衡、熔断器、数据存储等。而 Spring Cloud Gateway 则是 Spring Cloud 微服务架构的网关,它基于 Spring 5.0,使用了 Reactor 模式实现了非阻塞式的 API 服务路由代理。 下面是 Spring Cloud Alibaba 整合 Spring Cloud Gateway 的步骤: 1. 创建 Spring Boot 项目,并添加 Spring Cloud Alibaba 和 Spring Cloud Gateway 依赖。 2. 编写配置文件,配置 Spring Cloud Alibaba Nacos 作为服务注册中心,并配置 Spring Cloud Gateway 的路由规则。 3. 在启动类上添加 @EnableDiscoveryClient 和 @EnableGateway 注解,启用服务注册和网关。 4. 编写过滤器,对请求进行处理。 5. 启动项目,访问网关地址进行测试。 参考示例代码: pom.xml 文件添加依赖: ```xml <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency> </dependencies> ``` application.yml 文件配置: ```yaml server: port: 8080 spring: application: name: gateway cloud: nacos: discovery: server-addr: localhost:8848 gateway: routes: - id: test_route uri: http://localhost:8081 predicates: - Path=/test/** - id: demo_route uri: http://localhost:8082 predicates: - Path=/demo/** ``` 启动类 GatewayApplication.java 文件: ```java @SpringBootApplication @EnableDiscoveryClient @EnableGateway public class GatewayApplication { public static void main(String[] args) { SpringApplication.run(GatewayApplication.class, args); } } ``` 编写过滤器 GlobalFilter.java 文件: ```java @Component public class GlobalFilter implements GatewayFilter, Ordered { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { // 处理请求 return chain.filter(exchange); } @Override public int getOrder() { return 0; } } ``` 以上就是 Spring Cloud Alibaba 整合 Spring Cloud Gateway 的简单示例,希望可以帮助到你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值