從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是已經完善的

 

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