Rocketmq actual combat (Part I)

Time:2022-1-25

When expectations disappear, fear arises.

——Gracian

outline

Rocketmq actual combat (Part I)

Illustration

Case introduction

1. Business analysis

Simulate the [order] and [Payment] businesses in the shopping scenario of e-commerce websites

Rocketmq actual combat (Part I)

Illustration

(1) Place an order

The user requests the order system to place an order

The order system calls the order service to place an order through RPC

The order service calls the inventory service to deduct inventory

The order service calls the coupon service and deducts the coupon

Confirm the order after the order payment is completed

(2) Pay

User request payment system

The payment system calls the third-party payment platform API to initiate the payment process

After the user pays successfully through the third-party payment platform, the third-party payment platform will call back and notify the payment system

The payment system calls the order service to confirm the order

problem analysis

1. Distributed system downtime

The whole system is distributed deployment, including order system, commodity system and member system. The three systems complete the whole order placing process through RPC call. RPC call will lead to the coupling of systems in the order. If the member system goes down, it will lead to the unavailability of the order process.

How to decouple asynchronously:

Using rocketmq, after placing an order, the order system writes the “order message” into MQ as a producer, and the commodity system and member system act as the “order message” in MQ for consumer consumption. This can achieve the purpose of asynchronous decoupling. As long as the order system is normal, the order business can be carried out normally for users.

2. Data integrity

After the user submits the order, the inventory and coupons are deducted successfully, but the order confirmation operation fails (for example, payment fails), then the inventory and coupons need to be returned.

How to ensure data integrity?

After receiving the order confirmation failure notification, send a “confirmation failure message” to MQ

The commodity system and the member system listen to the “confirmation failure message” as consumers and return the corresponding business.

3. Invalid orders, peer attacks!

The user pays through the third party payment platform (Alipay, WeChat). If the order is placed, and it has not been paid for a long time, the order should be cancelled. Therefore, this place involves a time limited order scenario. If the system fails to pay successfully within 15 minutes, it will need to cancel the order and return the inventory and coupons.

4. Spike and rush buying peak process impact

Project code introduction

1. Project engineering

Rocketmq actual combat (Part I)

Illustration
Rocketmq actual combat (Part I)

Illustration
Rocketmq actual combat (Part I)

Illustration

2. Database

Rocketmq actual combat (Part I)

Illustration

(1) Order form

Rocketmq actual combat (Part I)

Illustration

(2) Commodity list

Rocketmq actual combat (Part I)

Illustration

(3) User table

Rocketmq actual combat (Part I)

Illustration

(4) Coupon form

Rocketmq actual combat (Part I)

Illustration

3. Framework and technology

The overall project is built with springboot and integrates mybatis. Maven relies on the following:

Rocketmq actual combat (Part I)

Illustration

Springboot integrates rocketmq and uses gson as a sequence tool for MQ sending and consumption

Rocketmq actual combat (Part I)

Illustration

In addition, use mybaits Gengerator reverse engineering to generate curd persistence layer code for the data table

Rocketmq actual combat (Part I)

Illustration
Rocketmq actual combat (Part I)

Illustration

Link:https://pan.baidu.com/s/1gCOLPI76hu1IJwLJnVOdfgExtraction code: rc2r

I amRaojiang_ Chi Meng, let persistence become a habit. Thank you for your:give the thumbs-upCollectionandcomment, I’ll see you next time!


Previous:Rocketmq common problem analysis and performance optimization

Next:Rocketmq actual combat (Part 2)

Recommended Today

Building the basic static page of Vue chat room

design sketch HTML: <template>     <view>         <view>             <scroll-view scroll-y=”true”>                 <div> <!– Message notification — >                     <div>                         <div>2021-12-28 16:50:00</div> < div > XXX processed this work order < / div >                     </div> <!– Left — >                     <!– <div></div> –> <!– Right — >                     <!– <div></div> –>               </div>               <div>                 <div>                     <image src=”../../static/logo.png”>                     <div>                         <div>2021-12-28 16:50:00</div> < […]