Spring Boot + Netflix Eureka
-
Upload
- -
Category
Technology
-
view
13.930 -
download
3
Transcript of Spring Boot + Netflix Eureka
eureka : サービスディスカバリribbon : ロードバランシング Hystrix : サーキットブレイカー govenator : Google Guice拡張feign : 宣言的HTTPクライアント vector : リソース監視&可視化
SimianArmy : AWSのサーバを落とす …
eureka : サービスディスカバリribbon : ロードバランシング Hystrix : サーキットブレイカー govenator : Google Guice拡張feign : 宣言的HTTPクライアント vector : リソース監視&可視化
SimianArmy : AWSのサーバを落とす …
内部DNSの場合Web/AP
Service
内部DNS
1. 事前にIPを登録hoge1.internal = 192.168.0.1
2. 呼び出し時に参照
3. 呼び出しhttp://hoge1.internal:8081/hoge
Eurekaの場合Web/AP
Service
Eureka
1. サービス起動時にIPとPortを登録
hoge-service = 192.168.0.1:8081
2. 呼び出し時に参照getNextServerFromEureka(“hoge-service”)
3. 呼び出しhttp://2の戻り値/hoge
Ribbonを使った場合Web/AP
Service
Eureka
1. サービス起動時にIPとPortを登録
hoge-service = 192.168.0.1:8081
2. Ribbonが参照3. 呼び出し
http://hoge-service/hoge
4. Ribbonが変換http://192.168.0.1:8081/hoge
ServiceService
複数台もOKWeb/AP
Service
Eureka1. サービス起動時にIPとPortを登録
hoge-service = 192.168.0.1:8081 hoge-service = 192.168.0.2:8081 hoge-service = 192.168.0.3:8082
2. Ribbonが参照3. 呼び出し
http://hoge-service/hoge
4. Ribbonが変換http://192.168.0.2:8082/hoge変換後のアドレスは アクセスごとに変わる
@SpringBootApplication @EnableEurekaServer public class OreNoEureka { public static void main(String[] args) { SpringApplication.run(OreNoEureka.class, args); } }
OreNoEureka.java
server.port: 8781
eureka: client: registerWithEureka: false fetchRegistry: false server: waitTimeInMsWhenSyncEmpty: 0
application.yml
@SpringBootApplication @EnableEurekaClient public class OreNoService { public static void main(String[] args) { SpringApplication.run(OreNoService.class, args); } }
OreNoService.java
spring.application.name: ore-no-service
server.port: 8081
eureka: client: serviceUrl.defaultZone: http://localhost:8761/eureka instance: hostname: localhost
application.yml
@SpringBootApplication @EnableEurekaClient public class OreNoWeb { public static void main(String[] args) { SpringApplication.run(OreNoWeb.class, args); } }
OreNoWeb.java
public class OreNoWeb { @Autowired RestTemplate restTemplate;
// application.ymlに入れるほうがオススメ String url = "http://ore-no-service/hoge"; public Hoge call() { restTemplate.getForEntity(url, Hoge.class); } }
OreNoWeb.java
spring.application.name: ore-no-web
server.port: 8082
eureka: client: serviceUrl.defaultZone: http://localhost:8761/eureka instance: hostname: localhost
application.yml