Skip to content

Latest commit

 

History

History
149 lines (90 loc) · 6.72 KB

config-server.md

File metadata and controls

149 lines (90 loc) · 6.72 KB

Config Serverの導入

次にConfig Serverを導入し、コンフィギュレーションの一元管理を

image

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

Config Serverの作成

作業手順

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

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

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

  3. src/main/resources/application.propertiesこの内容に変更

  4. GitHubのmetflix-configプロジェクトを自分のアカウントでFork image

  5. application.propertiesspring.cloud.config.server.git.uriの値をhttps://github.com/making/metflix-config.gitから自分のレポジトリに変更 image

動作確認

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

image

コンソールを確認

image

http://localhost:8888/envにアクセス

image

http://localhost:8888/membership/defaultにアクセス

image

http://localhost:8888/recommendations/defaultにアクセス

image

http://localhost:8888/ui/defaultにアクセス

image

Config Clientの設定

作業手順

Membership
  1. membershippom.xmlこの内容に変更
  2. membershipsrc/main/resources/application.properties削除
  3. membershipsrc/main/resourceを右クリック -> New -> File image
  4. File name: bootstrap.properties image
  5. src/main/resources/bootstrap.propertiesこの内容に変更
Recommendations
  1. recommendationspom.xmlこの内容に変更
  2. recommendationssrc/main/resources/application.properties削除
  3. recommendationssrc/main/resourceを右クリック -> New -> File
  4. File name: bootstrap.properties
  5. src/main/resources/bootstrap.propertiesこの内容に変更
UI
  1. uipom.xmlこの内容に変更
  2. uisrc/main/resources/application.properties削除
  3. uisrc/main/resourceを右クリック -> New -> File
  4. File name: bootstrap.properties
  5. src/main/resources/bootstrap.propertiesこの内容に変更
  6. src/main/java/com/metflix/UiApplication.javaこの内容に変更
  7. src/main/resources/templates/index.htmlこの内容に変更

動作確認

membershiprecommendationsuiを再起動

image

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

image

Forkしたmetflix-configプロジェクトのui.propertiesを編集

image

以下の内容を追加

message=It's A Beautiful Day

image

以下のコマンドを実行して、GitHub上のプロパティ変更をロード

$ curl -XPOST localhost:8080/refresh
["message"]

image

http://localhost:8080を再読み込みして変更が反映されていることを確認(アプリケーションの再起動は不要)。

image

以下のコマンドで一時的なプロパティ変更も可能

$ curl -XPOST localhost:8080/env -d message="Message is updated"
{"message":"Message is updated"}
$ curl -XPOST localhost:8080/refresh
[]

http://localhost:8080を再読み込みして変更が反映されていることを確認。

image