bronze-gateway:基于 Spring Boot 的微服务网关项目

基于netty实现的轻量级、高性能网关

Branch2Tags6

logo

bronze-gateway v1.0.6

基于netty实现的轻量级、高性能网关!

Version Documentation License: APACHE-2.0 star

wushusong/bronze-gateway

开源许可

本项目是一个开源项目,使用 Apache-2.0 许可。有关许可的详细信息,请参阅 LICENSE 文件。

免责声明

Bronze-gateway是一个开源学习项目,与商业行为无关。用户在使用该项目时,应遵循法律法规,不得进行非法活动。如果Bronze-gateway发现用户有违法行为,将会配合相关机关进行调查并向政府部门举报。用户因非法行为造成的任何法律责任均由用户自行承担,如因用户使用造成第三方损害的,用户应当依法予以赔偿。使用Bronze-gateway所有相关资源均由用户自行承担风险.

源码

gitee

gitcode

1、项目集成 bronze-gateway

springboot版本要求:2.7.18及以上

1、引入依赖

        <dependency>
            <groupId>io.github.wushusong</groupId>
            <artifactId>bronze-gateway-core</artifactId>
            <version>1.0.6</version>
        </dependency>

2、增加yml配置

gateway:
  port: 9999
  backendResponseTimeoutMs: 6000 # 后端响应超时时间
  clientWriteTimeoutMs: 6000 # 客户端写入超时时间
  connectTimeoutMs: 6000 # 连接超时时间
  maxConnectionsPerHost: 2000 # 每个主机的最大并发连接数(如果没有配置,使用合理默认值)
  maxPendingAcquires: 20000 # 每个主机最大等待连接数(如果没有配置,使用合理默认值)
  routes:
    - id: wss-test-gw # 服务名称,每个服务唯一
      path: /wss-test-gw/ # 服务访问路径,注意,前后都要斜杠,不能有*号
      instances: # 服务实例
        - serviceId: wss-test-gw-1 # 服务实例名称,同一个服务下,不同实例,serviceId要求唯一
          url: http://192.168.1.239:8089 # 服务地址,到端口一层即可
          weight: 1 # 权重,目前系统默认轮询策略
#        - serviceId: wss-test-gw-2 # 模拟服务2 该服务百分百失败
#          url: http://192.168.1.111:8089
#          weight: 1
    - id: jm-cloud-gw
      path: /jm-cloud-gw/ # 注意,前后都要斜杠,不能有*号
      loadBalancerType: roundRobinLoadBalancer # 轮询策略
      instances:
        - serviceId: jm-cloud-gw-1 # 模拟服务2 该服务是正常服务
          url: http://192.168.1.240:23500
          weight: 1
        - serviceId: jm-cloud-gw-2 # 模拟服务2 该服务百分百失败
          url: http://192.168.1.111:23500
          weight: 1
          gray: true # 灰度发布实例 当满足灰度条件的请求,都会进入该服务,否则跳转到正常服务 如下面配置的是基于请求头的灰度,当请求头有wss,则进入该服务
      # 灰度发布配置
      grayReleaseConfig:
        enabled: true
        headerBased: # 基于请求头
          headerName: VERSION # 请求头名称
          headerValues: # 请求头值
            - "wss"

  filters:
#    - name: AuthFilter  # 与@Component("AuthFilter")匹配
#      order: -100
#    - name: RateLimitFilter  # 与@Component("RateLimitFilter")匹配
#      order: -90
#      args:
#        permitsPerSecond: "1000"

#熔断配置
  resilience:
    failureRateThreshold: 50 # 失败率阈值百分比
    slowCallRateThreshold: 50 # 慢调用率阈值百分比
    slowCallDurationThreshold: 10 # 慢调用持续时间阈值
    waitDurationInOpenState: 60 # 熔断器开启状态持续时间
    permittedNumberOfCallsInHalfOpenState: 5 # 半开状态允许的调用次数
    minimumNumberOfCalls: 2 # 计算失败率所需的最小调用次数
    slidingWindowSize: 5 # 滑动窗口大小

熔断

如果需要使用熔断,需要再启动类上增加注解:WssResilienceEnable.java

测试

img.png

img_1.png

自定义限流,继承接口Filter

img_2.png

启动

img_3.png

测试

请求地址:http://192.168.1.239:9999/jm-cloud-gw/admin/tenant/getTenantById/2?a=111

会根据yml配置。匹配:jm-cloud-gw 代理到实例:jm-cloud-gw,并代理到地址 http://192.168.1.240:23500,完整代理后地址: http://192.168.1.240:23500/admin/tenant/getTenantById/2?a=111

img_4.png

限流

img_5.png

img.png

有问题请issues或者添加本人qq:1193302291

Introduction

基于netty实现的轻量级、高性能网关

Customize your domain