Skip to content

Quick Start

This chapter will demonstrate how to use the out-of-the-box Sentinel current limiting and downgrading capabilities provided by Spring Cloud Alibaba to provide high-availability protection for Spring Cloud applications.

Access Sentinel

Introduce the starter dependency whose group ID is com.alibaba.cloud and artifact ID is spring-cloud-starter-alibaba-sentinel in the pom.xml file:

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

The following example is the simplest example of using Sentinel:

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
}
}
@RestController
public class TestController {
@GetMapping(value = "/hello")
@SentinelResource("hello")
public String hello() {
return "Hello Sentinel";
}
}

The @SentinelResource annotation is used to identify whether the resource is limited or downgraded. The attribute hello of the annotation in the above example represents the resource name. @SentinelResource also provides other additional attributes such as blockHandler, blockHandlerClass, and fallback to represent current limiting or downgrading operations. For more information, please refer to Sentinel Annotation Support.

收藏
收藏暂无数据,请从小助手对话框添加
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
专家智能答疑

loading...

当前服务输出的内容均由人工智能模型生成,其生成内容的准确性和完整性无法保证,不代表我们的态度或观点。
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
账号:CNPilot
专家答疑