Micro-service-based Request Processing Method, Device, Electronic Device and Computer Storage Medium
The method simplifies microservices request handling by parsing HTTP requests and using pre-defined functions for efficient service processing, addressing inefficiencies in existing frameworks by enabling hot reloading and function-style development.
Patent Information
- Application Number
- CN202211199554.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-29
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2042-09-29
AI Technical Summary
The existing microservice technology has bloated engineering files and inefficient in the development and release process, especially the inconvenience of restarting the entire application in small and fast development applications.
Provides a microservice-based request processing method and device, which obtains the request path, parses the object, and calls preset execution functions to generate service response objects, and finally generates HTTP feedback messages, supports hot loading and functional development, simplifying the development process.
It improves the efficiency of microservice request processing, reduces dependence on bloated project files, supports hot loading and functional development, lowers the development threshold, and makes the transformation and release process more efficient.
Smart Images

Figure CN115580605B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of message processing, and particularly to a request processing method and device based on microservices. Background Art
[0002] With the development of computers, system functions have become increasingly complex, and the granularity of business splitting has become smaller and smaller to enhance its maintainability, reusability, etc. Therefore, more and more enterprises are transforming monolithic applications into microservice architectures. Thus, a huge system is split into different microservice subsystems, which are handed over to different project teams for maintenance to achieve the purposes of clear division of labor and inter-system reuse.
[0003] Currently, common microservice technologies use spring and dubbo in Java, flask and django in Python, etc. These frameworks have inconveniences in some aspects during development. First, a complete and bloated project file must be established. Even if only one interface is modified later, the entire project needs to be rebuilt. Second, when publishing, the entire application needs to be restarted, which is particularly inconvenient for small and fast-developed applications. Summary of the Invention
[0004] Aiming at the problems existing in the prior art, the main purpose of the embodiments of the present invention is to provide a request processing method and device based on microservices, to get rid of bloated project files and improve the efficiency of microservice request processing.
[0005] To achieve the above purpose, the embodiments of the present invention provide a request processing method based on microservices, and the method includes:
[0006] Obtain an HTTP request message sent by a client, and obtain a request path according to the HTTP request message;
[0007] Perform format parsing on the HTTP request message to obtain a parsing object, and obtain a service request object according to the request path and the parsing object;
[0008] According to the service request object, call and execute a pre-set execution function to obtain a service response object, and convert the service response object into HTTP response data;
[0009] Obtain an HTTP feedback message according to the HTTP response data, and send the HTTP feedback message to the client.
[0010] Optionally, in an embodiment of the present invention, obtaining a request path according to the HTTP request message includes:
[0011] Obtain the url address in the HTTP request message, and convert the slash separation in the url address into dot separation to obtain the request path.
[0012] Optionally, in an embodiment of the present invention, parsing the format of the HTTP request message to obtain a parsing object includes:
[0013] Obtain the content type value from the HTTP request message, and perform format parsing on the HTTP request message according to the content type value to obtain the parsing object.
[0014] Optionally, in an embodiment of the present invention, performing format parsing on the HTTP request message according to the content type value to obtain a parsing object includes:
[0015] If the content type value is the first preset value, perform key-value format parsing on the HTTP request message to obtain a key-value parsing object;
[0016] If the content type value is the second preset value, perform form format parsing on the HTTP request message to obtain a form parsing object.
[0017] Optionally, in an embodiment of the present invention, before calling and executing a pre-set execution function, the method further includes:
[0018] Determine the service file modification time corresponding to the service request object according to the request path in the service request object;
[0019] Perform a loading process on the service file corresponding to the service request object according to the service file modification time.
[0020] Optionally, in an embodiment of the present invention, calling and executing a pre-set execution function according to the service request object to obtain a service response object includes:
[0021] Call a pre-set execution function according to the service request object;
[0022] Use the parsing object in the service request object as a parameter to perform an execution process on the execution function to obtain a service response object.
[0023] Optionally, in an embodiment of the present invention, the execution function is pre-set in the following manner:
[0024] Define the entry function, parameters, and return value in the execution function according to the preset function definition rules;
[0025] Define the entry service class in the execution function according to the preset service definition rules.
[0026] An embodiment of the present invention further provides a request processing device based on microservices. The device includes:
[0027] The request message module is used to obtain the HTTP request message sent by the client and obtain the request path according to the HTTP request message;
[0028] The request object module is used to parse the format of the HTTP request message to obtain a parsed object, and obtain a service request object according to the request path and the parsed object;
[0029] The response data module is used to call and execute a preset execution function according to the service request object to obtain a service response object, and convert the service response object into HTTP response data;
[0030] The feedback message module is used to obtain an HTTP feedback message according to the HTTP response data and send the HTTP feedback message to the client.
[0031] Optionally, in an embodiment of the present invention, the request message module is further used to obtain the url address in the HTTP request message, and convert the slash separation in the url address into dot separation to obtain the request path.
[0032] Optionally, in an embodiment of the present invention, the request object module is further used to obtain the content type value from the HTTP request message, and parse the format of the HTTP request message according to the content type value to obtain a parsed object.
[0033] Optionally, in an embodiment of the present invention, the request object module includes:
[0034] The key-value parsing unit is used to perform key-value format parsing on the HTTP request message if the content type value is the first preset value to obtain a key-value parsing object;
[0035] The form parsing unit is used to perform form format parsing on the HTTP request message if the content type value is the second preset value to obtain a form parsing object.
[0036] Optionally, in an embodiment of the present invention, the device further includes:
[0037] The modification time module is used to determine the service file modification time corresponding to the service request object according to the request path in the service request object;
[0038] The file loading module is used to perform a loading process on the service file corresponding to the service request object according to the service file modification time.
[0039] Optionally, in an embodiment of the present invention, the response data module includes:
[0040] The execution function unit is used to call a preset execution function according to the service request object;
[0041] A response object unit, which is used to use the parsed object in the service request object as a parameter to execute the execution function and obtain a service response object.
[0042] Optionally, in an embodiment of the present invention, the device further includes:
[0043] A function definition module, which is used to define the entry function, parameters, and return value in the execution function according to a preset function definition rule;
[0044] A service definition module, which is used to define the entry service class in the execution function according to a preset service definition rule.
[0045] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the above method is implemented.
[0046] The present invention also provides a computer-readable storage medium, which stores a computer program for executing the above method.
[0047] The present invention also provides a computer program product, including a computer program / instructions. When the computer program / instructions are executed by a processor, the steps of the above method are implemented.
[0048] Through the parsing of the request message, the present invention combines a preset execution function to accurately and efficiently process service requests. At the same time, it simplifies the development process, gets rid of bloated engineering files, and improves the efficiency of microservice request processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained according to these drawings.
[0050] Figure 1 It is a flowchart of a request processing method based on microservices according to an embodiment of the present invention;
[0051] Figure 2 It is a flowchart of message format parsing in an embodiment of the present invention;
[0052] Figure 3 It is a flowchart of file loading in an embodiment of the present invention;
[0053] Figure 4 It is a flowchart of obtaining a service response object in an embodiment of the present invention;
[0054] Figure 5Flow chart of setting an execution function in an embodiment of the present invention;
[0055] Figure 6 Schematic structural diagram of a system applying a request processing method based on microservices in an embodiment of the present invention;
[0056] Figure 7 Request forwarding flow chart in an embodiment of the present invention;
[0057] Figure 8 UML class schematic diagram in an embodiment of the present invention;
[0058] Figure 9 Configuration synchronization schematic diagram in an embodiment of the present invention;
[0059] Figure 10 Schematic structural diagram of a request processing device based on microservices in an embodiment of the present invention;
[0060] Figure 11 Schematic structural diagram of a request object module in an embodiment of the present invention;
[0061] Figure 12 Schematic structural diagram of a request processing device based on microservices in another embodiment of the present invention;
[0062] Figure 13 Schematic structural diagram of a response data module in an embodiment of the present invention;
[0063] Figure 14 Schematic structural diagram of a request processing device based on microservices in still another embodiment of the present invention;
[0064] Figure 15 Schematic structural diagram of an electronic device provided in an embodiment of the present invention. Detailed implementation manners
[0065] The embodiments of the present invention provide a request processing method and device based on microservices, which can be used in the financial field and other fields. It should be noted that the request processing method and device based on microservices of the present invention can be used in the financial field and can also be used in any field other than the financial field. The application field of the request processing method and device based on microservices of the present invention is not limited.
[0066] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0067] Such as Figure 1The figure shows a flowchart of a request processing method based on microservices according to an embodiment of the present invention. The execution subject of the request processing method based on microservices provided by the embodiment of the present invention includes, but is not limited to, a computer. Through the parsing of the request message and the combination with a preset execution function, the present invention accurately and efficiently processes service requests, simplifies the development process, gets rid of bloated engineering files, and improves the efficiency of microservice request processing. The method shown in the figure includes:
[0068] Step S1, obtain the HTTP request message sent by the client, and obtain the request path according to the HTTP request message.
[0069] Among them, when the client initiates an HTTP request, specifically, it can obtain the HTTP request message of the client in real time by listening and using the TCP protocol (Transmission Control Protocol).
[0070] As an embodiment of the present invention, obtaining the request path according to the HTTP request message includes: obtaining the url address in the HTTP request message, and converting the slash separation in the url address into dot separation to obtain the request path. That is, converting the slash separation of the url address in the HTTP request message into dot separation as the request path of the microservice.
[0071] Step S2, perform format parsing on the HTTP request message to obtain a parsing object, and obtain a service request object according to the request path and the parsing object.
[0072] As an embodiment of the present invention, performing format parsing on the HTTP request message to obtain a parsing object includes: obtaining the content type value from the HTTP request message, and performing format parsing on the HTTP request message according to the content type value to obtain a parsing object.
[0073] In this embodiment, as Figure 2 shown, performing format parsing on the HTTP request message according to the content type value to obtain a parsing object includes:
[0074] Step S21, if the content type value is the first preset value, perform key-value format parsing on the HTTP request message to obtain a key-value parsing object;
[0075] Step S22, if the content type value is the second preset value, perform form format parsing on the HTTP request message to obtain a form parsing object.
[0076] Specifically, convert the HTTP request into a service request object and pass it to the request forwarding module. The conversion process is as follows: (1) Obtain the value of the ContentType in the HTTP header (content type value). If it is application / json, parse the request body in JSON format; if it is application / x-www-form-urlencoded, parse the request body in key-value pair format (the first preset value) and convert it into a dictionary object; if it is application / form-data, parse the request body in form format (the second preset value) and convert it into a dictionary object, and convert the files in it into UploadedFile objects; (2) Convert the slash separation of the url address into dot separation as the microservice request path; (3) Convert the parsed object and the request path into a service request object.
[0077] Step S3, according to the service request object, call and execute the pre-set execution function to obtain a service response object, and convert the service response object into HTTP response data.
[0078] Among them, before calling the execution function, it is necessary to perform a loading process on the service file. The specific process includes: convert the microservice request path of the service request object into the path where the microservice interface file (i.e., the service file) is located. Determine whether the file exists. If it does not exist, return "module not found". Obtain the modification time of the interface file when it was last loaded in the module loading table in the running memory. If it has never been loaded, directly load the interface file and record the modification date of the file in the module loading table. If the modification time at the last load is earlier than the current modification time, reload the interface file and update the modification date of the file in the module loading table record. If the modification time is the same as the last time, skip the loading.
[0079] Furthermore, when calling the pre-set execution function, determine whether there is a function with the preset name in the interface, such as a function named "execute". If it exists, directly call this function as the execution function. In addition, pass the service request object (SerrviceRequest) as a parameter, execute the called execution function, and obtain the return value. If the return value is not a ServiceResponse object, use the return value as the data of ServiceResponse. In addition, use the return value as the service response object.
[0080] Among them, convert the service response object into HTTP response data. The service response object includes a return code (code), a message (message), and data (data). The data is of dictionary or list type, and its value type can be all basic types and some platform internal objects.
[0081] Specifically, the conversion process is as follows: (1) Combine the return code, information, and data into a key-value pair form, that is, {"code": return code, "message": information, "data": data}; (2) Generate a JSON string from the key-value pair. The present invention uses an existing python library for conversion; (3) Use the JSON string as the response body of HTTP, set the header attribute ContentType to application / json, and set the HTTP status code to 200.
[0082] Step S4: Obtain an HTTP feedback message based on the HTTP response data, and send the HTTP feedback message to the client.
[0083] Among them, put the HTTP response data into the HTTP message to obtain the HTTP feedback message, and send the HTTP feedback message to the calling client.
[0084] As an embodiment of the present invention, as Figure 3 shown, before calling and executing a preset execution function, the method further includes:
[0085] Step S31: Determine the modification time of the service file corresponding to the service request object according to the request path in the service request object;
[0086] Step S32: Perform a loading process on the service file corresponding to the service request object according to the service file modification time.
[0087] Among them, before calling the execution function, it is necessary to perform a loading process on the service file. The specific process includes: Convert the microservice request path of the service request object into the path where the microservice interface file (i.e., the service file) is located. Determine whether the file exists. If it does not exist, return "module not found". Obtain the modification time of the interface file when it was last loaded in the module loading table in the running memory.
[0088] Further, if it has never been loaded, directly load the interface file and record the modification date of the file in the module loading table. If the modification time at the last load is earlier than the current modification time, reload the interface file and update the modification date of the file recorded in the module loading table. If the modification time is the same as the last time, skip the loading.
[0089] As an embodiment of the present invention, as Figure 4 shown, according to the service request object, calling and executing a preset execution function to obtain a service response object includes:
[0090] Step S41: Call a preset execution function according to the service request object;
[0091] Step S42: Use the parsing object in the service request object as a parameter to execute the execution function, and obtain a service response object.
[0092] Among them, when calling the pre-set execution function, it is judged whether there is a function with a preset name in the interface. If so, directly call this function as the execution function. In addition, pass the service request object (SerrviceRequest) as a parameter, execute the called execution function, and obtain the return value. If the return value is not a ServiceResponse object, use the return value as the data of ServiceResponse. In addition, use the return value as the service response object.
[0093] As an embodiment of the present invention, as Figure 5 shown, the execution function is pre-set in the following manner:
[0094] Step S51: Define the entry function, parameters, and return value in the execution function according to the preset function definition rules;
[0095] Step S52: Define the entry service class in the execution function according to the preset service definition rules.
[0096] Specifically, for example, the entry function name is execute, the parameter is the ServiceRequest object, and the return value is the ServiceResponse object. If data such as a string is returned, it is defaulted to the data content of the ServiceResponse object. Further, for example, the entry service class name is MainService, which inherits from ServiceProvider and must implement the execute method.
[0097] In a specific embodiment of the present invention, as Figure 6 shown is the schematic diagram of the system structure applying the request processing method based on microservices in the embodiment of the present invention. The present invention makes up for the defects in the prior art and provides a lightweight microservice design method that supports hot loading and functional development. When developing microservices, only interface files need to be written, without bloated project files. When modifying microservices, only a single interface file needs to be modified, and the entire project does not need to be rebuilt. When publishing microservices, there is no need to restart the entire application. After changing the interface file, the first call takes effect. The platform has formulated a microservice interface writing specification, simplifies the microservice interface code, is similar to function writing, reduces the development threshold, and pays more attention to business logic.
[0098] In view of the problems in the prior art, the system of the present invention provides a lightweight microservice design method that supports hot loading and functional development. The present invention is described by taking the Python language as an example, but it is also applicable to other languages. The specific implementation of the present invention includes eight parts: a Web access module, a request conversion module, a request forwarding module, a database module, a configuration synchronization module, a logging module, a node registration module, and a microservice interface. The dependencies between modules are as Figure 6 shown. The message format of the present invention adopts the JSON format (RFC 7159), but it is still valid for messages such as XML. JSON belongs to a lightweight data exchange format, which is convenient for developers to read, easy to parse and generate, and also supports cross-language conversion. The system shown in the figure includes:
[0099] Web access module: This module is used to listen for HTTP requests and process each HTTP call. Designing with flask based on the wsgi interface is an implementation example of the present invention, and it also belongs to the scope of the present invention for many popular frameworks such as django, fastAPI, and tornado. This module receives HTTP messages through the TCP protocol, extracts the information in the HTTP message, and for all messages related to URLs, it passes them to the request conversion module for processing. It also receives the processing results of the request conversion module, puts the response data into the HTTP message, and sends it to the calling client.
[0100] Request conversion module: This module is mainly responsible for converting data objects between the Web access module and the request forwarding module, and unifying the service request information. Therefore, the specific implementation of this module changes with the design of the Web access module. It includes:
[0101] 1. This module converts the HTTP request into a service request object (ServiceRequest, as Figure 8 shown), and passes it to the request forwarding module. The conversion operation is as follows:
[0102] Obtain the value of the HTTP header ContentType. If it is application / json, then parse the request body in JSON format; if it is application / x-www-form-urlencoded, then parse the request body in key-value pair format and convert it into a dictionary object; if it is application / form-data, then parse the request body in form format and convert it into a dictionary object, and convert the files in it into UploadedFile objects; convert the slash separation of the url address into dot separation as the microservice path; convert the parsed object and request path and other information into a service request object.
[0103] For example: Submit a = 1 and b = 2 to the address / api / service / example in the POST manner. Then, the microservice path is service.example, and the request data is the dictionary object {"a": "1", "b": "2"}.
[0104] 2. This module converts the service response object (ServiceResponse, as Figure 8 shown) into an HTTP response and returns the HTTP response to the Web access module. The service response object includes a return code (code), a message (message), and data (data). The data is of dictionary or list type, and its value type can be all basic types and some internal objects of the platform.
[0105] The conversion operation is as follows: Combine the return code, message, and data into key-value pairs (i.e., {"code": return code, "message": message, "data": data}); Generate a JSON string from the key-value pairs. The present invention uses an existing python library for conversion; Use the JSON string as the HTTP response body, set the header attribute ContentType to application / json, and set the HTTP status code to 200.
[0106] For example: If the return code is 0, the message is OK, and the data is {"x": "1"}, then the returned HTTP data is the string {"code": 0, "message": "OK", "data": {"x": "1"}}.
[0107] Request forwarding module: Implements the function of hot loading. This module forwards the service request (ServiceRequest) object to the corresponding microservice interface. By dynamically detecting whether the interface file has been modified, the hot loading of the interface file is achieved. As Figure 7 shown, its processing flow is as follows:
[0108] 1. Convert the microservice path of the service request object into the path where the microservice interface file is located. Determine whether the file exists. If it does not exist, return "module not found".
[0109] 2. Obtain the modification time of the interface file when it was last loaded in the module loading table in the running memory.
[0110] 3. If it has never been loaded, directly load the interface file and record the modification date of the file in the module loading table.
[0111] 4. If the modification time when it was last loaded is earlier than the current modification time, reload the interface file and update the modification date of the file recorded in the module loading table.
[0112] 5. If the modification time is the same as the previous time, skip the loading.
[0113] 6. Check if there is a function named "execute" in the interface. If so, directly call this function. Pass the service request object (SerrviceRequest) as a parameter and obtain the return value. If the return value is not a ServiceResponse object, use the return value as the data of ServiceResponse, then go to step 9. If not, go to step 7.
[0114] 7. Check if there is a MainService class in the interface. If not, return "Module entry not found" and end the request forwarding. Check if the MainService class inherits from ServiceProvider. If not, return "Incorrect entry type" and end the request forwarding.
[0115] 8. Construct a MainService object, call its before_execute method (functions in a class are called methods), then execute the execute method, and finally execute the after_execute method with the captured exception as the parameter. Take out the response value of the MainService object as the interface return value.
[0116] 9. Return the interface return value ServiceResponse object to the request conversion module.
[0117] Database module: This module uses connection pool technology to uniformly manage multiple types of database connections. Manage multiple connection pools by naming. For relational databases, we use the sqlalchemy library to establish a connection pool, the pymongo library to establish a connection pool for mongo databases, and the redis library in Python to establish a connection pool for redis databases.
[0118] When a microservice interface operates on the database, a database connection is retrieved from the corresponding database pool by a specific name. When the interface finishes operating on the data, the database is returned to the connection pool by the close function.
[0119] Configuration synchronization module: This module is used to synchronize the configuration files in the configuration center to this server and load them into the platform system. As Figure 9 shown, this invention takes the apollo configuration center as an example, and it is also effective for configuration centers such as Spring Cloud Config, Disconf, and Diamond. The configuration synchronization module is divided into: configuration pulling and configuration loading.
[0120] 1. The configuration pulling function caches the content from the server to the local file, and each server has a configuration pulling process. Before the platform starts, this function pulls the JSON configuration file corresponding to the project from the configuration center and stores it in the specified configuration directory. Then, every 300s (this value is the official recommended value), it obtains the version of the configuration through the server. Once the version is updated, it immediately caches it to the local file again to keep the file up-to-date.
[0121] 2. The configuration loading function loads the configuration from the local file into memory. A server has several working processes, and each working process has a configuration loading thread. This thread detects the local cache file. If the file is modified, it reads it again and updates the configuration in memory.
[0122] The configuration synchronization module implements a three-level configuration synchronization scheme, which reduces the pressure caused by each thread requesting the configuration center server and also reduces the performance loss during configuration synchronization.
[0123] The log recording module: This module is used to record the running logs of the platform and synchronize the server log files to the log management system for later maintenance and analysis. The present invention uses but is not limited to ELK as the log management system.
[0124] The log writing function is implemented using a log library. Using the logging library of python is an implementation example of the present invention, and the logger name uses the microservice path value separated by dots.
[0125] The log synchronization function uses the filebeat tool to periodically scan all log files in the log directory and synchronize the content changes to the ELK server. The filebeat configuration file is responsible for being pulled by the configuration synchronization module.
[0126] The node registration module: This module registers the current node machine server to the registration center to facilitate other servers to call the local service. In the implementation example of the present invention, nacos is used as the service registration center, and it is still valid for registration centers such as zookeeper and eurake. This module runs using an independent process and periodically sends heartbeat packets to the API interface of the registration center to indicate the health status of this node.
[0127] The microservice interface: It mainly implements the functional development style. The microservice application is the microservice interface developed by developers for implementing specific logical processing. The microservice interface has two writing styles. Each python script file has and only has one entry. The development form is similar to writing functions, and no microservice-related knowledge is required.
[0128] 1) Define the entry function: The name of the entry function is execute, with a parameter of the ServiceRequest object and a return value of the ServiceResponse object. If a string or other data is returned, it is defaulted to the data content of the ServiceResponse object. An example is shown in Table 1 below.
[0129] Table 1
[0130]
[0131] 2) Define the entry service class: The name of the entry service class is MainService, which inherits from ServiceProvider and must implement the execute method. An example is shown in Table 2 below.
[0132] Table 2
[0133]
[0134] Among them, the execute function is used for the main logical processing, without parameters and without a return value. The before_execute function is used for preprocessing operations before the execution of the logic, without parameters and without a return value. This function can be overridden to define personalized preprocessing. The after_execute function is used for cleanup operations after the execution of the logic. The parameter is error, indicating the exception triggered during the execution process. When no exception occurs, error is None. The return value is a boolean type, indicating whether the processing is completed. If it is true, the subsequent normal return is made. If it is false, the exception situation is fed back to the upper level until the return value is true or the request forwarding module is reached.
[0135] The present invention proposes a lightweight microservice design method that supports hot loading and functional development. Developers only need to write interface files without bloated project files. Adopting a functional writing style, the development process is simple and easy to learn, and more energy can be focused on the business logic itself. To upgrade and transform the interface, only a single script needs to be modified, and it can be independently managed and published without restarting the server and application.
[0136] The present invention parses the request message, combines it with a preset execution function, accurately and efficiently processes the service request, simplifies the development process, gets rid of bloated project files, and improves the microservice request processing efficiency.
[0137] As Figure 10 shown is a schematic structural diagram of a request processing device based on microservices according to an embodiment of the present invention. The device shown in the figure includes:
[0138] A request message module 10, configured to obtain an HTTP request message sent by a client and obtain a request path according to the HTTP request message;
[0139] A request object module 20, configured to parse the format of an HTTP request message to obtain a parsed object, and obtain a service request object according to the request path and the parsed object;
[0140] A response data module 30, configured to call and execute a preset execution function according to the service request object to obtain a service response object, and convert the service response object into HTTP response data;
[0141] A feedback message module 40, configured to obtain an HTTP feedback message according to the HTTP response data, and send the HTTP feedback message to the client.
[0142] As an embodiment of the present invention, the request message module 10 is further configured to obtain the url address in the HTTP request message, and convert the slash separation in the url address into dot separation to obtain a request path.
[0143] As an embodiment of the present invention, the request object module 20 is further configured to obtain a content type value from the HTTP request message, and perform format parsing on the HTTP request message according to the content type value to obtain a parsed object.
[0144] In this embodiment, as Figure 11 shown, the request object module 20 includes:
[0145] A key-value parsing unit 21, configured to perform key-value format parsing on the HTTP request message if the content type value is a first preset value to obtain a key-value parsed object;
[0146] A form parsing unit 22, configured to perform form format parsing on the HTTP request message if the content type value is a second preset value to obtain a form parsed object.
[0147] As an embodiment of the present invention, as Figure 12 shown, the apparatus further includes:
[0148] A modification time module 50, configured to determine the modification time of the service file corresponding to the service request object according to the request path in the service request object;
[0149] A file loading module 60, configured to perform a loading process on the service file corresponding to the service request object according to the service file modification time.
[0150] As an embodiment of the present invention, as Figure 13 shown, the response data module 30 includes:
[0151] An execution function unit 31, configured to call a preset execution function according to the service request object;
[0152] A response object unit 32, configured to use the parsed object in the service request object as a parameter to execute an execution function and obtain a service response object.
[0153] As an embodiment of the present invention, as Figure 14 shown, the device further includes:
[0154] A function definition module 70, configured to define an entry function, parameters, and return values in the execution function according to a preset function definition rule;
[0155] A service definition module 80, configured to define an entry service class in the execution function according to a preset service definition rule.
[0156] Based on the same application concept as the above-mentioned microservice-based request processing method, the present invention also provides the above-mentioned microservice-based request processing device. Since the principle of solving problems by this microservice-based request processing device is similar to that of a microservice-based request processing method, the implementation of this microservice-based request processing device can refer to the implementation of a microservice-based request processing method, and the repeated parts will not be elaborated.
[0157] The present invention parses the request message, combines a preset execution function, and accurately and efficiently processes service requests. At the same time, it simplifies the development process, gets rid of bloated engineering files, and improves the efficiency of microservice request processing.
[0158] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the above method is implemented.
[0159] The present invention also provides a computer program product, including computer programs / instructions. When the computer programs / instructions are executed by a processor, the steps of the above method are implemented.
[0160] The present invention also provides a computer-readable storage medium, which stores a computer program for executing the above method.
[0161] As Figure 15 shown, the electronic device 600 may further include: a communication module 110, an input unit 120, an audio processor 130, a display 160, and a power supply 170. It should be noted that the electronic device 600 does not necessarily have to include Figure 15 all the components shown in Figure 15 ; in addition, the electronic device 600 may further include
[0162] As Figure 15As shown, the central processing unit 100, sometimes also referred to as a controller or operation control, may include a microprocessor or other processor device and / or logic device. The central processing unit 100 receives inputs and controls the operation of various components of the electronic device 600.
[0163] Among them, the memory 140 can be, for example, one or more of a buffer, a flash memory, a hard drive, a removable medium, a volatile memory, a non-volatile memory, or other suitable devices. It can store the above information related to failures, and can also store programs for executing relevant information. And the central processing unit 100 can execute the programs stored in the memory 140 to achieve information storage or processing, etc.
[0164] The input unit 120 provides inputs to the central processing unit 100. The input unit 120 is, for example, a key or a touch input device. The power supply 170 is used to supply power to the electronic device 600. The display 160 is used to display display objects such as images and texts. The display can be, for example, an LCD display, but is not limited thereto.
[0165] The memory 140 can be a solid-state memory, for example, a read-only memory (ROM), a random access memory (RAM), a SIM card, etc. It can also be a memory that stores information even when powered off, can be selectively erased and has more data. An example of such a memory is sometimes referred to as an EPROM, etc. The memory 140 can also be some other type of device. The memory 140 includes a buffer memory 141 (sometimes referred to as a buffer). The memory 140 can include an application / function storage section 142, which is used to store application programs and function programs or the processes for operating the electronic device 600 through the central processing unit 100.
[0166] The memory 140 can also include a data storage section 143, which is used to store data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage section 144 of the memory 140 can include various drivers of the electronic device for communication functions and / or for performing other functions of the electronic device (such as a messaging application, an address book application, etc.).
[0167] The communication module 110 is a transmitter / receiver 110 that transmits and receives signals via the antenna 111. The communication module (transmitter / receiver) 110 is coupled to the central processing unit 100 to provide input signals and receive output signals, which can be the same as in the case of a conventional mobile communication terminal.
[0168] Based on different communication technologies, in the same electronic device, multiple communication modules 110 may be provided, such as a cellular network module, a Bluetooth module, and / or a wireless local area network module, etc. The communication module (transmitter / receiver) 110 is also coupled to a speaker 131 and a microphone 132 via an audio processor 130 to provide an audio output via the speaker 131 and receive an audio input from the microphone 132, thereby implementing general telecommunication functions. The audio processor 130 may include any suitable buffers, decoders, amplifiers, etc. Additionally, the audio processor 130 is also coupled to a central processor 100, enabling recording on the device through the microphone 132 and playing the sounds stored on the device through the speaker 131.
[0169] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program code.
[0170] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing devices to generate a machine, such that the instructions executed by the processors of the computer or other programmable data processing devices produce means for implementing the functions specified in Figure 1 one or more of the flows Figure 1 or multiple flows and / or blocks
[0171] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including instruction means that implement the functions specified in Figure 1 one or more of the flows Figure 1 or multiple flows and / or blocks
[0172] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus, so that a series of operation steps are performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby the instructions executed on the computer or other programmable apparatus provide steps for implementing the functions specified in one process or a plurality of processes and / or blocks Figure 1 one process or a plurality of processes and / or blocks Figure 1 steps for implementing the functions specified in one block or a plurality of blocks.
[0173] In the present invention, specific embodiments are used to elaborate the principles and implementation manners of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention. At the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A request processing method based on microservices, characterized in that The method includes: Obtain an HTTP request message sent by a client, and obtain a request path according to the HTTP request message; Perform format parsing on the HTTP request message to obtain a parsed object, and obtain a service request object according to the request path and the parsed object; Determine the modification time of the service file corresponding to the service request object according to the request path in the service request object, including: judging whether the service file corresponding to the service request object exists according to the request path in the service request object; if it exists, obtain the modification time when the service file was last loaded from the module loading table in the running memory as the modification time of the service file corresponding to the service request object; Perform a loading process on the service file corresponding to the service request object according to the modification time of the service file, including: if the modification time of the service file does not exist, perform a loading process on the service file corresponding to the service request object, and record the modification time of the service file in the module loading table; if the modification time of the service file exists and the modification time of the service file is earlier than the current modification time, perform a loading process on the service file corresponding to the service request object, and update the modification time of the service file in the module loading table; if the modification time of the service file exists and the modification time of the service file is the same as the current modification time, do not perform a loading process on the service file corresponding to the service request object; Call and execute a pre-set execution function according to the service request object to obtain a service response object, and convert the service response object into HTTP response data; Obtain an HTTP feedback message according to the HTTP response data, and send the HTTP feedback message to the client.
2. The method according to claim 1, characterized in that, The obtaining the request path according to the HTTP request message includes: Obtain the url address in the HTTP request message, and convert the slash separation in the url address into dot separation to obtain the request path.
3. The method according to claim 1, characterized in that, The performing format parsing on the HTTP request message to obtain a parsed object includes: Obtain a content type value from the HTTP request message, and perform format parsing on the HTTP request message according to the content type value to obtain the parsed object.
4. The method according to claim 3, wherein The performing format parsing on the HTTP request message according to the content type value to obtain a parsed object includes: If the content type value is a first preset value, perform key-value format parsing on the HTTP request message to obtain a key-value parsed object; If the content type value is a second preset value, perform form format parsing on the HTTP request message to obtain a form parsed object.
5. The method according to claim 1, wherein The calling and executing a pre-set execution function according to the service request object to obtain a service response object includes: Call a pre-set execution function according to the service request object; Use the parsed object in the service request object as a parameter to perform an execution process on the execution function to obtain the service response object.
6. The method according to claim 1, wherein The execution function is pre-set in the following manner: Define the entry function, parameters, and return value in the execution function according to the predefined function definition rules; Define the entry service class in the execution function according to the predefined service definition rules.
7. A request processing device based on microservices, characterized in that, The device includes: A request message module, configured to obtain an HTTP request message sent by a client, and obtain a request path according to the HTTP request message; A request object module, configured to perform format parsing on the HTTP request message to obtain a parsed object, and obtain a service request object according to the request path and the parsed object; A modification time module, configured to determine the modification time of the service file corresponding to the service request object according to the request path in the service request object, including: judging whether the service file corresponding to the service request object exists according to the request path in the service request object; if it exists, obtain the modification time when the service file was last loaded from the module loading table in the running memory as the modification time of the service file corresponding to the service request object; A file loading module, configured to perform a loading process on the service file corresponding to the service request object according to the modification time of the service file, including: if the modification time of the service file does not exist, perform a loading process on the service file corresponding to the service request object, and record the modification time of the service file in the module loading table; if the modification time of the service file exists and the modification time of the service file is earlier than the current modification time, perform a loading process on the service file corresponding to the service request object, and update the modification time of the service file in the module loading table; if the modification time of the service file exists and the modification time of the service file is the same as the current modification time, do not perform a loading process on the service file corresponding to the service request object; A response data module, configured to call and execute a pre-set execution function according to the service request object to obtain a service response object, and convert the service response object into HTTP response data; A feedback message module, configured to obtain an HTTP feedback message according to the HTTP response data, and send the HTTP feedback message to the client.
8. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, and the computer instructions are used to cause the processor to implement the method according to any one of claims 1 to 6 when executed.
Citation Information
Patent Citations
Method and system for processing CGI request in HTTP server
CN106453573A
HTTP client and data communication method
CN114697306A