Microservices - Microservice Architecture and Components (1)

 1. Common problems and corresponding components of microservice architecture

Once the microservice system architecture is adopted, several problems are bound to be encountered:
how to manage so many small services? (Service Governance Registry[Service Registration Discovery Elimination]) nacos


With so many small services, how do they communicate with each other? (restful rpc dubbo feign)    

httpclient("url", parameter), springBoot restTemplate("url", parameter),    feign


With so many small services, how do clients access them? (gateway) gateway


With so many small services, once there is a problem, how should we deal with it? (fault tolerance) sentinel


With so many small services, once there is a problem, how should we troubleshoot?  (Link tracking) Skywalking

cannot be bypassed by any microservice designer for the above problems, so most microservice products are aimed at each Problems provide corresponding components to solve them.

 When a request comes in, we will go to the registration center through the gateway to pull our service list, and then route it to the corresponding service through our local load balancer ribbon. We can also combine our sentinel to perform A series of fault-tolerant means, including our current limiting, downgrading, etc., and the call between services, we use Feigin to make an elegant call, so in the distributed architecture, there is a consistent transaction As for sexual issues, we use SEATA to solve them.

2. SpringCloud Alibaba Microservice Solution

1 Overview

    Spring Cloud Alibaba is a sub-project of Spring Cloud, dedicated to providing a one-stop solution for microservice development. This project contains the necessary components to develop 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 small amount of configuration to connect Spring Cloud applications to Alibaba microservice solutions, and quickly build distributed application systems through Alibaba middleware.

2. Core component analysis

Spring Cloud Alibaba provides the following core functions by default (understand first):

Service rate-limiting and downgrading:
        By default, it supports the access of WebServlet, OpenFeign, RestTemplate, Spring Cloud Gateway, and RocketMQ's rate-limiting and downgrading functions. You can modify the rate-limiting and downgrading rules in real time through the console at runtime, and also supports viewing the rate-limiting and downgrading Metrics monitoring.
Service registration and discovery:
        Based on the Spring Cloud service registration and discovery standard, it is realized with the help of Nacos, and the support of Ribbon is also integrated by default.
Distributed configuration management:
        Based on Nacos, it supports external configuration in distributed systems, and automatically refreshes when the configuration changes.
Message-driven capability:
        Build message-driven capabilities for microservice applications based on Spring Cloud Stream.
Distributed transactions:
        Use @GlobalTransactional annotation to solve distributed transaction problems efficiently and with zero intrusion to business.
Distributed task scheduling:
        Provides second-level, accurate, highly reliable, and highly available scheduled (based on Cron expression) task scheduling services. At the same time, it provides a distributed task execution model, such as grid tasks. Grid tasks support the even distribution of sea quantum tasks to all Workers for execution.

3. Solution architecture design

    Based on the microservices implemented by Spring Cloud Alibaba, the solution design architecture is shown in the figure:

4. Build the SpringCloud aggregation project and initialize the environment

4.1 Engineering structure

cgb2106-4 (工作区/空项目)
├── 01-sca   //(微服务父工程)
     ├── sca-provider         //服务提供方
     ├── sca-consumer         //服务消费方
     ├── sca-gateway          //网关服务,这个工程后续会作为服务的访问入口

4.2 Add corresponding dependencies

参考网址:https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E

    In the pom file, add the following dependencies:

<!--    maven的父工程为一个pom工程,此工程主要负责依赖版本及部分基础依赖的管理-->
    <dependencyManagement>
        <dependencies>
            <!--Spring Boot 依赖(定义了微服务规范)-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <!--Spring Cloud 依赖(定义了微服务规范)-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR9</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <!--Spring Cloud Alibaba依赖(基于spring微服务规范做了具体落地实现)-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.6.RELEASE</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

5. Summary

    In short, microservices are an architectural design approach in which each service (service) in this architecture is designed for a set of functions and focuses on solving a specific problem. If developers gradually add more code to a service and the service becomes complex, it can be broken into multiple smaller services. Next, carry out independent development, testing, deployment, operation, and maintenance. In turn, it can handle client requests better and more flexibly and improve the reliability and scalability of the system.

Guess you like

Origin blog.csdn.net/m0_63270506/article/details/124459811