从springcloud netflix迁移到springcloud alibaba(二)使用sentinel代替hystrix

一、从hystrix迁移

1.pom文件替换

  <!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-sentinel -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>

使用sentinel替换hystrix

2.注解替换

@Bean
    @SentinelRestTemplate
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

使用@SentinelRestTemplate替换@@LoadBalanced

二、迁移hystrix-dashboard至sentinel-dashboard

1.下载sentinel-dashoard

https://github.com/alibaba/Sentinel/releases

建议下载源码包

2.application.propertres

spring.cloud.sentinel.transport.dashboard=localhost:7001

在consumer中添加,这样dashboard就可以自动识别了。

3.效果

三、项目地址

我的项目地址:https://github.com/sustly/blog_vue_server/tree/springcloud_alibaba

注意是springcloud_alibaba分支,springcloud_netflix是已经完善的

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章