Series of articles study:

Learn about microservices (part 1) : Learn about microservices

Learning microservices series (2) : Build services based on SpringBoot

Learning micro-service series (3) : Springboot + page front and back end separation and RESTFUL style interface writing

Learning microservice series (4) : Springboot service Gateway Gateway

Learning microservices series (5) : SpringBoot microservices use NACOS as the registry

Learning microservice series (vi) : SpringBoot microservice uses NACOS as the configuration center

Learning microservice series (7) : NacOS principle analysis

Learning microservices series (8) : Springboot services distributed transactions and solutions

Learning microservice series (nine) : Springboot service interface security authentication design

Learning microservice series (10) : Springboot microservice distributed asynchronous message communication

Learn microservices (11) : CI/CD, DevOps for microservices

Learn microservices series (12) : Service Governance

Our articles above have illustrated a number of related technologies under the microservices architecture, where service governance issues arise as business services evolve to the microservices architecture. Under the microservice architecture, new service problems arise, which requires service governance for microservices. What problems do micro services have to be managed? 1. Observability. As microservices have more deployment carriers than single applications, they need to have a clear control over the calling relationship and status among many services. 2. Traffic management and security protection. Because microservices have different versions, it is necessary to control the invocation between microservices to smooth the version change of microservices. This process requires distribution to different versions of services based on traffic characteristics (access parameters, etc.) and percentages, which also incubates the segmentation topics of service governance such as grayscale publishing, blue-green publishing, and A/B testing.

observability

Observability We need several APM software to help us monitor the status of the service. This includes CPU load in hardware, memory usage, and network usage. Error rate at the system software level Interface response time, call link and other information.

Commonly used APM tools are:

SkyWalking Github Wu-sheng/Skywalking is an open source system developed by a brother named Wu Sheng in China. It is also a system for tracking, alerting and analyzing the business running status of JAVA distributed application cluster. It has relatively simple functions, but it can support link tracking well in some simple businesses.

Zipkin is an open source product of Twitter. Zipkin’s Java application uses a component called Brave to collect performance analysis data within the application. Through the implementation of a series of Java interceptors, to achieve HTTP /servlet requests, database access call process tracking. You can then collect performance data for Java applications by adding these interceptors to configuration files such as Spring. Timing data for the collection of services to address latency issues in the microservice architecture, including data collection, storage, lookup, and presentation.

The Grafana+ Zabbix zabbix software monitors a wide range of network parameters and server health and integrity. Zabbix uses a flexible alarm mechanism that allows users to configure mail-based alarms for almost any event. This allows users to quickly respond to server problems. In addition, there are many commercial APM software: such as Cloud, Borui and so on.

Traffic management and security protection

Flow management and circuit breaker protection, here I specifically introduce Ali’s Sentinel. Let’s take a look at sentinel’s ecosystem:

Sentinel is divided into two parts:

  • The core library (Java client) is independent of any framework/library, can run in all Java runtime environments, and has good support for frameworks such as Dubbo/Spring Cloud.
  • The Console (Dashboard) is based on Spring Boot and can be packaged to run directly without the need for additional application containers such as Tomcat.

Comparison with Hystrix:

Access the console to view monitoring data in real time

  1. To download the console JAR package, you can download it directly from github.com/alibaba/Sen… Page to download, you can also download the source code to compile (github.com/alibaba/Sen…
java -Dserver.port=8333- Dcsp.sentinel.dashboard.server=localhost:8333 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.42..jar
Copy the code
  • – dserver. port Specifies the port of the console
  • – Dcsp. Sentinel. Dashboard. Server specify the address of the console, equivalent to register themselves, so start can see their own information
  • – dproject. name Specifies the name of the application to be added
  1. After startup, visit http://localhost:8333 to jump to the main page of the console, as shown below:

We will not explain the operation of the console, you can try it yourself, for example, we want to see the real-time monitoring data, then click the first real-time monitoring menu, you can see the following effect:

The entire console page is explained in Chinese, you can directly click on the specific functions of each part of the experience, you can see the QPS of each URI, rejected QPS and other information.

The client accesses the console

Above is actually the console itself into the access, if we want to access the actual work of the project, how to access? The client needs to import the Transport module to communicate with the Sentinel console. You can introduce JAR packages through pom.xml:

<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-transport-simple-http</artifactId>
	<version>1.81.</version>
</dependency>
Copy the code

Also add the JVM startup parameter to specify the console address:

-Dcsp.sentinel.dashboard.server=localhost:8333
Copy the code

Note: If your application is a Spring Boot or Spring Cloud application, you can use Spring Cloud Alibaba to specify the configuration through the Spring configuration file, which we will discuss below.

Sentinel is initialized when the client first invokes it to start sending heartbeat packets to the console. Then we can see our own apps on the console. Various traffic limiting mechanisms can be added through configuration.

The Springboot project introduces Sentinel

  1. The POM file is added
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-alibaba-sentinel</artifactId>
    <version>0.21..RELEASE</version>
</dependency>
Copy the code
  1. Properties file added
# sentinel console spring. Cloud. Sentinel. Transport. The dashboard = localhost:8099
spring.cloud.sentinel.eager=true
Copy the code
  1. Start the Springboot service directly after starting the Sentinel console

This concludes our entire series on microservices, and there will be more to come, including vue on the front end, Golang on the server, and the series. Please pay more attention to the public number: IT technology small stack