Skip to content

Commit 435ccba

Browse files
committed
Create circuit-breaker.md
1 parent 5179137 commit 435ccba

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

circuit-breaker.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
## Circuit Breakerの導入
2+
3+
次にCircuit Breakerの導入して、障害の伝播を防ぎます。
4+
5+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/d7b3f0be-64e0-8a03-d83b-09c8102236bb.png)
6+
7+
本ページで作成するソースコードは[こちら](https://github.com/making/metflix/tree/04-circuit-breaker)(`04-circuit-breaker`ブランチ)から参照可能です。
8+
9+
10+
### Hystrix Commandの作成
11+
12+
#### 作業手順
13+
14+
#### Recommendations
15+
16+
1. `recommendations``pom.xml`[この内容](https://github.com/making/metflix/blob/04-circuit-breaker/recommendations/pom.xml)に変更
17+
1. `recommendations``src/main/java/com/metflix/RecommendationsApplication.java`[この内容](https://github.com/making/metflix/blob/04-circuit-breaker/recommendations/src/main/java/com/metflix/RecommendationsApplication.java)に変更
18+
19+
20+
#### UI
21+
22+
1. `ui``pom.xml`[この内容](https://github.com/making/metflix/blob/04-circuit-breaker/ui/pom.xml)に変更
23+
1. `ui``src/main/java/com/metflix/UiApplication.java`[この内容](https://github.com/making/metflix/blob/04-circuit-breaker/ui/src/main/java/com/metflix/UiApplication.java)に変更
24+
25+
#### 動作確認
26+
27+
`recommendations``ui`を再起動。
28+
29+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/7a12e579-0f53-139a-6ce4-065ecdc697e4.png)
30+
31+
[http://localhost:8080](http://localhost:8080)にアクセス
32+
33+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/8e1eba55-739c-4f24-bbe5-4d8490af424b.png)
34+
35+
次に`membership`サービスを停止。
36+
37+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/0a62766f-fb90-b660-3a9b-3850030a1608.png)
38+
39+
再度、[http://localhost:8080](http://localhost:8080)にアクセスし、Recommendationsの結果が変わっていることを確認。
40+
41+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/0b9c18b3-9c75-6a42-5c13-701f8cb90b57.png)
42+
43+
`membership`サービスを起動。
44+
45+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/3d04f3bd-420e-67b5-5824-3bc32311c98f.png)
46+
47+
しばらくして[http://localhost:8080](http://localhost:8080)にアクセスすると復旧していることを確認
48+
49+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/dde8de71-12b9-7d14-c30a-ef66c01c9008.png)
50+
51+
同様に`recommendations`サービスを停止させると、Recommendationsの結果が空になっていることを確認。
52+
53+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/fb5ad815-df20-5827-ce80-4168f8f46324.png)
54+
55+
動作を確認したら`recommendations`サービスを起動。
56+
57+
[http://localhost:3333/hystrix.stream](http://localhost:3333/hystrix.stream)にアクセス。メトリクスのイベントストリームが流れてくることを確認。
58+
59+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/971293f3-c060-ba6e-eb84-ed0aad9692be.png)
60+
61+
62+
### Circuit Breaker Dashboardの作成
63+
64+
65+
#### 作業手順
66+
67+
1. File -> New -> Spring Starter Project
68+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/642499a3-0f6f-8e3d-6f65-499808937abf.png)
69+
70+
1. * Name : `hystrix-dashboard`
71+
* Group: `com.metflix`
72+
* Artifact: `hystrix-dashboard`
73+
* Package: `com.metflix`
74+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/2311a692-5d1d-02f1-da5d-7566802822b2.png)
75+
76+
1. * Cloud Circuit Breaker -> `Hystrix Dashboard`
77+
* Cloud Config -> `Config Client`
78+
* Ops -> `Actuator`
79+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/8c774962-d0cc-3e53-a204-ecc6f3018b57.png)
80+
81+
82+
1. workspaceを確認
83+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/e68451c3-ffe0-3f84-d6cd-6166e0d2c1ec.png)
84+
85+
1. `src/main/java/com/metflix/HystrixDashboardApplication.java`[この内容](https://github.com/making/metflix/blob/04-circuit-breaker/hystrix-dashboard/src/main/java/com/metflix/HystrixDashboardApplication.java)に変更
86+
1. `src/main/resources/application.properties`**削除**
87+
1. `src/main/resources`を右クリック -> New -> File
88+
1. File name: `bootstrap.properties`
89+
1. `src/main/resources/bootstrap.properties`[この内容](https://github.com/making/metflix/blob/04-circuit-breaker/hystrix-dashboard/src/main/resources/bootstrap.properties)に変更
90+
91+
#### 動作確認
92+
93+
Package Explorerの`HystrixDashboardApplication.java`を右クリック -> Run As -> Spring Boot App
94+
95+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/e324f409-ee24-7d5f-710f-4bcb114a69b9.png)
96+
97+
98+
コンソールを確認
99+
100+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/617b4f3f-2806-2445-3aeb-0a66e7cb95ee.png)
101+
102+
103+
[http://localhost:7979/hystrix](http://localhost:7979/hystrix)にアクセス
104+
105+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/2e2b16b3-273a-2b1d-fbaa-359a878b582c.png)
106+
107+
`http://localhost:3333/hystrix.stream`を入力してMonitor Streamをクリック。
108+
109+
![image](https://qiita-image-store.s3.amazonaws.com/0/1852/bbf99ff3-76a9-e9d4-b96b-0c2395619014.png)
110+
111+
`http://localhost:4444/hystrix.stream`も同様

0 commit comments

Comments
 (0)