2.4.2 Service Boot: Configuration Management micro services

(Step 2 in Figure 2-6) guide service occurs when the service first start micro and need to load their application configuration information. Figure 2-8 provide more context for the boot process.
Any application developers know that it is sometimes necessary to make the runtime behavior of an application can be configured. Typically this involves the deployment of the application attribute file read configuration data of the application, or read data from the data store (e.g., relational databases).
Micro services often encounter the same type of configuration requirements. The difference is that, micro-service applications running on the cloud, you may run hundreds or even thousands of micro service instance. To further complicate matters, these services may be scattered around the world. Due to the large number of geographically dispersed services, redeploy Services to obtain the new configuration data it becomes difficult to implement.
The data stored in an external server data storage solution to this problem, but on the micro-service cloud presents a unique set of challenges.
(1) the structure of configuration data tend to be simple, but generally is not frequently written frequently read. In this case, use a relational database is "overkill" because the relational database designed to manage than a simple set of keys more complex data model right.
(2) Because the data is accessed on a regular basis, but rarely change, so the data must have low latency readability.
(3) must be highly available data storage, and data services close to the reader. Configuration data is stored can not be completely closed, otherwise it will become the single point of failure of the application.
In Chapter 3, we describe how to use simple tools like key-value data store to manage micro-service application configuration data.
2.4.3 Service registration and discovery: how clients communicate with the micro-Services
From the micro-service consumer's perspective, micro-location services should be transparent, because in a cloud-based environment, the server is short. Short means that the server hosting the service is usually shorter than the service life of running corporate data centers. You can quickly start and dismantle cloud-based services through a new IP address assigned to the server running the service.
By sticking to the brief service as an object can be freely handled, micro-services architecture can achieve a high degree of scalability and availability by running multiple service instances. Service demand and elasticity can be managed as soon as possible in case of need. Each service has assigned to it a unique and non-permanent IP address. The disadvantage is the short service, with the appearance and disappearance services, manual or manual management services likely to cause a large number of short outages.
Examples of micro-services requires a proxy registration to a third party. This registration process is called discovery service (step 3 in Figure 2-6, and 2-9 in more information on this process). When the micro-service instances using the service discovery agent registration, micro discovery agent service instance will tell two things: service instance physical IP address or domain name address, and the application can be used to find the logical name of the service. Some services agency also found that access to the requested URL registration services, service discovery agent can use this URL to perform health checks.
Then, the client and service discovery agent to communicate to find the location services.
2.4.4 convey micro-services "health"
Service discovery agent not only plays the role of a traffic policeman to guide the client to the service location. In the micro-cloud-based service applications usually have multiple instances running the service, some service instances, sooner or later there will be some problems. Service discovery agent monitors the health of each service instance which it is registered, and remove service instance in question from its routing table to ensure that clients do not access the service instance failure has occurred.
After the discovery of micro-services, service discovery agency will continue to monitor the health check and ping interfaces to ensure that the service is available. This is step 4 in Figure 2-6. Figure 2-10 is provided in the context of this step.
By building a consistent interface to the health check, we can use the cloud-based monitoring tools to detect problems and respond to them appropriately.
If the service discovery agent found a problem with the service instance, you can take corrective action, such as shutting down the failed instance or start another instance of the service.
The easiest way to use the micro REST service environment, the interface is constructed health examination Publication may return payload and JSON HTTP status codes HTTP endpoint. In the micro-services based in non-Spring Boot, developers often need to write a return service health endpoints.
在Spring Boot中,公开一个端点是很简单的,只涉及修改Maven构建文件以包含Spring Actuator模块。Spring Actuator提供了开箱即用的运维端点,可帮助用户了解和管理服务的健康状况。要使用Spring Actuator,需要确保在Maven构建文件中包含以下依赖项:
 
  1. <dependency> 
  2.   <groupId>org.springframework.boot</groupId> 
  3.   <artifactId>spring-boot-starter-actuator</artifactId> 
  4. </dependency> 
 
如果访问许可证服务上的 http://localhost:8080/health端点,则应该会看到返回的健康状况数据。图2-11提供了返回数据的示例。
如图2-11所示,健康状况检查不仅仅是微服务是否在运行的指示器,它还可以提供有关运行微服务实例的服务器状态的信息,这样可以获得更丰富的监控体验。
 
2.5 将视角综合起来
云中的微服务看起来很简单,但要想成功,却需要有一个综合的视角,将架构师、开发人员和DevOps工程师的视角融到一起,形成一个紧密结合的视角。每个视角的关键结论概括如下。
(1)架构师——专注于业务问题的自然轮廓。描述业务问题域,并听取别人所讲述的故事,按照这种方式,筛选出目标备选微服务。还要记住,最好从“粗粒度”的微服务开始,并重构到较小的服务,而不是从一大批小型服务开始。微服务架构像大多数优秀的架构一样,是按需调整的,而不是预先计划好的。
(2)软件工程师——尽管服务很小,但并不意味着就应该把良好的设计原则抛于脑后。专注于构建分层服务,服务中的每一层都有离散的职责。避免在代码中构建框架的诱惑,并尝试使每个微服务完全独立。过早的框架设计和采用框架可能会在应用程序生命周期的后期产生巨大的维护成本。
(3)DevOps工程师——服务不存在于真空中。尽早建立服务的生命周期。DevOps视角不仅要关注如何自动化服务的构建和部署,还要关注如何监控服务的健康状况,并在出现问题时做出反应。实施服务通常需要比编写业务逻辑更多的工作,也更需要深谋远虑。
 
2.6 小结
要想通过微服务获得成功,需要综合架构师、软件开发人员和DevOps的视角。
微服务是一种强大的架构范型,它有优点和缺点。并非所有应用程序都应该是微服务应用程序。
从架构师的角度来看,微服务是小型的、独立的和分布式的。微服务应具有狭窄的边界,并管理一小组数据。
从开发人员的角度来看,微服务通常使用REST风格的设计构建,JSON作为服务发送和接收数据的净荷。
Spring Boot是构建微服务的理想框架,因为它允许开发人员使用几个简单的注解即可构建基于REST的JSON服务。
从DevOps的角度来看,微服务如何打包、部署和监控至关重要。
开箱即用。Spring Boot允许用户用单个可执行JAR文件交付服务。JAR文件中的嵌入式Tomcat服务器承载该服务。
Spring Boot框架附带的Spring Actuator会公开有关服务运行健康状况的信息以及有关服务运行时的信息。
 

Guess you like

Origin www.cnblogs.com/mongotea/p/11973162.html