Learning route

** My blog website **IT Little god www.itxiaoshen.com

Ecological Overview

Architecture evolution

What is microservice

https://martinfowler.com/microservices/

Microservices Guide

In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.

-- James Lewis and Martin Fowler (2014)

in short , Microservice architecture style is a way to develop a single application into a set of small services , Each service runs in its own process , And with lightweight mechanisms ( Usually HTTP resources API) signal communication . These services are built around business capabilities , It can be deployed independently through a fully automated deployment mechanism . Centralized management of these services is minimal , These services can be written in different programming languages , And use different data storage technologies .

-- James · Lewis and Martin · Fowler (2014)


Architecture evolution

Dubbo file

The evolution of website application

With the development of the Internet , The scale of web applications continues to grow , Conventional vertical application architectures can no longer cope , Distributed service architecture and flow computing architecture are imperative , There is an urgent need for a governance system to ensure the orderly evolution of the architecture . Good architecture is not designed from the beginning , It's evolving

Single application architecture

When website traffic is low , Just one app , Deploy all functions together , To reduce deployment nodes and costs . here , Data access framework to simplify the work of adding, deleting, modifying and querying (ORM) Is the key .

Vertical application architecture

When the number of visits increases gradually , Single application increases the acceleration brought by the machine is getting smaller and smaller , One of the ways to improve efficiency is to break down the application into separate applications , To improve efficiency . here , For accelerating front-end page development Web frame (MVC) Is the key .

Distributed service architecture

As more and more vertical applications , Interaction between applications is inevitable , Extract core business , As an independent service , Gradually form a stable service center , Enable front-end applications to respond more quickly to changing market demands . here , Distributed service framework for business reuse and integration (RPC) Is the key .

Flow computing architecture

When the service is more and more , Capacity assessment , Problems such as waste of small service resources are gradually emerging , At this time, it is necessary to add a dispatching center to manage the cluster capacity in real time based on the access pressure , Improve cluster utilization . here , Resource scheduling and Governance Center for improving machine utilization (SOA) Is the key .

SOA Service architecture and micro service architecture


Recommended Architecture

Spring Cloud Official website

Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer’s own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.

Spring Cloud Provide tools for developers , Some common patterns used to quickly build distributed systems ( For example, configuration management 、 Service discovery 、 Circuit breaker 、 Intelligent routing 、 The micro broker 、 Control bus 、 One-off token 、 Global lock 、 Leadership election 、 Distributed session 、 State of the cluster ). The coordination of the distributed system leads to the boiler plate mode , Use Spring Cloud developers can quickly build services and applications that implement these patterns . They work well in any distributed environment , Including developers' own laptops 、 Hosting platforms such as bare metal data center and cloud casting .


Spring Cloud Alibaba Official website

Spring Cloud Alibaba provides a one-stop solution for distributed application development. It contains all the components required to develop distributed applications, making it easy for you to develop your applications using Spring Cloud.

With Spring Cloud Alibaba, you only need to add some annotations and a small amount of configurations to connect Spring Cloud applications to the distributed solutions of Alibaba, and build a distributed application system with Alibaba middleware.

Alibaba cloud provides a one-stop solution for distributed application development . It contains all the components needed to develop distributed applications , Make it easy for you to use SpringCloud Developing applications .

Through Alibaba cloud Spring cloud , You just need to add some comments and a few configurations , Can be Spring Cloud applications are connected to Alibaba cloud's distributed solutions , Alibaba cloud middleware is used to build distributed application systems .


Sentinel: Traffic control and service degradation : Alibaba Sentinel flow control 、 Open circuit and system adaptive protection

Nacos registration and discovery: Service registration and discovery : You can ask Alibaba Nacos Registration instance , The client can use spring Managed bean Find examples . Support Ribbon, adopt Spring Cloud Netflix Client load balancer

Nacos config: Distributed configuration : Use Alibaba Nacos As data storage

Seata: A high performance 、 Easy to use distributed transaction solutions , For microservice Architecture . Solve the problem of distributed transactions in microservices

Dubbo:Apache Dubbo It's a high performance 、 Lightweight open source service framework , Provides six core competencies : High performance for interface agents RPC call , Intelligent fault tolerance and load balancing , Services automatically register and discover , Highly scalable , Traffic scheduling during operation period , Visual service governance and operation and maintenance .

Spring Cloud Stream: Event driven , Use RocketMQ Binder Build highly scalable event driven microservices

Spring Cloud Bus: The message bus : Use Spring Cloud Bus Nodes connecting distributed systems

Spring Cloud Netflix Ribbon: Client load balancer : Nacos Client default integration ribbon

Spring Cloud Gateway: Provides an in Spring WebFlux Build on API Library of gateways .Spring Cloud Gateway Designed to provide a simple and effective way to route to api, And provide them with crosscutting concerns , Such as : Security 、 monitor / Index and elasticity .

Appache SkyWalking: Application performance monitoring tools for distributed systems , Especially for micro service , Cloud local and container based (Docker, Kubernetes, Mesos) Architecture design .

be based on Spring Cloud Alibaba Recommended micro service ecosystem Architecture , Based on layered architecture .

Access layer : The outermost layer is LVS+Keepalived, It can withstand hundreds of thousands of high concurrent flow peaks , Then through the inner layer nginx The cluster forwards the client requests to the server based on the load balancing policy JAVA Back end technology stack Spring Cloud Gateway colony ;

Business middle level :Spring Cloud Gateway Microservices go through Nacos Get the route configuration information and the discovery of the route backend micro service provider , adopt OAuth2 Do unified login Authorization , And integrate Sentinel Limit the current for the request 、 Fuse 、 Reduce , be based on dubbo Protocol performance RPC Make microservice calls or service aggregation calls , The call between the back-end microservices also adopts dubbo Agreed rpc, For the server that needs distributed transactions, it can use Seata Realization .

Technical middle floor : The data storage layer includes memory 、 database 、 Full text search engine storage layer ; The basic service layer provides common basic component functions of distributed systems ; The log collection layer adopts ELK

System monitoring layer : Distributed Link Tracking 、 Container based monitoring and alarm

Maven Introduction to simple integration engineering

shopping-demo Source code address

https://gitee.com/yongzhebuju/shopping

Function introduction


This example mainly uses... For microservices Nacos Realize the reading of configuration center 、 Service registration and service discovery , The microservice gateway implements routing strategies and integrates them sentinel Achieve current limiting , Use... Between microservices Dubbo High performance RPC To call .

This case mainly includes the following demo modular

commons: Public service module , Public storage pojo Entity class and micro service interface module , such as Dubbo Service provider interface definition 、 be based on Open Feign Remote call service provider interface definition, etc , Common module pom Some public reference dependencies can be configured, such as spring-cloud-starter-alibaba-nacos-config and spring-cloud-starter-alibaba-nacos-discovery etc. , In this way, other micro services only need to rely on common modules

gateway: Microservice gateway module , Responsible for microservice routing 、 Authorized certification 、 Micro service aggregation and other functional processing

users: User module , Provide access to the user interface

good: Commodity module , Provide commodity interface , Need to call the user interface

Core source code and configuration

Engineering parent pom The file mainly contains Spring Boot、Spring Cloud、Spring Cloud Alibaba My father depends on

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.itxs</groupId>
<artifactId>shopping</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
</parent> <modules>
<module>shopping_commons</module>
<module>shopping_goods</module>
<module>shopping_users</module>
<module>shopping_gateway</module>
</modules> <properties>
<java.verson>1.8</java.verson>
<spring.cloud.verison>Hoxton.SR12</spring.cloud.verison>
<spring.cloud.alibaba.verison>2.2.1.RELEASE</spring.cloud.alibaba.verison>
</properties> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.verison}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring.cloud.alibaba.verison}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> </project>

Microservices yml The configuration file , Microservices are configured in Nacos Configuration center , Each microservice local configuration file only needs to configure the service name 、 The active environment and the address of the configuration center 、 Configuration file extension 、 Namespace and group . The following is the gateway configuration file , Other module configuration files are similar

spring:
profiles:
active: dev
cloud:
nacos:
config:
server-addr: localhost:8848
file-extension: yaml
namespace: 54c53c3a-6008-4ecc-90fe-2ffcae64b95b
group: shopping
application:
name: gateway

commons Entity classes and expose get user interface services

package com.itxs.entity;

import java.io.Serializable;

public class User implements Serializable {
private String name;
private Integer age; public User(String name, Integer age) {
this.name = name;
this.age = age;
}
}
package com.itxs.service;

import com.itxs.entity.User;

public interface UserService {
User getUser(String userId);
}

users The microservice obtains the user interface implementation

package com.itxs.service;

import com.itxs.entity.User;
import org.apache.dubbo.config.annotation.Service; @Service
public class UserServiceImpl implements UserService{
@Override
public User getUser(String userId) {
System.out.println("userId:"+userId);
return new User("zhangsan",16);
}
}

users controller Implementation class , Also available here http Protocol call mode

package com.itxs.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class UserController { @RequestMapping("/users/1")
public String getUser(){
return "hello users";
}
}

goods controller

package com.itxs.controller;

import com.itxs.entity.User;
import com.itxs.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class GoodsController { @Reference
UserService userService; @RequestMapping("/goods/1")
public String getGoods(){
return "hello goods";
} @RequestMapping("/goods/user")
public String getUserInfo(){
User user = userService.getUser("a1001");
return user.toString();
}
}

Nacos Configuration center

Start a local Nacos server End , Visit local nacos Management interface http://localhost:8848/nacos, The default port is 8848, Default user password nacos/nacos, stay dev There is a gateway under the namespace 、 user 、 Product micro service configuration file , All use shoopping Group

users-dev.yaml

server:
port: 8081
spring:
profiles:
active: dev
cloud:
nacos:
discovery:
server-addr: 192.168.3.3:8848
namespace: 54c53c3a-6008-4ecc-90fe-2ffcae64b95b
group: shopping
sentinel:
enabled: true
transport:
dashboard: localhost:8888
port: 8719
application:
name: users

goods-dev.yaml

server:
port: 8082
spring:
profiles:
active: dev
cloud:
nacos:
discovery:
server-addr: 192.168.3.3:8848
namespace: 54c53c3a-6008-4ecc-90fe-2ffcae64b95b
group: shopping
sentinel:
enabled: true
transport:
dashboard: localhost:8888
port: 8729
application:
name: goods

gateway-dev.yaml

server:
port: 8083
spring:
profiles:
active: dev
main:
allow-bean-definition-overriding: true
cloud:
nacos:
discovery:
server-addr: 192.168.3.3:8848
namespace: 54c53c3a-6008-4ecc-90fe-2ffcae64b95b
group: shopping
sentinel:
enabled: true
transport:
dashboard: localhost:8080
port: 8719
gateway:
discovery:
locator:
lowerCaseServiceId: true
enabled: true
routes:
- id: users_route
uri: lb://users
predicates:
- Path=/users/** - id: goods_route
uri: lb://goods
predicates:
- Path=/goods/**
application:
name: gateway
management:
endpoints:
web:
exposure:
include: "*"

Sentinel Console

adopt Sentinel The source code project starts Sentinel Console , It's a Spring Boot project

Visit local Sentinel Console interface http://localhost:8080/, The default port is 8080, Default user password sentinel/sentinel, Because there is no persistence function for the time being , So just came in, the content is empty

Microservices start

Start the gateway 、 user 、 Three microservices of goods , The user micro service port is 8081, The commodity micro service port is 8082, The gateway microservice port is 8083

Access directly without a gateway goods Microservices http://localhost:8082/goods/1, go http Method call interface

Configure our access to user services through gateway routing http://localhost:8083/users/users/1 , The access result is correct

Continue to access commodity interface services http://localhost:8083/goods/goods/1 , The access result is correct

Access goods and services and call user services http://localhost:8083/goods/goods/user , The access result is correct

Sentinel The console sets the lower limit flow rule , in the light of goods/goods/user This contact link is used for flow control setting

When we access it twice a second, we will still access it normally , We press... Continuously and quickly F5 Refresh will appear Blocked by Sentinel: FlowException, This is the default Sentinel Return current limiting , We can also implement custom current limit prompt

One stop solution for mainstream microservices Spring Cloud Alibaba It's enough to get started and read more related articles

  1. Spring Cloud And microservice construction :Spring Cloud brief introduction

    Spring Cloud brief introduction Because of the functions that microservices should have Microservices can be split into " tiny " and " service " Two words ." tiny " It means small , How small is that " tiny &q ...

  2. Spring Cloud Alibaba Introduction to the actual combat nacos( One )

    Spring Cloud Alibaba Introduction to the actual combat nacos( One ) Antecedents to introduce ​ Spring Cloud Alibaba It's a new generation of micro service solution provided by Alibaba , I believe there will be more and more companies adopting micro service architecture ...

  3. Microservice architecture - choice Spring Cloud, give up Dubbo

    Spring Cloud Can it be used in small and medium-sized companies in China ? from 2016 From the beginning of the year until now , We've been on this road for more than a year . In the use of Spring Cloud Before , We don't have much experience in microservice practice . from ...

  4. Microservice architecture integrator —Spring Cloud ( Reprint )

    Software is alive , The architecture you build determines whether the software will be bumpy or happy in its whole life . This article is not about how to use Spring Cloud A tutorial for , But to explore Spring Cloud What is it? , And the background and significance of its birth . 1 background 2 ...

  5. Python How to integrate the micro service written into Spring Cloud system ?

    Preface In today's article, xiaomaige will share with you an interesting case encountered in his current work , It's how to put Python The micro services written are integrated into Java Technology stack based Spring Cloud In the micro service system ? Maybe some friends will have questions , To ...

  6. Microservices SpringCloud And Spring Cloud Config Configuration center service

    In the first two Spring Cloud Config The blogs in the configuration center need to specify the address of the configuration service url:spring.cloud.config.uri, Clients call the configuration center directly server End to get the configuration file ...

  7. Spring Cloud Micro service five :Spring cloud gateway Current limiting

    Preface : In Internet applications , Especially e-commerce , There are many scenarios with high concurrency , such as : seckill . Rush purchase . double 11 etc. , At the beginning of the time point will make the flow of explosive influx , If the network traffic is not controlled, it is likely to cause the background instance resource exhaustion . Limiting traffic refers to reducing traffic through a specified strategy , ...

  8. 【 Microservices 】 Use spring cloud Build a micro service framework , Organize learning materials

    Write it at the front Use spring cloud Build a micro service framework , It's one of my most important jobs recently , At first I used bubbo Add zookeeper We've made one based on dubbo The microservice framework of , Then it was rejected by the architect , The architect said : This thing is out of date . along with ...

  9. Microservice architecture spring cloud zipkin

    Spring Cloud Zipkin It is the link tracking component of microservice , Help learn more about request&response The total time of , And the time consumed by each micro service . Microservice name . Exception information and other process information . ( One ) edition ...

  10. Microservice architecture spring cloud turbine

    Introduced earlier spring cloud hystrix And its hystrix dashboard, But it's all about monitoring a single project , For a project , There must be many micro Services , It's very inconvenient to see one by one , If one can fuse centrally ...

Random recommendation

  1. ** contrast $_POST、$GLOBALS[&#39;HTTP_RAW_POST_DATA&#39;] and file_get_contents(&#39;php://input&#39;)

    Recently, we are developing wechat interface , I have learned some new technical points , Today, I will simply list the technical points learned about receiving data . public function __construct($token, $wxuser = ''){ $ ...

  2. Hang Dian 1013-Digitai Root( This is a postgraduate entrance examination programming problem - Tian Da 2015)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. HttpRequest Get Post,WebClient Get

    #region HttpRequestGet public string HttpRequestGet(string url) { return HttpRequestGet(url, WebRequ ...

  4. Yes web Understanding and application of single entry mode in application php Realization

    In us web Application development , Single entry mode is often heard or seen , Before I started learning tp I don't understand why I want to use a single entry mode in the framework , Just using , Recently, when I was working on a little thing, I realized why I was web Single entry should be used in development ...

  5. Android The design logic of jigsaw puzzle , From cut to interactive animation , From level to countdown , Instance improvement !

    Android The design logic of jigsaw puzzle , From cut to interactive animation , From level to countdown , Instance improvement ! The last chapter of Qunying biography , I took a general look at this example , I found that Hongyang great God also did , Just refer to the design logic of two people , It's almost the same , That's it ...

  6. H5 Use Swiper Sliding conflict encountered in the process

    One . problem (1)PC The end mouse can drag the wheel in the middle to make the page slide up and down , Click the left button and press it. You can't drag it (2) Mobile browsing H5 Fingers can't slide the page , As a result, the text at the bottom of many pages cannot be seen Two . solve the problem 1. Let's start with css The problem of , Lord ...

  7. div+css Hide content style method

    div css Hide content style method     div+css How to hide content In general ,css Hidden uses , as follows : 1. Hiding text 2. Hide hyperlinks ( Alternative black chain ) 3. Hide the statistical code 4. Hide beyond picture 5.css ...

  8. java Character encoding problem

    Write a function that intercepts a string , Input as a string and number of bytes , Output as a string truncated by bytes . But make sure that the Chinese characters are not cut in half , Such as “ I ABC”4, It should be cut as “ I AB”, Input “ I ABC han DEF”,6, The output should be “ I ABC” instead of ...

  9. 【 primary 】Coursera—Andrew Ng machine learning — Course notes Lecture 2_Linear regression with one variable Univariate linear regression

    Lecture2   Linear regression with one variable  Univariate linear regression 2.1 Model to represent Model Representation 2.1.1  Linear regression Li ...

  10. xamarin.IOS App Flashback log ----crash

    One . Find log file location : adopt xcode/windows/device/ Yours IPhone/crash Two . You can check the log directly , But the log record is too messy to understand , Need conversion processing , lookup .DSYM file , file location :/Use ...