05 - micro service topic 03 - Introduction to micro Service Framework

1. Monomer architecture vs microservice architecture 1.1 single machine architecture 1.1.1 what is a single architecture...
1. Monomer architecture vs microservice architecture
2. Spring Cloud microservice technology stack
3. Spring Cloud Alibaba technology stack

1. Monomer architecture vs microservice architecture

1.1 single machine architecture

1.1.1 what is a single architecture

An archive package (such as war format) contains applications that apply all functions, which we usually call monomer applications. The methodology of single application architecture is called single application architecture. (just a war to beat the world).

1.1.2 schematic diagram of single structure

1.1.3 advantages and disadvantages of single architecture

advantage:

  • The architecture is simple and clear, and there is no "fancy" problem to be solved.
  • Development, testing and deployment are simple (especially the operation and maintenance personnel will wake up when they fall asleep)

Disadvantages:

  • With the business expansion, the code becomes more and more complex and the code quality is uneven (the level of developers is different), which will make you scared every time you submit code and modify every small bug.

  • Slow deployment (due to the single architecture and complex functions). You can imagine the speed of the next code deployment from 200W + (15 minutes)

  • The expansion cost is high. According to the single frame composition, assuming that the user module is a CPU intensive module (involving a large number of operations), we need to replace a more powerful CPU, and our order module is an IO intensive module (involving a large number of read-write disks) , we need to replace more powerful memory and efficient disk. However, our single architecture cannot be expanded for a single function module, so we need to replace more powerful CPU, more powerful memory and more powerful disk, and the price is rising.

  • It hinders the development of new technologies... For example, if our web architecture module is migrated from struts 2 to spring boot, it will become a disaster

1.2 microservices and microservice architecture

1.2.1. Definition of micro service
  • english: https://martinfowler.com/articles/microservices.html

  • chinese: http://blog.cuicc.com/blog/2015/07/22/microservices

The core of microservice is to split the traditional stand-alone applications into services one by one according to the business, and completely decouple them. Each service provides specific functions. A service only does one thing. Similar to the process, each service can be deployed separately, or even have its own database. Such a small service is microservice.

  • For example, traditional stand-alone e-commerce applications have modules such as order / payment / inventory / logistics / points (understood as service)

  • We split it according to the business model, which can be divided into order service, payment service, inventory service, logistics service and integral service

  • If I don't split it, there is a major bug in my non core business integration module, resulting in system memory overflow and downtime of the whole service. If I just say that my integration micro service is unavailable after splitting, the core functions of my whole system can still be used

1.2.2. Characteristics of microservices

1) Independent deployment and flexible expansion

The traditional single architecture is deployed in the unit of the whole system, while the micro service is deployed in the unit of each independent component (such as user service and commodity service).

2) Effective isolation of resources

One of the principles of microservice design is that each microservice has an independent data source. If microservice A wants to read and write the database of microservice B, it can only call the exposed interface of microservice B. This effectively avoids the problems caused by competing for database and cache resources between services.

3) Adjustment of team organizational structure

The idea of microservice design has also changed the original organizational structure of enterprise R & D team. The traditional R & D organizational structure is a horizontal structure, with front-end team at the front end, back-end team at the back end, DBA team at the DBA, and test team. The design idea of microservice has a certain impact on the division of team, making the division of team organizational structure more inclined to vertical frame For example, a team is responsible for user business and a team is responsible for payment business.

1.2.3. What is the microservice architecture?

Microservice architecture style is a method of developing a single application as a set of small services. Each application runs in its own process and works with lightweight mechanisms (usually HTTP resource API s) These services are built around business functions and can be deployed independently through the automatic deployment mechanism. These services have the least centralized management, can be written in different programming languages and use different data storage technologies.

SOA architecture emphasizes the communication and decoupling between heterogeneous systems, while microservice architecture emphasizes the fine-grained splitting and deployment of systems according to business boundaries

Microservice architecture is an architecture style that advocates:

  • Develop a single application into a set of small services

  • Each service runs in its own process

  • Services communicate with each other through a lightweight communication mechanism (http rest api)

  • Each service can be deployed independently

  • Each service can even have its own database

Microservice and microservice architecture are two completely different concepts. Microservice emphasizes the size of services and the single function provided externally, while microservice architecture refers to managing the microservices one by one to provide a complete set of services externally.

1.2.4. Advantages and disadvantages of microservices

advantage:

  • Each service is small enough and cohesive enough to make the code easier to understand and focus on one business function point (compared with traditional applications, it may be necessary to understand the whole system by changing a few lines of code)

  • The development is simple, and one service can only do one thing. (join you to do payment service, you just need to know the payment related code)

  • Microservices can be developed by a small team of 2-5 people to improve efficiency

  • On demand scaling, loose service coupling, and each service can be developed and deployed

  • The front and back ends are separated. As java developers, we only need to concern the security and performance of the back-end interface, and don't pay attention to the human-computer interaction of the page (H5 Engineers). According to the front and back-end interface protocol and the input parameters, we return the json back parameters.

  • A service can have its own database, or multiple services can connect to the same database.

Disadvantages:

  • It increases the workload of operation and maintenance personnel. In the past, only one war package was deployed, but now hundreds of war packages (k8s+docker+jenkins) may need to be deployed

  • Services call each other, increasing communication costs

  • Data consistency problem (distributed transaction problem)

  • Performance monitoring, problem location

1.2.5. Applicable scenarios of microservices

appropriate

  • Large and complex projects... (fear of 200W lines of code from single architecture)

  • Fast iterative projects... (from the fear of one version a day)

  • Projects with high concurrency... (consider the fear of elastic expansion)

inappropriate

  • Business stability means fixing bug s and changing data

  • The iteration cycle is long and the release frequency is once or twice a month

2. Spring Cloud microservice technology stack

2.1. Introduction

Spring Cloud is a one-stop solution for distributed microservice architecture. It is a collection of landing technologies of a variety of microservice architectures, commonly known as microservices.

Spring Cloud provides developers with tools to quickly build some common patterns in distributed systems (such as configuration management, service discovery, circuit breaker, intelligent routing, micro agent, control bus, one-time token, global lock, leadership election, distributed session, cluster state).

  • Official website: https://spring.io/projects/spring-cloud

  • Chinese documents: https://www.springcloud.cc/

  • Spring Cloud China Community: http://springcloud.cn/

2.2. Spring Cloud micro service architecture ecosystem

2.3. Components included in spring cloud Netflix

  • Eureka, service registration and discovery, provides a service registry, a client for service discovery, and a convenient interface for viewing all registered services. All services use Eureka's service discovery client to register themselves with Eureka's server.
  • Zuul, gateway. All clients request to access the background service through this gateway. He can use a certain routing configuration to determine which service handles a URL. And get the registered service from Eureka to forward the request.
  • Ribbon, that is, load balancing. When Zuul gateway sends a request to a service application, if a service starts multiple instances, it will send it to a service instance through the ribbon through a certain load balancing strategy.
  • Feign is a service client. If services need to access each other, you can use RestTemplate or feign client. By default, it uses the Ribbon to achieve load balancing.
  • Hystrix, monitoring and circuit breaker. We only need to add the hystrix label on the service interface to realize the monitoring and circuit breaker functions of this interface.
  • The Hystrix Dashboard provides an interface to monitor the time consumed by service calls on various services.
  • Turbine, monitoring aggregation, using Hystrix monitoring, we need to open the monitoring information of each service instance to view. Turbine can help us aggregate the monitoring information of all service instances into one place for unified viewing. In this way, you don't need to open pages one by one to view them one by one.

[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-S1MufB5m-1634186304824)(assets/15608.png)]

3. Spring Cloud Alibaba technology stack

Like Spring Cloud, Spring Cloud Alibaba is also a set of microservice solutions, including the necessary components for developing distributed application microservices, so that developers can easily use these components to develop distributed application services through the Spring Cloud programming model. Relying on Spring Cloud Alibaba, you only need to add some annotations and a few configurations to connect Spring Cloud applications to Alibaba microservice solutions and quickly build distributed application systems through Alibaba middleware. As a new implementation under the Spring Cloud system, Spring Cloud Alibaba has more functions than official components or other third-party implementations such as Netflix, Consul, ZooKeeper, etc

3.1. Spring Cloud Alibaba contains components

Ali open source component
  • Nacos: a dynamic service discovery, configuration management and service management platform that is easier to build cloud native applications.

  • Sentinel: take the flow as the entry point to protect the stability of services from multiple dimensions such as flow control, fuse degradation and system load protection.

  • RocketMQ: an open source distributed messaging system, based on highly available distributed cluster technology, provides low latency and highly reliable message publishing and subscription services.

  • Dubbo: a high-performance Java RPC framework widely used in China.

  • Seata: Alibaba open source product, an easy-to-use high-performance microservice distributed transaction solution.

  • Arthas: an open source Java dynamic tracking tool, which is based on bytecode enhancement technology and has very powerful functions.

Ali commercial components

As a commercial company, Alibaba launched Spring Cloud Alibaba, which is listed to a large extent. It hopes to help promote its own cloud products by seizing the developer ecology.

  • Alibaba Cloud ACM: an application configuration center product that centrally manages and pushes application configurations in a distributed architecture environment.

  • Alibaba Cloud OSS: Alibaba cloud Object Storage Service (OSS) is a cloud storage service provided by Alibaba cloud.

  • Alibaba cloud scheduler X: a distributed task scheduling product developed by Alibaba middleware team, which provides second level and accurate timed (based on Cron expression) task scheduling service.

[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-95wmTxjX-1634186304825)(assets/15607.png)]

2.2. Spring Cloud Alibaba version selection

Version selection: Spring Cloud Alibaba corresponds to 2.2.1.RELEASE

The parent pom is as follows

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.tuling.mall</groupId> <artifactId>vip-spring-cloud-alibaba</artifactId> <version>0.0.1-SNAPSHOT</version> <name>vip-spring-cloud-alibaba</name> <packaging>pom</packaging> <description>Demo project for Spring Cloud Alibaba</description> <properties> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR3</spring-cloud.version> <spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>$</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>$</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

Latest version selection: Spring Cloud Alibaba 2.2.5.RELEASE

The parent pom is as follows:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.tuling.mall</groupId> <artifactId>vip-spring-cloud-alibaba</artifactId> <version>0.0.1-SNAPSHOT</version> <name>vip-spring-cloud-alibaba</name> <packaging>pom</packaging> <description>Demo project for Spring Cloud Alibaba</description> <properties> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR8</spring-cloud.version> <spring-cloud-alibaba.version>2.2.5.RELEASE</spring-cloud-alibaba.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>$</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>$</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>

13 October 2021, 23:47 | Views: 4322

Add new comment

For adding a comment, please log in
or create account

0 comments