SpringCloud网关:Gateway

网关是介于客户端和服务器端之间的中间层,所有的外部请求都会先经过 网关这一层。也就是说,API 的实现方面更多的考虑业务逻辑,而安全、性能、监控可以交由 网关来做,这样既提高业务灵活性又不缺安全性,典型的架构图如图所示:

  • 安全 ,只有网关系统对外进行暴露,微服务可以隐藏在内网,通过防火墙保护。
  • 易于监控。可以在网关收集监控数据并将其推送到外部系统进行分析。
  • 易于认证。可以在网关上进行认证,然后再将请求转发到后端的微服务,而无须在每个微服务中进行认证。
  • 减少了客户端与各个微服务之间的交互次数
  • 易于统一鉴权。

Application注解如下:

@EnableZuulProxy
@SpringCloudApplication
public class ZuulGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(ZuulGatewayApplication.class,args);
    }
}

yaml配置文件如下:

server:
  port: 9000
spring:
  application:
    name: ad-gateway
eureka:
  client:
    service-url:
      defaultZone: http://server1:8000/eureka/

# 网关配置
zuul:
  prefix: /zmn # 统一前缀
  routes:      # 路由
    path: /ad-sponsor/** # 前缀
    serviceId: eureka-client-ad-sponsor  # 转发的微服务名字
    strip-prefix: false                  # 不跳过前缀 /ad-sponsor
                         

原文地址:https://www.cnblogs.com/zhuomuniao/p/12391957.html

时间: 2024-08-30 18:18:57

SpringCloud网关:Gateway的相关文章

第二代网关GateWay搭建流程

Spring Cloud第二代网关GateWay是由纯Netty开发,底层为Reactor,WebFlux构建,不依赖任何Servlet容器,它不同于Zuul,使用的是异步IO,性能较Zuul提升1.6倍.搭建过程如下(本次搭建的为子项目,主项目可以参考Nacos搭建流程 ) pom <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-start

springcloud组件gateway断言(Predicate)

Spring Cloud Gateway是SpringCloud的全新子项目,该项目基于Spring5.x.SpringBoot2.x技术版本进行编写,意在提供简单方便.可扩展的统一API路由管理方式. 概念解释: Route(路由):路由是网关的基本单元,由ID.URI.一组Predicate.一组Filter组成,根据Predicate进行匹配转发. Predicate(谓语.断言):路由转发的判断条件,目前SpringCloud Gateway支持多种方式,常见如:Path.Query.M

微服务SpringCloud之GateWay路由

在前面博客学习了网关zuul,今天学下spring官方自带的网关spring cloud gateway.Zuul(1.x) 基于 Servlet,使用阻塞 API,它不支持任何长连接,如 WebSockets,Spring Cloud Gateway 使用非阻塞 API,支持 WebSockets,支持限流等新特性. Spring Cloud Gateway 是 Spring Cloud 的一个全新项目,该项目是基于 Spring 5.0,Spring Boot 2.0 和 Project R

微服务网关GateWay

Gateway简介简介Spring Cloud Gateway 是 Spring 官方基于 Spring 5.0,Spring Boot 2.0 和 Project Reactor 等技术开发的网关,旨在为微服务架构提供一种简单而有效的统一的 API 路由管理方式,统一访问接口.SpringCloud Gateway 作为 Spring Cloud 生态系中的网关,目标是替代 Netflix ZUUL,其不仅提供统一的路由方式,并且基于 Filter 链的方式提供了网关基本的功能,例如:安全,监

微服务SpringCloud之GateWay服务化和过滤器

Spring Cloud Gateway 提供了一种默认转发的能力,只要将 Spring Cloud Gateway 注册到服务中心,Spring Cloud Gateway 默认就会代理服务中心的所有服务. 一.服务网关注册到注册中心 这里服务和注册中心使用前面博客中的EurekaServer和EurekaClient.服务网关注册到注册中心只需引入依赖包和增加配置. 1.引入依赖包spring-cloud-starter-netflix-eureka-client <dependency>

第十三章 SpringCloud之Gateway 路由

#######gateway  路由案例####### 1.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="

Linux查看网关(Gateway)方法

route -n ip route show traceroute www.baidu.com -s 100 [第一行就是自己的网关] netstat -r more /etc/network/interfaces [Debian/Ubuntu Linux] more /etc/sysconfig/network-scripts/ifcfg-eth0 [Red Hat Linux]

SpringCloud网关ZUUL集成consul

最近一直在搞基于springcloud的微服务开发,为了不限定微服务开发语言,服务发现决定采用consul不多说上代码 pom文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ht

springcloud 网关过滤器Zuul Filter

为什么需要网关过滤器? 微服务架构体系中,通常一个业务系统会有很多的微服务, 比如:OrderService.ProductService.UserService..., 为了让调用更简单,一般会在这些服务前端再封装一层, 类似下面这样: 前面这一层俗称为“网关层”,其存在意义在于,将"1对N"问题 转换成了"1对1”问题(路由), 同时在请求到达真正的微服务之前,可以做一些预处理(过滤), 比如:登录验证,日志打印... Filter 的生命周期 Filter 的生命周期有