1.創建microservice-student-provider-hystrix-1005項目
2.加入依賴
<dependencies>
<dependency>
<groupId>com.java1234.springcloud</groupId>
<artifactId>microservice-common</artifactId>
<version>${project.version}</version>
</dependency>
<!-- actuator監控引入 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<!-- 修改後立即生效,熱部署 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
3.application.yml
server:
port: 1005
context-path: /
# 數據源配置
spring:
application:
name: microservice-student
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/db_springcloud
username: root
password: 123456
jpa:
hibernate:
ddl-auto: update
show-sql: true
eureka:
instance:
hostname: localhost #eureka客戶端主機實例名稱
appname: microservice-student #客戶端服務名
instance-id: microservice-student-hystrix:1005 #客戶端實例名稱
prefer-ip-address: true #顯示IP
client:
service-url:
# 單機 defaultZone: http://localhost:2001/eureka #把服務註冊到eureka註冊中心
defaultZone: http://eureka2001.java1234.com:2001/eureka/,http://eureka2002.java1234.com:2002/eureka/,http://eureka2003.java1234.com:2003/eureka/ # 集羣
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 3000
info:
groupId: $project.groupId$
artifactId: $project.artifactId$
version: $project.version$
負責人: 張三
聯繫電話: 110
4.拷貝microservice-student-provider-hystrix-1004代碼
5.新建microservice-student-consumer-hystrix-turbine-91項目並加入依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
6.application.yml
server:
port: 91
context-path: /
eureka:
client:
service-url:
defaultZone: http://eureka2001.java1234.com:2001/eureka/,http://eureka2002.java1234.com:2002/eureka/,http://eureka2003.java1234.com:2003/eureka/
turbine:
app-config: microservice-student # 指定要監控的應用名稱
clusterNameExpression: "'default'" #表示集羣的名字爲default
spring:
application:
name: turbine
7.啓動類StudentConsumerTurbineApplication_91
package com.java1234;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
@EnableTurbine
public class StudentConsumerTurbineApplication_91 {
public static void main(String[] args) {
SpringApplication.run(StudentConsumerTurbineApplication_91.class, args);
}
}
8.啓動三個eureka,兩個provider,一個consumer,一個turbine
9.監控地址http://localhost:91/turbine.stream