Gateway service current limiting fuse downgrade [Gateway+Sentinel]

Table of contents

Step 1: Start the sentinel-dashboard console

Step 2: Introduce sentinel dependency in gateway service

Step 3: Configure sentinel in gateway service application.yml

Step 4: Enter the service through the gateway and then enter the sentinel console to check the link status  


Step 1: Start the sentinel-dashboard console

java -jar 要启动的sentinel服务(是一个jar包,在jar包所在目录在cmd命令启动即可默认端口8080)

Step 2: Introduce sentinel dependency in gateway service

<!-- sentinel -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

<!-- sentinel gateway -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>

Step 3: Configure sentinel in gateway service application.yml

spring:
  application:
    name: zmall-gateway
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
    sentinel:
      transport:
        port: 9998 #跟控制台交流的端口,随意指定一个未使用的端口即可
        dashboard: localhost:8080 # 指定控制台服务的地址
      eager: true #当服务启动时是否与sentinel建立连接
      web-context-unify: false # 关闭URL PATH聚合

Step 4: Enter the service through the gateway and then enter the sentinel console to check the link status  

This is to directly perform operations such as gateway current limiting on the microservice. Click flow control directly, set QPS=1, flow control mode=direct (default), flow control effect=fast fail (default), etc., and finally quickly refresh the product service address to view the flow control effect. At the same time, the flow control effect of the flow control can also be configured as a queue waiting method. When the traffic is too large, the queue waiting method is used to slowly digest the requests, so as to achieve the purpose of traffic cutting.  

Guess you like

Origin blog.csdn.net/m0_63300795/article/details/128337712