官术网_书友最值得收藏!

Service registration and discovery

Why is service registration and discovery important? So far, we have been calling the service through its URL, which includes the IP address—for example, http://localhost:8080/prodthus we expect the service to run at that address. Even though we might substitute the test and the production URLs, the step of calling the service at a particular IP address and port is still static.

However, in a cloud environment, things are quite dynamic. If the service goes down at a given IP, it can come up in a different IP address as it comes up on some container. Although we can mitigate that with virtual IPs and reverse proxies, it would be better to look up a service dynamically at the time of the service call and then call the service at the IP address. The lookup addresses can be cached in the client, so that the dynamic lookup need not be performed for each service call.

A registry (referred to as a service registry) helps in this case. When the service boots up, it registers itself in a registry. There is also a heartbeat between registry and service to ensure that the registry keeps only live services in its registry. If the heartbeat stops, the registry deregisters that instance of the service.

For this quick starter, we are going to use Spring Cloud Netflix, which nicely integrates with Spring Boot. We need three components now:

  • Product service: We have already written this
  • Service registry: We are going to use Eureka, which is part of Spring Cloud
  • Service client: Instead of calling our service directly through a browser, we will write a simple client to our service
主站蜘蛛池模板: 新干县| 杭锦旗| 新宁县| 安塞县| 申扎县| 澜沧| 临湘市| 公安县| 辽宁省| 天等县| 鲜城| 嘉黎县| 荔浦县| 连平县| 承德县| 梨树县| 黄大仙区| 奉化市| 政和县| 南充市| 衡东县| 旅游| 尼玛县| 兴化市| 雷州市| 寻乌县| 安仁县| 梧州市| 通许县| 彩票| 日喀则市| 阿巴嘎旗| 曲沃县| 陈巴尔虎旗| 宜兴市| 娄烦县| 怀安县| 雷波县| 宜阳县| 永登县| 波密县|