当前位置:网站首页>Sentinel series integrates Nacos and realizes dynamic flow control

Sentinel series integrates Nacos and realizes dynamic flow control

2022-06-13 05:40:00 codain

From the flow control in the previous chapter , You can actually see ,Sentinel It is essential to focus only on the definition of resources , It will control the flow of resources , In the last chapter we based on Sentinel Dashboard The console controls the flow of resources , But I don't know if you have found a problem in the process of actual operation , When the service restarts , When I looked back at the console, I found : All the flow control rules have disappeared , In fact, this is because the relevant data is stored in memory , Once the application restarts , The data will be clear , So in order to solve this problem ,Sentinel Dedicated dynamic data source support


at present ,Sentinel Support the expansion of multiple data sources :Consul、ZK wait , Let's focus on integration Nacos Implement dynamic flow control rules , Steps are as follows :

1、 add to Nacos Dependence of data source

<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-datasource-nacos</artifactId>
    <version>1.7.0</version>
</dependency>

2、 Add configuration file

spring:
  application:
    name: sentinel-server
  cloud:
    sentinel:
      transport:
        dashboard: 127.0.0.1:8080
      datasource: # Support redis、zk Such as middleware , Which one to use , Below - key Just follow the one 
        - nacos:
            server-addr: 127.0.0.1:8848
            data-id: ${spring.application.name}-nacos
            group-id: DEFAULT_GROUP
            data-type: json
            rule-type: flow

3、 Define an interface

@RestController
public class DashController {
    @GetMapping("/dash")
    public String dash(){
        return "dash";
    }
}

4、 Get into Nacos Console , Add configuration file

5、 Start project , see Sentinel Dashboard Flow control rule list

  This resource name , When the service starts , load nacos The resources just configured , And then call /dynamic Interface , Current limiting will occur json, as follows :

  thus , The dynamic current limiting rule is completed

原网站

版权声明
本文为[codain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280508406758.html