Business processing method and device, electronic device, and storage medium
By obtaining the target business request in the service system and using the idempotent function to judge the lock, the problem of malicious requests in clustered deployment is solved, the high availability and security of the system are achieved, and the stability and efficiency of clustered deployment are improved.
Patent Information
- Application Number
- CN202111564288.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2041-12-20
AI Technical Summary
In clustered service systems, there are problems such as malicious tampering of tokens leading to excessive system load, repeated data submission leading to inefficiency, and increased system unreliability. Existing solutions cannot effectively prevent invalid requests and cannot be quickly and efficiently integrated into engineering projects.
By obtaining the target business request, determining the corresponding idempotent function, and using MySQL optimistic locking, Redission distributed locking, or Zookeeper distributed locking to determine whether to obtain the lock, if so, execute the business logic, otherwise return an exception message, and achieve non-invasive and fast access to the business system.
Effectively prevent malicious repeated requests, improve system high availability, high scalability and security, and make the clustered deployment of service systems safer, simpler and more stable.
Smart Images

Figure CN114398631B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of the Internet, and in particular to a business processing method and device, an electronic device, and a storage medium. Background Art
[0002] When the inpatient system is used in a clustered deployment, there are scheduled tasks within the service that need to call external systems for drug data, drug inventory, inspection items, and other information. The simultaneous execution of tasks on multiple nodes at the same time will cause duplicate drug catalog information in the hospital's pharmacy data; and in a weak network environment, when inpatient doctors check medical orders, form data is submitted repeatedly, and the prescribed drugs and inspection items under the orders are repeated, which will also result in a large amount of medical personnel costs to delete the duplicate data, thereby reducing staff efficiency, increasing time costs, and increasing system unreliability.
[0003] Existing service cluster deployment: A common solution is to use a token mechanism. When calling a service interface, the backend is first requested to generate a token, which is then stored in a cached redis-key and returned to the frontend. The frontend form submission must carry this token in the header to request the backend interface. This can cause users to maliciously tamper with a large number of tokens and concurrently request the backend interface, leading to excessive system load, a large number of useless keys in Redis for a short period of time, and even server unavailability. The existing annotation-based approach uses aspect-based thinking to intercept and verify the unique identifier before the target method is called. This also results in a large number of invalid unique identifiers in a short period of time, making customization and componentization impossible, and preventing fast and efficient integration into engineering projects. Summary of the Invention
[0004] The embodiment of the present application provides a business processing method for preventing malicious, large-scale, useless, and repeated business requests, efficiently improving the high availability, high scalability, and security of the system, making the clustered deployment of the service system safer, simpler, and more stable, and achieving configuration-based, non-invasive, and rapid access to the business system.
[0005] This embodiment of the present application provides a service processing method, including:
[0006] Get the target business request;
[0007] Determine an idempotent function corresponding to the target business request, and determine whether to obtain a lock corresponding to the target business request based on the idempotent function;
[0008] If so, execute the business logic corresponding to the target business request;
[0009] If not, return exception information.
[0010] In one embodiment, the idempotent function is based on MySQL optimistic locking;
[0011] The determining whether to obtain the lock corresponding to the target business request according to the idempotent function includes:
[0012] Create a table structure including primary key id and lock name;
[0013] Performing MD5 information digest calculation on the specified service parameters in the target service request to obtain a target identifier;
[0014] In the created lock record table structure, searching whether there is a lock record table entry corresponding to the target identifier; if so, determining that the lock corresponding to the target business request is not obtained;
[0015] If not, determine to obtain the lock corresponding to the target service request, and create a lock record table entry corresponding to the target identifier.
[0016] In one embodiment, the idempotent function is based on a Redission distributed lock;
[0017] The determining, based on the idempotent function, whether to obtain the lock corresponding to the target business request includes:
[0018] Performing MD5 information digest calculation on the specified service parameters in the target service request to obtain a target identifier;
[0019] Determine whether there is a lock corresponding to the target identifier according to the try lock interface in Redission;
[0020] If yes, determine to obtain the lock corresponding to the target business request;
[0021] If not, it is determined that the lock corresponding to the target service request is not obtained.
[0022] In one embodiment, the idempotent function is based on a Zookeeper distributed lock;
[0023] The determining, based on the idempotent function, whether to obtain the lock corresponding to the target business request includes:
[0024] Performing MD5 information digest calculation on the specified service parameters in the target service request to obtain a target identifier;
[0025] Determine whether there is a lock corresponding to the target identifier according to the acquire interface in Zookeeper;
[0026] If yes, determine to obtain the lock corresponding to the target business request;
[0027] If not, it is determined that the lock corresponding to the target service request is not obtained.
[0028] In one embodiment, determining the idempotent function corresponding to the target service request includes:
[0029] The idempotent function is determined according to the annotation configuration information corresponding to the target business request.
[0030] In one embodiment, the annotation configuration information includes a switch for extending the component;
[0031] Before obtaining the target service request, the method further includes:
[0032] The extension component is instantiated through the Spring framework to obtain the extension component annotated with the idempotent function.
[0033] In one embodiment, before instantiating the extension component through the Spring framework, the method further includes:
[0034] Load the component resource package of the extension component from the specified resource path of the spring framework;
[0035] Inject the configuration class information corresponding to the extension component.
[0036] The present application also provides a service processing device, including:
[0037] Request acquisition module, used to obtain target business requests;
[0038] A judgment module, configured to determine an idempotent function corresponding to the target service request, and determine whether to obtain a lock corresponding to the target service request based on the idempotent function;
[0039] A business logic execution module is used to execute the business logic corresponding to the target business request;
[0040] The exception information return module is used to return the exception information if no.
[0041] An embodiment of the present application further provides an electronic device, comprising:
[0042] processor;
[0043] a memory for storing processor-executable instructions;
[0044] The processor is configured to execute the above-mentioned business processing method.
[0045] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. The computer program can be executed by a processor to complete the above-mentioned business processing method.
[0046] The technical solution provided by the above-mentioned embodiments of the present application obtains the target business request; determines the idempotent function corresponding to the target business request, and judges whether the lock corresponding to the target business request is obtained based on the idempotent function; if so, executes the business logic corresponding to the target business request; if not, returns exception information, thereby preventing a large number of malicious and useless requests, and effectively improving the high availability, high scalability, and reusability of the system, making the clustered deployment of the service system safer, simpler, and more stable, and achieving configuration-based, non-invasive service and rapid access to the business system. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments of the present application.
[0048] Figure 1 A schematic diagram of the structure of an electronic device provided in one embodiment of the present application;
[0049] Figure 2 This is a flowchart of a business processing method provided by an embodiment of the present application;
[0050] Figure 3 This is a flowchart of a business processing method provided by an embodiment of the present application;
[0051] Figure 4 This is a block diagram of a service processing device according to an embodiment of the present application. DETAILED DESCRIPTION
[0052] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0053] Similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and should not be understood as indicating or implying relative importance.
[0054] In this application, the target business request is obtained, the idempotent function corresponding to the target business request is determined, and the idempotent function is used to determine whether the lock corresponding to the target business request is obtained. If so, the business logic corresponding to the target business request is executed; if not, an exception message is returned.
[0055] Figure 1This is a structural diagram of an electronic device provided in an embodiment of the present application. The electronic device can be used to execute the service processing method provided in an embodiment of the present application. Figure 1 As shown, the electronic device 100 includes: one or more processors 102, and one or more memories 104 storing processor-executable instructions, wherein the processor 102 is configured to execute the business processing method provided in the following embodiments of the present application.
[0056] The processor 102 can be a gateway, a smart terminal, or a device including a central processing unit (CPU), a graphics processing unit (GPU), or other forms of processing units with data processing capabilities and / or instruction execution capabilities. It can process data of other components in the electronic device 100 and control other components in the electronic device 100 to perform desired functions.
[0057] The memory 104 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), a hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 102 may execute the program instructions to implement the business processing method described below. Various applications and various data may also be stored in the computer-readable storage medium, such as various data used and / or generated by the application.
[0058] In one embodiment, Figure 1 The electronic device 100 may further include an input device 106, an output device 108, and a data acquisition device 110, which are interconnected via a bus system 112 and / or other forms of connection mechanisms (not shown). Figure 1 The components and structure of the electronic device 100 shown are merely exemplary and non-limiting. The electronic device may also have other components and structures as needed.
[0059] The input device 106 can be a device used by a user to input instructions, and can include one or more of a keyboard, a mouse, a microphone, and a touch screen. The output device 108 can output various information (e.g., images or sounds) to the outside (e.g., a user), and can include one or more of a display, a speaker, etc. The data acquisition device 110 can capture images of an object and store the captured images in the memory 104 for use by other components. For example, the data acquisition device 110 can be a camera.
[0060] In one embodiment, the various components in the example electronic device used to implement the business processing method of the embodiment of the present application can be integrated or dispersed, such as integrating the processor 102, memory 104, input device 106 and output device 108 into one, while separating the data acquisition device 110.
[0061] In one embodiment, the example electronic device used to implement the business processing method of the embodiment of the present application can be implemented as an intelligent terminal such as a smart phone, a tablet computer, a smart watch, a car-mounted device, etc.
[0062] Figure 2 This is a flow chart of a business processing method provided by an embodiment of the present application. Figure 2 As shown, the method may include the following steps S210-S240.
[0063] Step S210: Obtain a target service request.
[0064] The server receives the target service request. Target services, such as prescription services in the hospitalization system, are not limited here.
[0065] Step S220: Determine the idempotent function corresponding to the target service request, and determine whether the lock corresponding to the target service request is obtained based on the idempotent function. If yes, execute step S230; if not, execute step S240.
[0066] After receiving the target service request, the server determines the idempotent function corresponding to the target service request. Idempotent functions include idempotent implementation classes for MySQL, Redis, and Zookeeper. Based on the idempotent function, the server determines whether to obtain the lock corresponding to the target service request. Locks corresponding to the target service request include MySQL optimistic locks, Redis distributed locks, and Zookeeper distributed locks. If so, the server executes step S230; if not, the server executes step S240.
[0067] Step S230: Execute the business logic corresponding to the target business request.
[0068] According to step S220, it is determined whether the lock corresponding to the target business request is obtained according to the idempotent function. If so, the lock corresponding to the target business request is obtained and the business logic corresponding to the target business request is executed.
[0069] Step S240: Return exception information.
[0070] According to step S220, it is determined whether the lock corresponding to the target business request is obtained according to the idempotent function. If not, the lock corresponding to the target business request is not obtained, and an exception message is returned, indicating that there is an exception message of repeated submission, which is not limited here.
[0071] Figure 3 This is a flow chart of a business processing method provided by an embodiment of the present application. Figure 3 As shown, the method may include the following steps S310-S380.
[0072] Step S310: Load the component resource package of the extension component from the specified resource path of the Spring framework.
[0073] First, define a Spring Framework extension class, IdemConnectorBeanInject. Then, use the Spring Framework's spring.factory file to assemble org.springframework.boot.autoconfigure.EnableAutoConfiguration = xxx (extension class name). Based on the @EnableAutoConfiguration provided by the Spring Framework and the SPI extension provided by @EnableAutoConfiguration, use the Spring.Factory Loader abstract class to load the resource path META_INFO / spring.factories. Its static method loadFactories loads the component resource package of the extension component. The component resource package is the component JAR package, and the resource path is the storage address of the component JAR package, similar to the internal path, relative path, and absolute path addresses, which are not limited here.
[0074] Step S320: inject configuration class information corresponding to the extension component.
[0075] Inject the configuration information corresponding to the extension component. This configuration information includes: the extension component's creation connection entity class information, the component's host information, port number, account number, password, etc., as well as the management-related API implementation class injected into the corresponding extension component. API stands for Application Programming Interface.
[0076] Step S330: Instantiate the extension component through the Spring framework to obtain the extension component annotated with the idempotent function.
[0077] By adding the component switch prefix field xw-idempoent to the Spring framework and prefixing it with idempoent, the extension component is instantiated to obtain idempotent functions annotated with MySQL, Redis, and Zookeeper. These extension components include: is_print: Specifies whether to print logs; idempoent-name: Specifies the type of idempotent lock, including MySQL optimistic locks, Redis distributed locks, and Zookeeper distributed locks.
[0078] Step S340: Obtain the target service request. Please refer to the description of step S210 in the above embodiment for details, which will not be repeated here.
[0079] Step S350: Determine an idempotent function according to the annotation configuration information corresponding to the target business request.
[0080] Based on the annotation configuration information corresponding to the target business request, the annotation configuration information is @interfaceIdempotentLimit(functionname, int second, string des), where interface IdempotentLimit is the annotation name; functionname is the method name; int second is the number of requests within a certain timeframe. For example, if second = 5, only one request can be made within 5 seconds, and other requests will be filtered out. String des is the default value for quick response, indicating a quick response to repeatedly submitted exception messages. The annotation configuration information includes the switch for the extension component. Based on this annotation configuration information, the idempotent function is determined. This idempotent function includes the corresponding idempotent implementation classes for MySQL, Redis, and Zookeeper.
[0081] Step S360: Determine whether the lock corresponding to the target business request is obtained based on the idempotent function.
[0082] The idempotent function is used to determine whether the lock corresponding to the target business request has been obtained. Examples of locks corresponding to the target business request include MySQL optimistic locks, Redis distributed locks, and Zookeeper distributed locks. If the idempotent function determines that the lock corresponding to the target business request has been obtained, step S370 is executed. If the idempotent function determines that the lock corresponding to the target business request has not been obtained, step S380 is executed.
[0083] Step S370: Execute the business logic corresponding to the target business request.
[0084] Please refer to the description of step S230 in the above embodiment for details, which will not be repeated here.
[0085] Step S380: Return exception information.
[0086] Please refer to the description of step S240 in the above embodiment for details, which will not be repeated here.
[0087] In one embodiment, an idempotent MySQL function is based on a MySQL optimistic lock. Determining whether a MySQL optimistic lock corresponding to a target business request is obtained based on the idempotent MySQL function includes: creating a table structure including a primary key ID and a lock name; combining specified business parameters and a business method in the target business request to perform an MD5 message digest algorithm calculation to obtain a target identifier key; wherein the specified business parameters may be a method name and a request parameter name; in a created lock record table structure, performing a select * from fu_distribute_lock where lock_name=? for update query to determine whether a lock record table entry corresponding to the target identifier key exists; an effective time may be set in the lock record table entry; if so, determining that the MySQL optimistic lock corresponding to the target business request is not obtained; if not, determining that the MySQL optimistic lock corresponding to the target business request is obtained, and creating a lock record table entry corresponding to the target identifier.
[0088] In one embodiment, the idempotent function Redission is based on the Redission distributed lock; according to the idempotent function Redission, whether the lock Redission distributed lock corresponding to the target business request is obtained is determined, including: performing an MD5 information digest algorithm calculation on the specified business parameters in the target business request, where the specified business parameters can be a method name and a request parameter name, to obtain a target identification key; according to the try lock interface redisClient.try lock('key',TimeUnit unit) in Redission, it is determined whether a lock corresponding to the target identification key exists; if so, it is determined that the lock Redission distributed lock corresponding to the target business request is obtained; if not, it is determined that the lock Redission distributed lock corresponding to the target business request is not obtained.
[0089] In one embodiment, the idempotent function Zookeeper is based on the Zookeeper distributed lock; according to the idempotent function, it is determined whether the lock corresponding to the target business request is obtained, including: performing an md5 information digest algorithm calculation on the specified business parameters in the target business request, wherein the specified business parameters can be a method name and a request parameter name, to obtain a target identification key; according to the acquire interface zkClient.acquire('key',TimeUnit.SECONDS) in Zookeeper, it is determined whether there is a lock corresponding to the target identification key; if so, it is determined that the lock Zookeeper distributed lock corresponding to the target business request is obtained; if not, it is determined that the lock Zookeeper distributed lock corresponding to the target business request is not obtained.
[0090] The following is an embodiment of the device of the present application, which can be used to execute the above-mentioned business processing method embodiment of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the business processing method of the present application.
[0091] Figure 4 This is a block diagram of a service processing device according to an embodiment of the present application. Figure 4 As shown, the device includes a request acquisition module 410, a judgment module 420, a business logic execution module 430, and an abnormal information return module 440.
[0092] Request acquisition module 410, used to obtain target service request;
[0093] A determination module 420 is configured to determine an idempotent function corresponding to a target service request and determine whether a lock corresponding to the target service request is obtained based on the idempotent function;
[0094] The business logic execution module 430 is configured to execute the business logic corresponding to the target business request;
[0095] The exception information returning module 440 is used to return the exception information if no.
[0096] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned business processing method, and will not be repeated here.
[0097] In several embodiments provided in this application, the disclosed devices and methods may also be implemented in other ways. The device embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of the devices, methods, and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a portion of code, and the module, program segment, or a portion of code contains one or more executable instructions for implementing the specified logical functions. In some alternative implementations, the functions marked in the boxes may also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes may actually be executed substantially in parallel, or they may sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, may be implemented using a dedicated hardware-based system that performs the specified functions or actions, or may be implemented using a combination of dedicated hardware and computer instructions.
[0098] In addition, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0099] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
Claims
1. A business processing method, characterized in that: The method comprises: Get the target business request; Determine an idempotent function corresponding to the target business request, and determine whether to obtain the lock corresponding to the target business request based on the idempotent function; the idempotent function includes: corresponding idempotent implementation classes of Mysql, Redission, and Zookeeper; If so, execute the business logic corresponding to the target business request; If not, return exception information; The step of determining the idempotent function corresponding to the target service request includes: Determine the idempotent function according to the annotation configuration information corresponding to the target business request; Wherein, the annotation configuration information includes a switch for the extension component; Before obtaining the target service request, the method further includes: The extension component is instantiated through the Spring framework to obtain the extension component annotated with the idempotent function; wherein, the component switch pre prefix field xw-idempoent and idempoent are added to the Spring framework, and then the extension component is instantiated to obtain the extension component annotated with the idempotent function Mysql, Redission and Zookeeper, and the functions of the extension component include: adding whether to print logs and adding the type of idempotent lock; Before instantiating the extension component through the Spring framework, the method further includes: Load the component resource package of the extension component from the specified resource path of the spring framework; Inject the configuration class information corresponding to the extension component, the configuration class information includes: the creation connection entity class information of the extension component, the component's host information, port number, account number, password, and the management-related API implementation class injected into the corresponding extension component.
2. The method according to claim 1, characterized in that The idempotent function is based on Mysql optimistic lock; The determining whether to obtain the lock corresponding to the target business request according to the idempotent function includes: Create a table structure including primary key id and lock name; Performing MD5 information digest calculation on the specified service parameters in the target service request to obtain a target identifier; In the created lock record table structure, searching whether there is a lock record table entry corresponding to the target identifier; if so, determining that the lock corresponding to the target business request is not obtained; If not, determine to obtain the lock corresponding to the target service request, and create a lock record table entry corresponding to the target identifier.
3. The method according to claim 1, characterized in that The idempotent function is based on Redis distributed lock; The determining whether to obtain the lock corresponding to the target business request according to the idempotent function includes: Performing MD5 information digest calculation on the specified service parameters in the target service request to obtain a target identifier; Determine whether there is a lock corresponding to the target identifier according to the try lock interface in Redission; If yes, determine to obtain the lock corresponding to the target business request; If not, it is determined that the lock corresponding to the target service request is not obtained.
4. The method according to claim 1, wherein The idempotent function is based on Zookeeper distributed lock; The determining whether to obtain the lock corresponding to the target business request according to the idempotent function includes: Performing MD5 information digest calculation on the specified service parameters in the target service request to obtain a target identifier; Determine whether there is a lock corresponding to the target identifier according to the acquire interface in Zookeeper; If yes, determine to obtain the lock corresponding to the target business request; If not, it is determined that the lock corresponding to the target service request is not obtained.
5. A business processing device, characterized in that: include: Request acquisition module, used to obtain target business requests; A judgment module, configured to determine an idempotent function corresponding to the target service request, and determine whether to obtain a lock corresponding to the target service request based on the idempotent function; Idempotent functions include: corresponding idempotent implementation classes of MySQL, Redission, and Zookeeper; A business logic execution module is used to execute the business logic corresponding to the target business request; Exception information return module, used to return exception information if no; The step of determining the idempotent function corresponding to the target service request includes: Determine the idempotent function according to the annotation configuration information corresponding to the target business request; Wherein, the annotation configuration information includes a switch for the extension component; Before obtaining the target service request, the device is further configured to: The extension component is instantiated through the Spring framework to obtain the extension component annotated with the idempotent function; wherein, the component switch pre prefix field xw-idempoent and idempoent are added to the Spring framework, and then the extension component is instantiated to obtain the extension component annotated with the idempotent function Mysql, Redission and Zookeeper, and the functions of the extension component include: adding whether to print logs and adding the type of idempotent lock; Before instantiating the extension component through the spring framework, the device is further used to: Load the component resource package of the extension component from the specified resource path of the spring framework; Inject the configuration class information corresponding to the extension component, the configuration class information includes: the creation connection entity class information of the extension component, the component's host information, port number, account number, password, and the management-related API implementation class injected into the corresponding extension component.
6. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing processor-executable instructions; The processor is configured to execute the service processing method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and the computer program can be executed by a processor to complete the business processing method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Exponentiation processing method, device and equipment and storage medium
CN111625301A