「Sentinel」SpringBoot接入阿里巴巴流量哨兵

「Sentinel」SpringBoot接入阿里巴巴流量哨兵

項目地址:https://github.com/alibaba/Sentinel

dashboard jar包下載地址:https://github.com/alibaba/Sentinel/wiki/Dashboard

### 啟動dashboard

\tjava -jar sentinel-dashboard-1.6.3.jar

### 創建 SpringBoot 項目(2.0.6.RELEASE)

### SpringCloud (Finchley.RELEASE)

### 在pom.xml中配置依賴

刪除:

<dependency>
<groupid>org.springframework.cloud/<groupid>
<artifactid>spring-cloud-starter-netflix-hystrix/<artifactid>
/<dependency>
<dependency>
<groupid>org.springframework.cloud/<groupid>
<artifactid>spring-cloud-netflix-hystrix-stream/<artifactid>
/<dependency>
<dependency>
<groupid>com.netflix.hystrix/<groupid>
<artifactid>hystrix-javanica/<artifactid>
<version>1.5.12/<version>
/<dependency>

添加

<dependency>
<groupid>org.springframework.cloud/<groupid>
<artifactid>spring-cloud-starter-alibaba-sentinel/<artifactid>
<version>0.2.2.RELEASE/<version>
/<dependency>

### 在application.yml中配置

#### sentinel

spring:
cloud:
sentinel:
transport:
dashboard: localhost:8080
#### feign
feign:
httpclient:
enabled: false
okhttp:
enabled: true
hystrix:
enabled: false
sentinel:
enabled: true

### dashboard 賬號密碼(sentinel/sentinel)

### 請求APP後才能在dashboard中看到APP相關信息(9001、9005是兩個APP的端口)

http://localhost:9001/actuator/sentinel
http://localhost:9005/actuator/sentinel

### feign 報異常,可能是版本依賴問題

https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E

注意:json序列化 null 不再處理,直接返回給客戶端

### 一行代碼支持RestTemplate

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


分享到:


相關文章: