alibaba-sentinel实现

Sentinel 是什么?

随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。

sentinel替代了netfix的histrx的服务降级、服务熔断、服务降级。

sentinel下载地址https://github.com/alibaba/Sentinel/releases

sentinel-dashboard下载jar包启动就可以访问

启动命令:java -jar sentinel-dashboard-1.8.3.jar

访问:127.0.0.1:8080可以看到sentinel界面

alibaba-sentinel实现


 sentinel客户端配置

pom配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>spring-cloud-demo</artifactId>
        <groupId>com.xx.job</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>cloudAlibaba-sentinel5001</artifactId>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

application.yml文件

server:
  port: 5001
spring:
  application:
    name: cloudAlibaba-sentinel
  cloud:
    sentinel:
      transport:
        dashboard: 127.0.0.1:8080
    nacos:
      discovery:
        server-addr: 127.0.0.1:3333

主启动类:

package com.xx.job.cloudalibabasentinel;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@EnableDiscoveryClient
@SpringBootApplication
public class CloudAlibabaSentinelApplication {

    public static void main(String[] args) {
        SpringApplication.run(CloudAlibabaSentinelApplication.class, args);
    }

}

sentinel是懒加载的,要访问sentinel的客户端后才会被监控到

alibaba-sentinel实现

 

上一篇:SSM框架:拿来建个网站吧


下一篇:FATAL: License file expired:金仓数据库过期了...