In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use Nacos to achieve external dynamic data sources in Sentinel-Go. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
1. Sentinel
With the popularity of microservices, the stability between services and services is becoming more and more important. Taking the flow as the starting point, Sentinel protects the stability of the service from many dimensions, such as flow control, circuit breaker degradation, system load protection and so on.
Sentinel has the following characteristics:
Rich application scenarios: Sentinel takes on the core scenarios of Alibaba's Singles Day traffic promotion in the past 10 years, such as second kill (that is, burst traffic control within the system capacity), message peak cutting and valley filling, cluster flow control, real-time fuse downstream unavailable applications, and so on.
Complete real-time monitoring: Sentinel also provides real-time monitoring function. You can see the second-rate data of a single machine connected to the application in the console, and even the summary operation of less than 500 clusters.
Broad open source ecology: Sentinel provides out-of-the-box integration modules with other open source frameworks / libraries, such as Spring Cloud, Dubbo, and gRPC. You only need to introduce the appropriate dependencies and make a simple configuration to quickly access Sentinel.
Perfect SPI extension point: Sentinel provides easy-to-use and perfect SPI extension interface. You can quickly customize the logic by implementing an extension interface. Such as customized rule management, adapting to dynamic data sources, and so on.
1.1 History of Sentinel
In 2012, Sentinel was born, and its main function is ingress flow control.
From 2013 to 2017, Sentinel developed rapidly within Alibaba Group and became a basic technology module, covering all the core scenes. As a result, Sentinel has accumulated a large number of traffic consolidation scenarios and production practices.
In 2018, Sentinel is open source and continues to evolve.
In 2019, Sentinel gradually explored the direction of multilingual expansion, and successively launched the native version of C++ and Envoy cluster flow control support.
2. Nacos
Nacos is a platform for dynamic service discovery, configuration management and service management that is easier to build cloud native applications. Nacos is an open source implementation of Nacos, which is born out of Alibaba's internal ConfigServer and Diamond. Having experienced the test of the peak flow of Singles' Day and the super-large-scale capacity of Alibaba's economy, Alibaba's soft-load team has ten years of experience in this field, and has a good guarantee in terms of stability and functionality.
(Sentinel-Go integrates Nacos dynamic data source architecture)
At present, current limiting, circuit breaker and other strategies in Sentinel are based on rules. The purpose of providing dynamic data source extension is to dynamically update rule data through some configuration center middleware (such as nacos,etcd,conful, etc.).
3. Sentinel-Go current limiting Demo
When nacos is not integrated, the rules are defined inside the code and no external data sources are used.
3.1 installation
Go get http://github.com/alibaba/sentinel-golang
3.2 sample Demo
Using Sentinel is mainly divided into the following steps:
Configure and initialize Sentinel
Burying points (defining resources)
Configuration Rul
Package mainimport ("fmt"log"math/rand"time" sentinel "github.com/alibaba/sentinel-golang/api"github.com/alibaba/sentinel-golang/core/base"github.com/alibaba/sentinel-golang/core/flow"github.com/alibaba/sentinel-golang/util") func main () {/ / We should initialize Sentinel first. Err: = sentinel.InitDefault () if err! = nil {log.Fatalf ("Unexpected error:% + v", err)} _, err = flow.LoadRules ([] * flow.FlowRule {{Resource: "some-test", MetricType: flow.QPS, Count: 10, ControlBehavior: flow.Reject,} }) if err! = nil {log.Fatalf ("Unexpected error:% + v", err) return} ch: = make (chan struct {}) for I: = 0 I < 10; for + {go func () {for {e, b: = sentinel.Entry ("some-test", sentinel.WithTrafficType (base.Inbound)) if b! = nil {/ / Blocked. We could get the block reason from the BlockError. Time.Sleep (time.Duration (rand.Uint64 ()) * time.Millisecond)} else {/ / Passed, wrap the logic here. Fmt.Println (util.CurrentTimeMillis (), "passed") time.Sleep (time.Duration (rand.Uint64 ()) * time.Millisecond) / / Be sure the entry is exited finally. E.Exit ()} 400
Summary
To use nacos as an external dynamic data source in sentinel-go, you only need to change the part that originally declared Rule and loaded Rule to read from the nacos data source.
In this paper, we only introduce the integration of flow control, circuit breaker, warmup, and the integration of hot spot parameters, as long as you modify the configuration as needed.
Key code:
H: = datasource.NewFlowRulesHandler (datasource.FlowRulesJsonConverter) nds, err: = nacos.NewNacosDataSource (client, "sentinel-go", "flow", h) if err! = nil {fmt.Printf ("Fail to create nacos datasource client, err:% + v", err) return} err = nds.Initialize () if err! = nil {fmt.Printf ("Fail to initialize nacos datasource client, err:% + v" Err) return} above is how to use Nacos to implement external dynamic data sources in Sentinel-Go. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.