前提是你已經有了註冊中心,然後搭建一個基礎spring cloud 服務,並配置註冊服務等等前提環境搭建
接下來描述的服務提供者和服務調用者的配置都是一樣的,來自《spring cloud 與docker微服務架構實戰》的讀後的個人總結.
pom文件中需要引入spring-cloud-starter-hystrix/spring-cloud-starter-hystrix-dashboard/spring-cloud-netflix-hystrix-stream/spring-cloud-starter-turbine-stream/spring-cloud-starter-stream-rabbit
如下
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId></dependency><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId></dependency><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-hystrix-stream</artifactId></dependency><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine-stream</artifactId></dependency><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId></dependency>
啟動類需要添加如下註解
/*turibine監控*/@EnableTurbineStream@EnableCircuitBreaker/*Dashboard監控*/@EnableHystrixDashboard
接下來的操作才是關鍵
1,將註冊中心服務提供者服務調用者都啟動
2.訪問服務提供者ip:port/hystrix 如圖
3. 圖中總共有三個文本框,其中第一個文本框是必填的,填寫的是服務調用者的ip:port/hystrix.stream,然後點擊Monitor Stream.
4. 注意,如果第一個文本框填寫的不正確會展示如下內容
5. 訪問服務調用者,當然,該服務調用者提供的接口需要調用服務提供者提供的接口的
6.這時候就能看到如下內容,就證明你成功了
訪問hystrix.stream
訪問該連接時,想要出現如下的情況
這個就要訪問服務提供者的ip:port/hystrix.stream
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。