|
| 1 | +## Circuit Breakerの導入 |
| 2 | + |
| 3 | +次にCircuit Breakerの導入して、障害の伝播を防ぎます。 |
| 4 | + |
| 5 | + |
| 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 | + |
| 30 | + |
| 31 | +[http://localhost:8080](http://localhost:8080)にアクセス |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +次に`membership`サービスを停止。 |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +再度、[http://localhost:8080](http://localhost:8080)にアクセスし、Recommendationsの結果が変わっていることを確認。 |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +`membership`サービスを起動。 |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +しばらくして[http://localhost:8080](http://localhost:8080)にアクセスすると復旧していることを確認 |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +同様に`recommendations`サービスを停止させると、Recommendationsの結果が空になっていることを確認。 |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +動作を確認したら`recommendations`サービスを起動。 |
| 56 | + |
| 57 | +[http://localhost:3333/hystrix.stream](http://localhost:3333/hystrix.stream)にアクセス。メトリクスのイベントストリームが流れてくることを確認。 |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +### Circuit Breaker Dashboardの作成 |
| 63 | + |
| 64 | + |
| 65 | +#### 作業手順 |
| 66 | + |
| 67 | +1. File -> New -> Spring Starter Project |
| 68 | + |
| 69 | + |
| 70 | +1. * Name : `hystrix-dashboard` |
| 71 | + * Group: `com.metflix` |
| 72 | + * Artifact: `hystrix-dashboard` |
| 73 | + * Package: `com.metflix` |
| 74 | + |
| 75 | + |
| 76 | +1. * Cloud Circuit Breaker -> `Hystrix Dashboard` |
| 77 | + * Cloud Config -> `Config Client` |
| 78 | + * Ops -> `Actuator` |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +1. workspaceを確認 |
| 83 | + |
| 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 | + |
| 96 | + |
| 97 | + |
| 98 | +コンソールを確認 |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +[http://localhost:7979/hystrix](http://localhost:7979/hystrix)にアクセス |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +`http://localhost:3333/hystrix.stream`を入力してMonitor Streamをクリック。 |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +`http://localhost:4444/hystrix.stream`も同様 |
0 commit comments