Skip to content

Latest commit

 

History

History
121 lines (69 loc) · 5.63 KB

File metadata and controls

121 lines (69 loc) · 5.63 KB

Service Registryの導入

これまで各サービスのREST APIにアクセスするために物理的なURL(ホスト名 + ポート番号)を直接記述していましたが、サービスをService Registryに登録させることにより、論理的なURL(サービスID)でサービスにアクセスできるようにします。

image

本ページで作成するソースコードはこちら(03-service-registryブランチ)から参照可能です。

Eureka Serverの作成

作業手順

  1. File -> New -> Spring Starter Project image

    • Name : eureka-server
  • Group: com.metflix
  • Artifact: eureka-server
  • Package: com.metflix image
    • Cloud Config -> Config Client
  • Cloud Discovery -> Eureka Server
  • Ops -> Actuator image
  1. workspaceを確認 image

  2. src/main/java/com/metflix/EurekaServerApplication.javaこの内容に変更

  3. src/main/resources/application.properties削除

  4. src/main/resourcesを右クリック -> New -> File

  5. File name: bootstrap.properties

  6. src/main/resources/bootstrap.propertiesこの内容に変更

動作確認

Package ExplorerのEurekaServerApplication.javaを右クリック -> Run As -> Spring Boot App

image

コンソールを確認

image

http://localhost:8761にアクセス

image

Eureka Clientの設定

作業手順

Membership
  1. membershippom.xmlこの内容に変更
  2. membershipsrc/main/resources/bootstrap.propertiesこの内容に変更
  3. membershipsrc/main/java/com/metflix/MembershipApplication.javaこの内容に変更
Recommendations
  1. recommendationspom.xmlこの内容に変更
  2. recommendationssrc/main/resources/bootstrap.propertiesこの内容に変更
  3. recommendationssrc/main/java/com/metflix/RecommendationsApplication.javaこの内容に変更
UI
  1. uipom.xmlこの内容に変更
  2. uisrc/main/resources/bootstrap.propertiesこの内容に変更
  3. uisrc/main/java/com/metflix/UiApplication.javaこの内容に変更

動作確認

membershiprecommendationsuiを再起動

image

http://localhost:8761にアクセス

image

http://localhost:8080にアクセス

image

Config Serverに設定した各サービスのURLが物理名(ホスト名+ポート番号)ではなく論理名になっていることに着目してください。

Membershipサービスのスケールアウト

Membershipサービスを3台にスケールアウトさせましょう。

image

$ cd $WORKSHOP/membership
$ ./mvnw clean package
$ PORT=4445 java -jar target/membership-0.0.1-SNAPSHOT.jar

別ターミナルでも

$ cd $WORKSHOP/membership
$ PORT=4446 java -jar target/membership-0.0.1-SNAPSHOT.jar

http://localhost:8761にアクセス

image

http://localhost:8080に何度かアクセスして、各Membershipサービスのログを見てそれぞれにアクセスがあることを確認してください。