Jixinda summary

system design

1. Why should we split api service server service manager service on jixinda platform? What functions do these three services correspond to?

A: because distributed design needs to be adopted, it needs to be split into three services. The services that need to be expanded by adopting a single architecture will include the manager background management function, while the manager has no concurrency and large amount of data, does not need horizontal expansion, and needs to be separated separately
The business complexity of api service is different from that of server service. api service only verifies the requested data. Server service really sends http requests to SMS service providers. It carries different data pressure and needs to be separated into two services

Database related

2. What are the database tables of jixinda platform, including channel and signature table, and what is the relationship between channel and template table? Write at least 5 tables

1)Blacklist table black_list
2)Channel table config
3)Channel signature intermediate table config_signature
4)Channel template intermediate table config_template
5)Signature form signature
6)Template table template
7)Manual table manual_process
8)Access platform table platform
9)Receive log table receive_log
10)Send log table receive_log
11)Regularly send task table timing_push

3. Provide channel id and signature id. how to query the channel corresponding to the channel and signature

	SELECT 
	  c.* 
	FROM
	  config c 
	  LEFT JOIN config_template ct 
		ON c.id = ct.config_id 
	  LEFT JOIN config_signature cs 
		ON c.id = cs.config_id 
	WHERE c.is_active = 1 
	  AND c.is_enable = 1 
	  AND c.is_delete = 1 
	  AND ct.template_id = 'Template id' 
	  AND cs.signature_id = 'autograph id' 
	ORDER BY c.level ASC 
or
 Use template id Query the channel template table to find the template id All corresponding channels id,Save through collection
	SELECT 
	  * 
	FROM
	  `config_template` 
	WHERE `template_id` = '' 
	
	Use signature id The signature can be found by querying the channel signature table id All corresponding channels id,Save through collection
	SELECT 
	  * 
	FROM
	  `config_signature` 
	WHERE `signature_id` = 'autograph id'
	
	Take the intersection of two sets, and take out the duplicate id,And according to these id Query the channel table to remove all deactivated, disabled and deleted channels
	SELECT 
	  * 
	FROM
	  `config` 
	WHERE id IN (
		In the set after taking the intersection id
	  ) 
	  AND is_active = 1 
	  AND is_enable = 1 
	  AND is_delete = 1 

Business related

4. Where does the API service finally store the data? B

A: In mysql, B:redis, C: rabbitMQ, D: send through HTTP client

5. Briefly introduce the business logic of api services?

A: verify the request of calling set Xinda, which has passed the following verification
1) Check if ak exists
2) Judge whether the access platform needs permission verification. If permission verification is enabled, compare the incoming verification value through ak,sk and timestamp encryption. If the verification value is the same as the encrypted ciphertext, prove that the identity passes, otherwise it fails
3) Judge whether the mobile phone number is empty, legal or not, and whether it is a list mobile phone number
4) Judge whether the template is empty, judge whether the signature is empty, and judge whether the signature template has a corresponding channel
5) Judge whether template parameters and template contents match

6. Why did the manager project finally send messages to redis

A: in order to improve performance, the server service will take the initiative to cache the data in mysql when the service is started. However, after the manager service modifies the content in the database, the data in the server service cache has not changed
You need to send a synchronous data message to the server service through redis, and the server service will re read the contents of the database into the cache, otherwise the contents in the cache will be inconsistent with those in the database

technology

7. How can the sdk be integrated into other people's systems?

because springboot During startup, only the corresponding packages under the startup class will be scanned, and our sdk The package path cannot be integrated with sdk Service adaptation needs to be utilized springboot Automatic assembly of
 stay resource Create under directory MATE-INF Catalog and write spring.factory catalogue
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.itheima.sdk.service.impl.SmsSendServiceImpl----Here is sdk Need to inject into ioc The full path of the class in the container

8. It is recommended that the handwriting singleton mode be designed as starving / enumerating / holder internal class mode, half points will be obtained, and full points will be obtained for lazy + DCL + volatile

Hungry Han style:
@Data
public class SingleCaseType {

private String name;

private Integer age;

//As long as the class is loaded, it creates objects and consumes memory
private static final SingleCaseType single = new SingleCaseType();

private SingleCaseType(String name, Integer age) {
	this.name = name;
	this.age = age;
}

private SingleCaseType() {
}

//Provide external methods for obtaining instances
public static SingleCaseType getInstance() {
	return single;
}

public static void main(String[] args) {
	SingleCaseType instance1 = SingleCaseType.getInstance();
	SingleCaseType instance2 = SingleCaseType.getInstance();
	System.out.println(instance1==instance2);
}

}

Lazy dcl + volatile:
public class SingleCaseType {

private String name;

private Integer age;

//As long as the class is loaded, it creates objects and consumes memory
private volatile static SingleCaseType single;


private SingleCaseType(String name, Integer age) {
	this.name = name;
	this.age = age;
}

private SingleCaseType() {
	
}

//Provide external methods for obtaining instances -- DCL confirmation is used here
public static SingleCaseType getInstance() {
	if(single==null) {
		synchronized (SingleCaseType.class) {
			if(single==null) {
				single = new SingleCaseType();
				return single;
			}else {
				return single;
			}
		}
	}else {
		return single;
	}
}

}

9. The execution sequence of filter, interceptor, controlleradvice, aspect and controller only considers the interception direction

Filter: filter
Interceptor: interceptor, managed by spring
aspect: slice our customized section. This is for the custom annotation
ControllerAdvice:Controller enhancement is mainly used for global exception interception and handling. Exceptions here can be custom exceptions or exceptions in JDK
Controller: our control layer

filter->interceptor->controllerAdvice->aspect->controller

10. Notification types in spring AOP

@Before				The notification method is executed before the target method is called
@After				The notification method will be called after the target method returns or abnormity.
@AfterReturning		The notification method will be called after the target method returns.
@AfterThrowing		The notification method will be invoked after the object method throws an exception.
@Around				The notification method encapsulates the target method

11. Why build such a SMS console in the project?

a) Peel off the duplicate code to form a middle console component, because if each service has to send SMS repeatedly, there will be a lot of duplicate code.
b) Once our SMS service provider is not easy to use, our SMS platform can automatically elect a new channel without stopping our system service

12. Talk about reflection?

First, let's talk about the reflection mechanism:
Reflection is that in the running state of the program, for any class, the properties and methods of the class can be obtained through specific methods, and these properties and methods can be called.
To put it bluntly, reflection is the function of obtaining and executing a class property or method when the program is running.

Next, let's talk about some common reflection related API s:
For example, get a class object. Class. Forname (full class name). Get the construction method of the class through the class object
Use the class object to create an object, such as class.newInstance.

Finally, we can talk about the advantages and disadvantages of reflection:
The advantage is to increase flexibility and dynamically obtain object instances at run time. The disadvantage is that reflection is inefficient and will destroy the encapsulation. Private methods of classes can be accessed through reflection, which is unsafe.

13. What is the difference between an interface and an abstract class?

Implementation: subclasses of abstract classes use extensions to inherit; The interface must be implemented using implements.
Constructor: abstract classes can have constructors; Interface cannot have.
Main method: an abstract class can have a main method, and we can run it; An interface cannot have a main method.
Implementation quantity: the class can implement many interfaces; However, only one abstract class can be inherited.
Access modifier: public modifier is used by default for methods in the interface; Methods in abstract classes can be arbitrary access modifiers
After Jdk8, static methods can be used in interfaces
13) Please explain the meaning of the three parameters messageErrorNum, configLevelFailNum and configBuildScale under the class SmsProperties in jixinda project? And why these three parameters?

messageErrorNum: the maximum number of failures of messages is less than the maximum number of messages for hot switching
configLevelFailNum: the maximum number of channel failures - true channel switching is performed when the number of failures is greater than configLevelFailNum
configBuildScale: startup ratio of channel election algorithm – channel election is conducted when the number of failures is greater than configLevelFailNum*configBuildScale

14. Briefly describe the implementation logic of timed SMS in the next project

Start a scheduled task:
1) redis distributed lock is used to prevent repeated SMS sending
2) Query the unprocessed (status=0) data from the time push table according to the time equivalent
3) According to the query results, call the SMS sending interface in turn and update the SMS sending status to processed ((status=1)

15. Describe the strategy pattern you used in the project? And give the reason for using the strategy pattern?

1) When the project starts, we initialize the policy class corresponding to each channel by implementing the CommandLineRunner interface, and each policy class implements a common abstract class
2) when we execute specific texting, we receive it through a common abstract class and then call the corresponding method through polymorphic thinking.

reason:
1) The policy mode complies with the opening and closing principle. It is closed for modification and open for extension.
2) Avoid using multiple conditional transition statements, such as if... else... Statements and switch statements

Keywords: Java

Added by lcy on Sat, 06 Nov 2021 11:19:00 +0200