Method for efficiently accessing spring project to sentinel
The method addresses inefficiencies in integrating sentinel with Spring projects by using a source code analysis platform and AOP to manage sentinel resources, improving development efficiency and maintainability without altering the original code.
Patent Information
- Application Number
- CN202411365269.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2024-12-31
AI Technical Summary
Existing methods for integrating sentinel with a Spring project are inefficient and invasive, affecting code maintainability and development efficiency.
A method involving a project source code analysis platform to extract class and method data, configure sentinel resources, set downgrade policies, and implement aspect-oriented programming to manage sentinel resources without altering the original code, using AOP and a resource management platform.
Improves development efficiency by reducing the need for manual sentinel-related code, enhancing maintainability, and enabling intuitive resource management, while maintaining code integrity.
Smart Images

Figure CN119225799A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of spring project analysis, and specifically provides a method for efficiently accessing sentinel with a spring project. Background Art
[0002] The spring framework is an open source J2EE application framework initiated by Rod Johnson. It is a lightweight container for managing the life cycle of beans. Spring solves many common problems encountered by developers in J2EE development.
[0003] This solution is to perform source code analysis on the package path agreed upon by the sentinel project that needs to be connected, obtain the class method data in the project, manage the class method data of the acquired project through the resource management platform, determine which resources need to be defined by sentinel, and then configure the downgrade policy rules for it. In the connected spring project, define the package path agreed upon by the project as a cut point, add aspect programming for sentinel resource definition processing, obtain the resources defined by the project resource platform, and set them as sentinel resources in aspect programming. This non-invasive programming will not affect the original code, and can prevent the website from crashing, improve the maintainability of the code, and also improve development efficiency. At the same time, the sentinel resources are placed on the resource management platform, so that the resource information currently defined in the project can be more intuitively seen, so it needs to be improved. Summary of the invention
[0004] The purpose of the present invention is to provide a method for efficiently accessing a spring project to sentinel, so as to solve the problems raised in the above background technology.
[0005] In order to achieve the above purpose, the present invention provides the following technical solution: a method for efficiently accessing sentinel with a spring project, the specific steps are as follows:
[0006] Step 1: Implement a project source code analysis platform. The platform can pull the project source code through the project git address configured in step 2, and then obtain all available class and method data contained therein according to the analyzed source code package path value configured in the project. These data include class name, method name, annotation, method input parameters, etc. These raw data are analyzed, stored in a structured manner, and synchronized to the resource management platform;
[0007] Step 2: In the resource management platform, configure the project related information that needs to be connected to sentinel, such as setting the project name, project git address, source code analysis package path, etc. After the configuration is completed, the source code analysis platform can be notified in time to analyze the project source code content. The platform analyzes the project class method data transmitted in step 1, compares the data with the previous data analyzed for the project, and updates the class method data that are newly added, modified, or deleted;
[0008] Step 3: In the resource management platform, configure sentinel resources based on the class method data obtained by the project dimension, and set general resource degradation policy rules in the platform for different sentinel resources to set;
[0009] Step 4: According to the resources configured in step 3, you can set each resource to be enabled or offline, and you can also manually configure the downgrade operation for the enabled resources. After setting, synchronize the relevant information to the Apollo configuration center in time. The connected project monitors the data of the Apollo configuration center and can obtain the resource configuration information of the current project in time;
[0010] Step 5: In the connected project, obtain the effective resource information and downgrade configuration rule data from Apollo in step 4 through step 7, intercept the data request, and determine whether the current resource has a direct downgrade mark based on the resource information. If yes, execute step 6. Otherwise, execute the sentinel resource downgrade control logic. If the resource code module is abnormal and meets the downgrade rule, execute step 6. Otherwise, execute the resource business code normally.
[0011] Step 6: The sentinel resource of the project is downgraded. The business logic code of the resource is no longer executed. Instead, the unified downgrade logic processing is directly executed and returned to the calling end.
[0012] Step 7: Synchronize the resource and downgrade rule data defined in Apollo to the logic of the sentinel management module; take the package path configured in step 1 as the cut point, code resource rule control logic, including the logic code for unified processing of resource exception downgrade, and implement it through AOP aspect-oriented programming. Extract these codes and make a public jar file, which is placed in the Maven warehouse to facilitate the connected project to reference the dependency;
[0013] Step 8: In the project, after referencing the jar file and sentinel dependencies provided in step 7, developers do not need to write sentinel-related code. They only need to focus on writing their own business code and carry out normal business development. When a new function is iterated and launched, determine whether it is necessary to perform source code analysis on the launched project. If necessary, execute step 1. Otherwise, the business can be launched directly.
[0014] Preferably, the structured storage described in step 1 should be stored in categories, and the structured storage also needs to store the source codes of the same project together.
[0015] Preferably, the analysis of the project source code content in step 2 should be carried out by classifying and analyzing the source codes one by one. When analyzing the project source code content by classifying and analyzing, it should be noted that the projects cannot be messed up.
[0016] Preferably, the setting of the general resource degradation policy rules in step 3 should be synchronized with the degradation of the platform resources, and the setting of the general resource degradation policy rules also needs to be classified for degradation operations.
[0017] Preferably, the manual configuration downgrade operation described in step 4 requires the operator to carefully observe each resource information to prevent erroneous downgrade, and the manual configuration downgrade operation requires the operator to perform the downgrade operation in a short time.
[0018] Preferably, the intercepted data request in step 5 needs to be analyzed immediately, and the intercepted data request should be observed promptly to see whether there is a downgrade mark.
[0019] Preferably, in step 6, the business logic code of the resource that is no longer executed should directly delete the source code after downgrading, and the business logic code of the resource that is no longer executed should be analyzed and used after calling or changing the code.
[0020] Preferably, the preparation of the common jar file in step seven should classify the codes of different resources, and the preparation of the common jar file also requires different naming of the code files of different resources.
[0021] Preferably, in step eight, the judgment on whether source code analysis is required for the online project should be performed one by one and in an orderly manner. When judging whether source code analysis is required for the online project, care should be taken not to skip or omit analysis when analyzing one by one.
[0022] The beneficial effects of the present invention are as follows:
[0023] Through steps one and two, the source code under the project configuration package path is analyzed to obtain all its compliant class method data. These class methods provide data support for configuring sentinel resources and setting downgrade rules for the project, replacing developers to find the resource class methods that need to be defined in complex project codes, improving development efficiency, and operators can uniformly collect and downgrade the logic code, which can speed up resource processing and improve efficiency. Through steps three and four, the resource management platform can quickly define and configure sentinel resources for the project class methods, and set different downgrade strategies. At the same time, it can set enable or offline operations for each resource, and manually configure downgrade operations for enabled resources, which can dynamically control the sentinel resources of the project and avoid re-publishing the project. In the resource platform, the current resource data of the project and the current status of the resources can be viewed more intuitively. Developers can operate and control the resource data of the project more efficiently and conveniently. Synchronous downgrading with the platform resources can prevent omissions. Through steps five, six, seven and eight, for the connected projects, developers no longer need to write related code about defining resource rules for sentinel, avoiding coupling sent in business code. Inel related code, during the development process, developers only need to focus on their own business code, and no longer need to consider sent inel related logic code, which improves development efficiency. This method will not affect the original code and improves the maintainability of the code. In summary, through this method, the project is connected to sent inel, which reduces the access cost of the project. Developers do not need to find the class method that needs to define resources in the project, which reduces the configuration cost of sent inel resource rules and improves development efficiency. The resource rule logic code is woven in an aspect-oriented way through AOP, so that it is not coupled with the business code. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 It is a flowchart of the present invention. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0026] like Figure 1 As shown, the embodiment of the present invention provides a method for efficiently accessing a spring project to sentinel, and the specific steps are as follows:
[0027] Step 1: Implement a project source code analysis platform. The platform can pull the project source code through the project git address configured in step 2, and then obtain all available class and method data contained therein according to the analyzed source code package path value configured in the project. These data include class name, method name, annotation, method input parameters, etc. These raw data are analyzed, stored in a structured manner, and synchronized to the resource management platform;
[0028] Step 2: In the resource management platform, configure the project related information that needs to be connected to sentinel, such as setting the project name, project git address, source code analysis package path, etc. After the configuration is completed, the source code analysis platform can be notified in time to analyze the project source code content. The platform analyzes the project class method data transmitted in step 1, compares the data with the previous data analyzed for the project, and updates the class method data that are newly added, modified, or deleted;
[0029] Step 3: In the resource management platform, configure sentinel resources based on the class method data obtained by the project dimension, and set general resource degradation policy rules in the platform for different sentinel resources to set;
[0030] Step 4: According to the resources configured in step 3, you can set each resource to be enabled or offline, and you can also manually configure the downgrade operation for the enabled resources. After setting, synchronize the relevant information to the Apollo configuration center in time. The connected project monitors the data of the Apollo configuration center and can obtain the resource configuration information of the current project in time;
[0031] Step 5: In the connected project, obtain the effective resource information and downgrade configuration rule data from Apollo in step 4 through step 7, intercept the data request, and determine whether the current resource has a direct downgrade mark based on the resource information. If yes, execute step 6. Otherwise, execute the sentinel resource downgrade control logic. If the resource code module is abnormal and meets the downgrade rule, execute step 6. Otherwise, execute the resource business code normally.
[0032] Step 6: The sentinel resource of the project is downgraded. The business logic code of the resource is no longer executed. Instead, the unified downgrade logic processing is directly executed and returned to the calling end.
[0033] Step 7: Synchronize the resource and downgrade rule data defined in Apollo to the logic of the sentinel management module; take the package path configured in step 1 as the cut point, code resource rule control logic, including the logic code for unified processing of resource exception downgrade, and implement it through AOP aspect-oriented programming. Extract these codes and make a public jar file, which is placed in the Maven warehouse to facilitate the connected project to reference the dependency;
[0034] Step 8: In the project, after referencing the jar file and sentinel dependencies provided in step 7, developers do not need to write sentinel-related code. They only need to focus on writing their own business code and carry out normal business development. When a new function is iterated and launched, determine whether it is necessary to perform source code analysis on the launched project. If necessary, execute step 1. Otherwise, the business can be launched directly.
[0035] First, the operator needs to create a source code analysis platform. Then, the source code of the project can be pulled through the project's git address. At this time, the operator will be able to analyze the source code of the project, compare and modify the data based on the data after analyzing the source code, and at the same time, the operator can set different sentinel resources in the resource management platform. At this time, the operator can take each resource offline, and can also manually downgrade the resources. Then the operator collects all the resource codes that need to be downgraded and then performs a unified downgrade on the employee codes. This can speed up the operator's downgrade of the resource code, and then the processed code is placed in a public jar file, and then business development can be carried out normally.
[0036] Among them, the structured storage in step one should be stored in a classified manner, and the structured storage also requires that the source code of the same project be stored together.
[0037] Operators can store source code data in an orderly manner by classifying them. Storing source code of the same project together can also prevent file loss or confusion.
[0038] Among them, the analysis of the project source code content in step 2 should be classified and analyzed one by one. When analyzing the project source code content, it is necessary to pay attention to not messing up the project.
[0039] When operators classify and analyze source codes, they can analyze project source codes in an orderly manner. At the same time, when analyzing source codes of related projects, they must also be careful not to mess with other content.
[0040] Among them, step three sets the general resource degradation policy rules, which should be downgraded synchronously with the platform resources. When setting the general resource degradation policy rules, it is also necessary to classify and perform the downgrade operation.
[0041] Synchronous downgrading with the platform's resources can prevent operators from missing or making mistakes when downgrading. At the same time, classified downgrading can also reduce the operator's fault tolerance when downgrading.
[0042] Among them, the manual configuration downgrade operation in step 4 requires the operator to carefully observe each resource information to prevent accidental downgrade, and the manual configuration downgrade operation requires the operator to perform the downgrade operation in a short time.
[0043] The operator observes the information of each resource to prevent downgrading errors when downgrading the resources, which can improve the tolerance rate of downgrading. The operator downgrades in a short time to prevent delays. If the delay is too long, missed downgrading will occur.
[0044] Among them, the interception of data request in step five needs to be analyzed immediately, and the interception of data request should be observed in time to see whether there is a downgrade mark.
[0045] When a data request is intercepted, the operator should analyze the data as soon as possible. At this time, it is possible to promptly observe whether there is a degradation mark, and the operator can perform subsequent operations.
[0046] Among them, in step 6, the business logic code that no longer executes resources should directly delete the source code after downgrading, and the business logic code that no longer executes resources should be analyzed and used again after calling or changing the code.
[0047] The purpose of deleting the source code is to allow the caller to better identify whether the logic code needs to be downgraded. At the same time, the operator also needs to modify or upgrade the logic code before using it.
[0048] Among them, in step seven, the codes of different resources should be classified when making a public jar file. When making a public jar file, the code files of different resources also need to be named differently.
[0049] Categorizing different resource codes can prevent operators from confusing resources. At the same time, after naming the code files, operators can find resource codes more quickly and efficiently.
[0050] Among them, step eight determines whether it is necessary to perform source code analysis on the online project. The judgment and analysis operations should be performed one by one and in an orderly manner. When determining whether it is necessary to perform source code analysis on the online project, be careful not to skip or omit the analysis when analyzing one by one.
[0051] When operators analyze the source codes one by one, they can effectively speed up the judgment process and reduce the error rate in judging the source codes.
[0052] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0053] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for efficiently accessing sentinel in a spring project, characterized in that: The specific steps are as follows: Step 1: Implement a project source code analysis platform. The platform can pull the project source code through the project git address configured in step 2, and then obtain all available class and method data contained therein according to the analyzed source code package path value configured in the project. These data include class name, method name, annotation, method input parameters, etc. These raw data are analyzed, stored in a structured manner, and synchronized to the resource management platform; Step 2: In the resource management platform, configure the project-related information that needs to be connected to Sentinel, such as setting the project name, project git address, source code analysis package path, etc. After the configuration is completed, the source code analysis platform can be notified in time to analyze the project source code content. The platform analyzes the project class method data transmitted in step 1, compares the data with the previous data analyzed for the project, and updates the class method data that are newly added, modified, or deleted; Step 3: In the resource management platform, configure sentinel resources based on the class method data obtained by the project dimension, and set common resource degradation policy rules in the platform for different sentinel resources to set; Step 4: According to the resources configured in step 3, you can set each resource to be enabled or offline, and you can also manually configure the downgrade operation for the enabled resources. After setting, synchronize the relevant information to the apollo configuration center in time. The connected project listens to the apollo configuration center data and can obtain the resource configuration information of the current project in time; Step 5: In the connected project, obtain the effective resource information and downgrade configuration rule data in Apollo in step 4 through step 7, intercept the data request, and determine whether the current resource has a direct downgrade mark based on the resource information. If yes, execute step 6. Otherwise, execute the sentinel resource downgrade control logic. If the resource code module is abnormal and meets the downgrade rule, execute step 6. Otherwise, execute the resource business code normally. Step 6: The sentinel resource of the project is downgraded. The business logic code of the resource is no longer executed. Instead, the unified downgrade logic processing is directly executed and returned to the calling end. Step 7: Synchronize the resources and downgrade rule data defined in Apollo to the logic of the Sentinel management module; Take the package path configured in step 1 as the cut point, code resource rule control logic, including the logic code for unified processing of resource exception degradation, and implement it through AOP aspect-oriented programming. Extract these codes and make a public jar file, which is placed in the Maven repository to facilitate the connected project to reference the dependency. Step 8: In the project, after referencing the jar file and sentinel dependencies provided in step 7, developers do not need to write sentinel-related code. They only need to focus on writing their own business code and carry out normal business development. When new function iterations are launched, determine whether source code analysis is required for the launched project. If necessary, execute step 1. Otherwise, the business can be launched directly.
2. According to claim 1, a method for efficiently accessing sentinel in a spring project is characterized in that: The structured storage described in step 1 should be stored in categories, and the structured storage also needs to store the source codes of the same project together.
3. According to claim 1, a method for efficiently accessing sentinel in a spring project is characterized in that: The analysis of the project source code content described in step 2 should be classified and analyzed one by one. When analyzing the project source code content, it is necessary to pay attention to not messing up the projects.
4. According to claim 1, a method for efficiently accessing sentinel in a spring project is characterized in that: The setting of the general resource degradation policy rules in step 3 should be synchronized with the platform resources for degradation. The setting of the general resource degradation policy rules also needs to be classified for degradation operations.
5. According to claim 1, a method for efficiently accessing sentinel in a spring project is characterized in that: The manual configuration downgrade operation described in step 4 requires the operator to carefully observe each resource information to prevent accidental downgrade, and the manual configuration downgrade operation requires the operator to perform the downgrade operation in a short time.
6. According to claim 1, a method for efficiently accessing sentinel in a spring project is characterized in that: The interception data request described in step five needs to be analyzed immediately, and the interception data request should be observed promptly to see whether there is a downgrade mark.
7. According to claim 1, a method for efficiently accessing sentinel in a spring project is characterized in that: The business logic code of the resource that is no longer executed in step 6 should directly delete the source code after downgrading, and the business logic code of the resource that is no longer executed should be analyzed and used again after being called or the code is changed.
8. According to claim 1, a method for efficiently accessing a spring project to sentinel is characterized in that: The preparation of the common jar file described in step 7 should classify the codes of different resources. The preparation of the common jar file also requires different naming of the code files of different resources.
9. According to claim 1, a method for efficiently accessing sentinel in a spring project is characterized in that: In step eight, the judgment of whether it is necessary to perform source code analysis on the online project should be performed one by one and in an orderly manner. When judging whether it is necessary to perform source code analysis on the online project, care should be taken not to skip or omit the analysis when analyzing one by one.
