In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to achieve SpringCloudAlibaba Sentinel current restriction and downgrade, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
I haven't updated for about half a month, and I'm really struggling with some SpringCloudAlibaba usage scenarios. At the same time, based on the current business and staffing, we even want to give up the solution of micro-service.
The current limit and downgrade of Sentinel is an essential scenario, which is actually based on the current business consideration of whether Sentinel is needed.
But in the end, it must be the scene of Sentinel, so let's put it in place directly.
The basic concept and usage scenario of Setinel
Setinel is described as "a highly available flow control and protection component". Flow control and flow protection can see that the significance of this component is to ensure the stability of micro-services. The meaning of Sentinel is the same as that of Hystrix in the original SpringCloud family.
In fact, there are many scenarios that can implement this scenario, such as the one mentioned at the beginning that you did not intend to use Sentinel because of business reasons. The other is some of our own problems to consider using some simpler solutions to implement. Such as "nginx" and so on.
Of course, compared with nginx, Sentinel can achieve better functionality and flexibility. Sentinel has more features, so I will slowly start to introduce the use of Sentinel. First of all, we use Sentinel to implement a current-limiting function. Of course, first of all, we need a Sentinel environment.
Deploy Sentinel Dashboard
Sentinel is divided into two parts, sentinel-core and sentinel-dashboard.
The sentinel-core part can support the local introduction of sentinel-core for the integration and configuration of current-limiting rules.
On the other hand, sentinel-dashboard can support the maintenance and adjustment of online flow control rules and circuit breaker rules on core.
Back to the point, let's deploy a Sentinel Dashboard first.
Project address: https://github.com/alibaba/Sentinel download address: https://github.com/alibaba/Sentinel/releases
This time we chose the current latest version v1.7.2 for deployment. Sentinel uses SpringBoot for development, so download the jar package directly and start it. Java-jar sentinel-dashboard-1.7.2.jar
Because Sentinel-Dashboard is developed using SpringBoot, there are not many configuration files of its own. The default port is 8080. If there is a port conflict, you can use "--server.port" to modify the binding. After the startup is successful, you can use the browser to see the following page:
Access method: "sentinel" / "sentinel"
"WARN:" if you need to adjust the relevant parameters, you can refer to the specific configuration file in github to modify it. The configuration is as follows:
# spring settings
Spring.http.encoding.force=true
Spring.http.encoding.charset=UTF-8
Spring.http.encoding.enabled=true
# cookie name setting
Server.servlet.session.cookie.name=sentinel_dashboard_cookie
# logging settings
Logging.level.org.springframework.web=INFO
Logging.file=$ {user.home} / logs/csp/sentinel-dashboard.log
Logging.pattern.file=% d {yyyy-MM-dd HH:mm:ss} [% thread]%-5level% logger {36} -% msg%n
# logging.pattern.console=% d {yyyy-MM-dd HH:mm:ss} [% thread]%-5level% logger {36} -% msg%n
# auth settings
Auth.filter.exclude-urls=/,/auth/login,/auth/logout,/registry/machine,/version
Auth.filter.exclude-url-suffixes=htm,html,js,css,map,ico,ttf,woff,png
# If auth.enabled=false, Sentinel console disable login
Auth.username=sentinel
Auth.password=sentinel
# Inject the dashboard version. It's required to enable
# filtering in pom.xml for this resource file.
Sentinel.dashboard.version=$ {project.version}
Project integration begins with the introduction of related dependencies and the introduction of "spring-cloud-starter-alibaba-sentinel" module.
["groupId" reminds me again that com.alibaba.cloud is the graduation version.)
Com.alibaba.cloud
Spring-cloud-starter-alibaba-sentinel
Org.springframework.boot
Spring-boot-starter-test
Test
Org.springframework.boot
Spring-boot-starter-web
Then we can add the relevant configuration spring.cloud.sentinel.transport.dashboard=localhost:8080 of sentinel-dashboard in the project
Create startup class and add Rest access interface
"SentinelFlowControlApplication.java" @ SpringBootApplication
Public class SentinelFlowControlApplication {
Public static void main (String [] args) {
SpringApplication.run (SentinelFlowControlApplication.class,args)
}
}
"SentinelTestController.java"
@ RestController
@ RequestMapping (value = "sentinel")
Public class SentinelTestController {
@ RequestMapping (value = "hello", method = RequestMethod.GET)
Public String hello () {
Return "CainGao"
}
}
If you visit the REST API and open the Sentinel-dashboard page, you can see that every time we visit it, it will be displayed in Dashboard, and our service has been registered with sentinel.
Add flow control rules
Now we can directly find the port we visit in the cluster link on the left to set the flow control rules. Now add a rule for QPS=1, and others use the default
After the configuration is completed, our current stream restriction effect should be that only one request can be sent successfully per second. Other requests will fail directly.
Direct Quick access Interface for testing
Currently, it can be found that when the QPS of the request is greater than 1, that is, the number of times sent per second is greater than 1, it will directly return "Blocked by Sentinel".
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.