SpringCloud-based microservice architecture study notes (1) chapter content and microservice architecture introduction

1 Introduction

1. 1 Learning the Preface

The notes in this chapter are mainly to record and learn some middleware knowledge such as microservice framework.

  1. Service cluster : multiple services distributed on multiple computers, each service completes some functions of the project, achieving high cohesion and low coupling.
  2. Service Gateway : Route forwarding (receive all external requests and forward them to the back-end microservices) + filter (longer authority, current limiting and monitoring);
  3. Registration center : The registration center can be said to be the "address book" in the microservice architecture, which records the mapping relationship between services and service addresses.
  4. Configuration Center : A system for unified management of all configurations in the project (centralized configuration management, unified standards; separation of configuration and application; real-time update; high availability)
  5. Message queue : In high-concurrency business scenarios, message queues play an irreplaceable role in traffic peak shaving and decoupling . The currently used message queues include RabbitMQ, RocketMQ, ActiveMQ, Kafka , ZeroMQ, Pulsar, etc.
  6. Distributed cache : The purpose of cache is to improve the efficiency of data query. Static data is usually stored in relational databases. The IO efficiency of such databases is generally not high, and it is often difficult to deal with high-concurrency queries. Using cache can greatly improve the throughput of read operations.
  7. Distributed search : A distributed search engine is a device that divides the entire network into several autonomous regions based on regions, topics, IP addresses and other division criteria, and sets up a search server in each autonomous region.
  8. Database : These three points determine the high cost performance of MySQL database. And at present, many mainstream companies still favor MySQL, and the famous Facebook is still continuing to use MySQL.

1. Design technology

  1. Service Technology : Microservice Governance, Serviceless Protection and Distributed Transactions
  2. Asynchronous Communication Technology : Asynchronous Communication and Reliable Message Service
  3. Cache technology : distributed cache, multi-level cache and Redis cluster
  4. Search Technology : Distributed Search
  5. DevOps : Docker technology

2. The path of learning

Practical articles
1) Microservice governance : registration discovery, remote adjustment, configuration management and routing gateway
2) Docker technology : the use of Docker, Dockererfile, DockerCompose
3) Asynchronous communication : MQ message model, SpringAMQP, message accumulation problem, data persistence
4 ) Distributed cache : Redis data structure, SpringDataRedis, cache penetration, avalanche
5) Distributed search : DSL statement, RestAPI, ES cluster status

Advanced
1) Microservice protection : flow control, system protection, circuit breaker downgrade, service authorization
2) Distributed transactions : distributed transactions, TCC model, AT model, Seata
3) Multi-level cache : OpenResty, multi-level cache, cache data Synchronization, Nginx local cache
4) Redis cluster : data persistence, Redis master-slave replication, Lua script, Redis cluster
5) Reliable message service : message reliability, mirror cluster, delay queue, message idempotency

1. Microservice Governance

1.1 Microservice_Service Architecture Evolution

  1. Monolithic architecture: simple and convenient, highly coupled, poor scalability, suitable for small projects
  2. Distributed architecture: high cohesion and low coupling, but complex architecture, suitable for large-scale Internet projects
  3. Microservice Architecture: It is not a new architecture, but a distributed architecture solution with well-designed architecture . The characteristics are: single responsibility, service-oriented, strong autonomy and isolation (avoiding cascading problems).
    1) Advantages: high cohesion and low coupling, smaller split granularity, and stronger service independence.
    2) Disadvantages: complex architecture, difficult operation and maintenance, monitoring, and deployment

1. 2 Microservice_Comparison of Microservice Technology

Nowadays, the two most popular micro-service landing technologies are Alibaba's Dubbo and Spring Cloud, and the following is a comparison and introduction.

  1. Dubbo : open source very early, the core thing is to serve remote calls (Dubbo protocol)
  2. SpringCloud : Integrates the microservice technology stack on the market and provides a full-stack microservice solution.
  3. SpringCloudAlibaba : Developed based on SpringCloud, and covers Dubbo technology (with some own components: Nacos, Dubbo, Sentineld, etc.)
  4. Huawei CSE : In fact, it also has its own microservice architecture CSE, which will be briefly introduced later!

There are four common microservice systems in the market:

  1. SpringCloud+Feign (SpringCloud technology stack + Restful service interface style + Feign service calling method)
  2. SpringCloudAlibaba+Feign (SpringCloudAlibaba technology stack + Restful service interface style + Feign service call method)
  3. SpringCloudAlibaba+Dubbo (SpringCloudAlibaba technology stack + Dubbo service interface standard + Dubbo service calling method)
  4. Dubbo original mode (dubbo technology stack + Dubbo service interface standard + Dubbo service call method)
    question: What are the service interface style and service call method?

1. 3 Microservice_SpringCloud Introduction

  1. What is Spring Cloud?
    SpringCloud is currently the most widely used microservice architecture in China, including SpringCloudAlibaba. Integrates the governance solutions required by major companies before (service registration discovery, unified configuration management, service remote call, unified gateway routing, service link monitoring and blanking, downgrade protection, etc.)
  2. Why is Spring Cloud as a microservice and not others?
    Spring Cloud integrates the functional components of various microservices, and realizes the automatic assembly of components based on SpringBoot (the biggest advantage is that the configuration of each component is cumbersome and does not communicate with each other), thus providing a good out-of-the-box experience.
  3. Component types and solutions
    1) Service registration discovery: Rureka, Nacos, Consul
    2) Unified configuration management: SpringCloudConfig, Nacos
    3) Service remote call: OpenFeign, Dubbo
    4) Unified gateway routing: SpringCloudGateway, zuul
    5) Service link monitoring : zipkin, Sleuth
    6) Traffic monitoring, load Junhe, cascade protection: Hystix, Sentinel

1.4 Microservice _demo import and run

  1. Open NavicatMySQL, create two new databases, and then read in the SQL file (NavicatMySQL is a fixed file, no installation required)
  2. Change the password for reading the database in the configuration file of the project (the default is 123 in the project, and 123456 in your own mysql), and it must correspond to the name of the database you created.
  3. Run two services, type url in the browser
    1) user's url : http://localhost:8081/user/1
    2) order's url : http://localhost:8080/order/101
  1. Through this small demo, people can clearly see how a project works.

1. 5 (Supplementary) Upload the local project to the cloud gitee

First, you need to create a new project with the same name on Gitee, and copy its link
1) Use cmd locally to clone the gitee project

git clone 仓库的路径     %仓库的路径为gitee上项目的访问路径

2) Put all the files in the local project into the clone project (just cloned)
3) Statement trilogy: add to local warehouse temporary warehouse; submit to local warehouse; submit to remote warehouse

git status   #查看项目中文件的状态
git add .    #一个空格带个点,把所有的文件都放入暂存区
git commit -m '修改的名称'   #把暂存区项目放入本地仓库,并且添加本次项目修改的名字
git push   # 把这个项目上传到已经链接的线上远程仓库

4) In the following projects, open IDEA directly, and add will be executed automatically. You only need to actively implement commit and push operations.

1. 6 Service splitting - service remote call

Goal: The function of querying the order according to the id of the order (that is, the user's information can be found in the orderservice)

Method: Obtain by writing http remote commissioning in the project (cannot be written internally, because the service function must be independent) specific steps

  1. Register restemplate in the configuration class (the startup class is also considered the configuration class)
  1. Initiate http request in orderservice, using useid information
  1. Summary
    1) Realize remote calls based on http requests initiated by RestTemplate
    2) Remote calls made by http requests are language-independent calls , as long as you know the other party's ip, port, interface path, and request parameters.
    3) The roles of provider and consumer are actually relative; a service can be a service provider and a service consumer at the same time

Reference
1) Dark Horse Programmer SpringCloud+RabbitMQ+Docker+Redis+Search+Distributed, System Detailed Springcloud Microservice Technology Stack Course

Guess you like

Origin blog.csdn.net/qq_42974034/article/details/129214675