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

系统管理员 2023-05-31 07:51 102阅读 0赞

一、从hystrix迁移

1.pom文件替换

  1. <!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-sentinel -->
  2. <dependency>
  3. <groupId>com.alibaba.cloud</groupId>
  4. <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
  5. <version>2.0.0.RELEASE</version>
  6. </dependency>

使用sentinel替换hystrix

2.注解替换

  1. @Bean
  2. @SentinelRestTemplate
  3. public RestTemplate getRestTemplate(){
  4. return new RestTemplate();
  5. }

使用@SentinelRestTemplate替换@@LoadBalanced

二、迁移hystrix-dashboard至sentinel-dashboard

1.下载sentinel-dashoard

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

建议下载源码包

20191024100610800.png

2.application.propertres

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

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

3.效果

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3B5Y2hhcm1fdQ_size_16_color_FFFFFF_t_70

三、项目地址

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

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

发表评论

表情:
评论列表 (有 0 条评论,102人围观)

还没有评论,来说两句吧...

相关阅读