SpringBoot+MQ+Redis+BootStrap spike system project framework construction

Project address: https://github.com/wannengdek/spring-boot-seckill

If the project is helpful to you, please help light up the small one.

Project introduction

To achieve the spike request, can resist the live high concurrent spike website.

How to solve it?

Page optimization

  1. Page caching, URL caching, object caching
  2. Page static, front-end and back-end separation
  3. Static resource optimization
  4. CDN optimization

Interface optimization

  1. Redis Pre-reduced Inventory Reduces Database Access
  2. Memory markup reduces Redis access
  3. RabbitMQ Queue Buffer, Order Asynchronously
  4. Accessing Nginx Horizontal Extensions
  5. Pressure measurement

Safety optimization

  1. Spike interface address hiding
  2. Mathematical Formula Verification Code
  3. Interface anti brush

Technical points:


Construction of Project Framework

Preliminary construction of spring boot + mybatis + thymeleaf can refer to this: https://blog.csdn.net/qq_41852212/article/details/96858050

Integrated Redis can view this: https://blog.csdn.net/qq_41852212/article/details/98475877

 

Whole project

The coding part is a temporary unused bag.

Encapsulate your own return structure

Class Result

<T> T means that the return value is a generic type, which returns whatever type of data it passes.

package spring.mooc.seckill.result;

public class Result<T> {
	private int code;
	private String msg;
	private T data;

	/**
	 * Successful calls
	 * */
	public static <T> Result<T> success(T data){
		return new  Result<T>(data);
	}
	
	/**
	 * Calls in the event of failure
	 * */
	public static <T> Result<T> error(CodeMsg cm){
		return new  Result<T>(cm);
	}
	
	private Result(T data) {
		this.code = 0;
		this.msg = "success";
		this.data = data;
	}
	
	private Result(CodeMsg cm) {
		if(cm == null) {
			return;
		}
		this.code = cm.getCode();
		this.msg = cm.getMsg();
	}

	public int getCode() {
		return code;
	}
	public String getMsg() {
		return msg;
	}
	public T getData() {
		return data;
	}
}

Return status code

CodeMsg adds as needed
package spring.mooc.seckill.result;

public class CodeMsg {
	private int code;
	private String msg;

	//Universal error codes
	public static CodeMsg SUCCESS = new CodeMsg(0, "success");
	public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "Server-side exception");
	public static CodeMsg BIND_ERROR = new CodeMsg(500101, "Parametric check exception:%s");
	//Login module 5002XX
	public static CodeMsg SESSION_ERROR = new CodeMsg(500210, "Session Not existing or invalid");
	public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500211, "The login password cannot be empty");
	public static CodeMsg MOBILE_EMPTY = new CodeMsg(500212, "The phone number can not be empty.");
	public static CodeMsg MOBILE_ERROR = new CodeMsg(500213, "Wrong phone number format");
	public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500214, "Mobile phone number does not exist.");
	public static CodeMsg PASSWORD_ERROR = new CodeMsg(500215, "Password error");

	//Commodity Module 5003XX

	//Order module 5004XX

	//Spike module 5005XX

	private CodeMsg( ) {
	}

	private CodeMsg( int code,String msg ) {
		this.code = code;
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}

	public CodeMsg fillArgs(Object... args) {
		int code = this.code;
		String message = String.format(this.msg, args);
		return new CodeMsg(code, message);
	}

	@Override
	public String toString() {
		return "CodeMsg [code=" + code + ", msg=" + msg + "]";
	}
}

 

 

 

 

Tags: Spring Redis github Database

Posted on Sat, 05 Oct 2019 17:57:20 -0700 by arion279