The birth of a springcloud microservice mall system

Time:2021-9-23

cause

One day, apple and watermelon said, “Hey, why is there no easy-to-use microservice mall on the market?”

Watermelon: “it’s too difficult. It looks like a micro Service Mall.”

Apple: “this is only background code, not database”

Watermelon: “what about this?”

Apple: “there is a database without a front end”

Watermelon: “what about this?”

Apple: “there is a front-end, but it’s PC. I want mobile”

Watermelon: “what about this?”

Apple: “can’t open a store, not B2C”

Watermelon: “what about this?”

Apple: “too old to maintain”

Watermelon: “let’s write it ourselves“

get ready

What should a micro service mall have?

A: split the service.

What is used for service registration discovery after splitting?

A: spring cloud Alibaba is very popular recently.

It’s all disassembled. Do you want to divide the library?

A: Yes, you must.

Do you want to handle distributed transactions after distributing the database?

A: use Seata. It’s relatively simple. In pursuit of performance, use MQ to achieve final consistency.

Dubbo should be used for internal service calls. I heard that the performance is very high?

A: Yes, but would it be better to use HTTP protocol? After all, I heard that Dubbo is not very compatible with k8s. With HTTP protocol, it is convenient to transform the architecture in the future.

What about search?

Answer: to participle, use es

The database needs to be synchronized to es. What do you use?

A: canal

What about security? What about login permissions?

A: write your own handwriting for security and login. The set of spring security is too complex.

What about the amount?

A: use points

implementation

The first step in building a mall is to unify exception handling

The birth of a springcloud microservice mall system

It was supposed to be Dubbo. Later, it was found that the compatibility between Dubbo and Nacos was not very good, k8s and there were many pits where Dubbo was incompatible, so it was decided to remove Dubbo

The birth of a springcloud microservice mall system

Code specification introduced into Alibaba

The birth of a springcloud microservice mall system

Spring cloud 2020 has just been released, meeting difficulties

The birth of a springcloud microservice mall system

Almost at the same time, Nacos was exposed to security problems, and the administrator ignored it, which made people angry

The birth of a springcloud microservice mall system

Reviewed the security related code again, verified the internal request encapsulation, and learned the lessons of Nacos

The birth of a springcloud microservice mall system

Seata step pit

The birth of a springcloud microservice mall system

Regardless of performance, rocketmq has transaction messages, and rabbitmq needs to write them by itself

The birth of a springcloud microservice mall system

complete

After the replacement of multiple frameworks and stepping on multiple pits, we seek the most reasonable results from many unreasonable ones. Each line of code is completed independently and has submission records. After nearly a year, the project finally came out!!!

A microservice B2B2C E-commerce mall system based on spring cloud, Nacos, Seata, mysql, redis, rocketmq, canal, elasticsearch and Minio adopts mainstream Internet technology architecture, brand-new UI design, supports cluster deployment, service registration and discovery, and has a complete order process. The code is completely open source without any secondary encapsulation, It is a very suitable e-commerce platform system for secondary development.

A microservice mall with very standardized code is scanned with Alibaba code specification tool, and there is no exception at all

The birth of a springcloud microservice mall system

Directory structure specification

We also have our own directory structure

The birth of a springcloud microservice mall system

  • VO (view object): display layer object, usually the object transferred from the web to the template rendering engine layer.
  • Dto (data transfer object): data transfer object. The front end is like an object transferred in the background, similar to param.
  • Bo (business object): business object, internal business object. It is only transferred internally, not externally.
  • Model: model layer. This object corresponds to the database table structure one by one. The data source object is transmitted upward through mapper layer.
  • Controller: it is mainly used for forwarding external access control, verifying various basic parameters, or simple processing of non reusable businesses. For simplicity, some non transaction related code is also written here.
  • Feignclient: because microservices call each other, here is the interface for internal requests.
  • Controller: it is mainly used to forward internal access control, verify various basic parameters, or simply process non reusable services. For simplicity, some non transaction related code is also written here.
  • Service layer: a relatively specific business logic service layer.
  • Manager layer: general business processing layer, which has the following characteristics:

    • 1) For the layer encapsulated by the third-party platform, preprocess the return results and convert exception information to adapt to the upper interface.
    • 2) Sink the general capabilities of the service layer, such as caching scheme and middleware general processing.
    • 3) Interact with the Dao layer and reuse the combination of multiple Daos.
  • Mapper persistence layer: data access layer for data interaction with underlying mysql.
  • Task layer: because there are scheduled tasks between each service, such as regularly confirming receipt, regularly invalidating activities, etc., the tasks in this layer are actually connected toxxl-job(specific information can be viewed.)https://github.com/xuxueli/xx…)Task scheduling.
  • Listener: listenRocketMQProcessing, sometimes listeningeasyexcelRelevant data.

aboutFeignClient, because microservices call each other,FeignIt is HTTP protocol, which is theoretically for decoupling. In fact, when the provider interface is modified but the caller does not, it will cause exceptions, so we extract it. In addition, internally exposed interfaces are common in many places, so we also extracted a module from the interface for easy reference. Can seemall4cloud-apiUnder this module are all internalfeignInterface information.

Technology selection

technology edition explain
Spring Boot 2.4 MVC core framework
Feign 3.0 Service call
Nacos 2.0 Service registration and discovery
Seata 1.4 Distributed transaction
Mybatis 2.1 Persistence layer framework
hutool 5.5 Java Toolset
pagehelper 1.3 Mybatis paging plug-in
Redis 2.4 Distributed cache
RocketMQ 2.2 Message queue
canal 1.1 Database synchronization
Spring Cloud Gateway 3.0 gateway
Spring Cloud LoadBalancer 3.0 load balancing
ElasticSearch 7.9 Data search
minio 8.0 File upload
Knife4j 3.0 MVC framework integrates swagger to generate API documents
Element UI 2.13 UI framework
vue、uni-app vue2.6 JS framework

System architecture diagram

The birth of a springcloud microservice mall system

API address after mall deployment

service address
Mall4cloud gatway gateway service http://127.0.0.1:9000
Mall4cloud auth authorization verification service http://127.0.0.1:9101
Mall4cloud biz business code service (such as picture upload / SMS, etc.) http://127.0.0.1:9000
Mall4cloud leaf ID generation service based on meituan leaf http://127.0.0.1:9100
Mall4cloud multishop merchant service http://127.0.0.1:9103
Mall4cloud order order service http://127.0.0.1:9106
Mall4cloud payment payment service http://127.0.0.1:9113
Mall4cloud product goods and services http://127.0.0.1:9112
Mall4cloud RBAC user role service http://127.0.0.1:9102
Mall4cloud search search service http://127.0.0.1:9108
Mall4cloud user user service http://127.0.0.1:9105

Screenshot of code operation

1. Background screenshot

  • Platform end

    The birth of a springcloud microservice mall system

  • Shangjiaduan

    The birth of a springcloud microservice mall system

    The birth of a springcloud microservice mall system

2. Screenshot of uniapp

The birth of a springcloud microservice mall system

The birth of a springcloud microservice mall system

The pit has been trampled for a year. Don’t you spend five minutes understanding it

Your praise and encouragement is the driving force for us to move forward~

Your praise and encouragement is the driving force for us to move forward~

Your praise and encouragement is the driving force for us to move forward~

Let’s have a star

https://gitee.com/gz-yami/mal…

Recommended Today

Seven Python code review tools recommended

althoughPythonLanguage is one of the most flexible development languages at present, but developers often abuse its flexibility and even violate relevant standards. So PythoncodeThe following common quality problems often occur: Some unused modules have been imported Function is missing arguments in various calls The appropriate format indentation is missing Missing appropriate spaces before and after […]