Microservice generation method, device, terminal device and storage medium
By obtaining the configuration guidance list and calling the data interface to generate microservice files, the time-consuming and labor-intensive problem of basic microservice development is solved, and microservice files that meet business needs can be quickly generated.
Patent Information
- Application Number
- CN202010615146.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2040-06-30
AI Technical Summary
The existing technology has numerous script files for basic microservices, which makes the development and writing process time-consuming and labor-intensive, and cannot quickly meet the data structure requirements of different businesses.
By obtaining the configuration guide list, calling the data interface to obtain the target template, and parsing the microservice functions to generate microservice files, the data structure requirements of the business needs are met.
It reduces the time of rewriting script files each time a new system is developed, improves development efficiency and flexibility, and can quickly generate microservice files that meet business functions and data structures.
Smart Images

Figure CN111767095B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of R&D management technology, and in particular to a microservice generation method, apparatus, terminal device, and storage medium. Background Art
[0002] With the rapid development of the domestic economy, the rapid development, launch, and market penetration of systems for ever-changing product and business models have become core challenges in software product development. Currently, pre-generating basic services is essential during the development of these systems. However, these services must meet the requirements of different businesses, and the data structures they meet vary. Therefore, each time a new system is developed, the script files for the basic services must be rewritten to meet the business needs. The numerous script files for basic microservices require significant time and effort to develop and write, resulting in a time-consuming and labor-intensive development phase for these services. Summary of the Invention
[0003] In view of this, the embodiments of the present application provide a microservice generation method, apparatus, terminal device and computer-readable storage medium to solve the problem that the script files of basic microservices in the prior art are numerous, which require a lot of time and energy to develop and write, resulting in time-consuming and labor-intensive problems during the development of basic services.
[0004] A first aspect of an embodiment of the present application provides a microservice generation method, including:
[0005] Obtain a first configuration guide list, where the first configuration guide list is used to describe microservice framework information and microservice functions;
[0006] According to the microservice framework information described in the first configuration guide list, calling the first data interface to obtain the corresponding first target template;
[0007] Parsing the microservice function to obtain a second target template corresponding to implementing the microservice function;
[0008] The second target template is written into the reserved position of the first target template, and a corresponding microservice file is generated.
[0009] In one embodiment, calling a first data interface to obtain a corresponding first target template according to the microservice framework information described in the first configuration guide list includes:
[0010] According to the microservice framework information, obtaining first identification information that establishes an association relationship with the microservice framework information;
[0011] Calling the first data interface according to the first identification information; wherein the first data interface is used to establish an interface connection with the template library when called;
[0012] A first target template corresponding to the first identification information is obtained from the template library through the first data interface.
[0013] In one embodiment, parsing the microservice function to obtain a second target template corresponding to implementing the microservice function includes:
[0014] Parsing the microservice function to obtain a first data structure and first annotation information of the first data structure;
[0015] Obtaining a first functional module corresponding to the first data structure;
[0016] The first annotation information is written into the first functional module to generate a second target template corresponding to the microservice function.
[0017] In one embodiment, after writing the second target template into the reserved location of the first target template and generating a corresponding microservice file, the method further includes:
[0018] The first data structure is written into a database of the microservice file, so that when the microservice file is running, the login information of the user logging into the microservice can be written into the database according to the corresponding first data structure.
[0019] In one embodiment, the obtaining of the first functional module corresponding to the first data structure includes:
[0020] According to the first data structure, obtaining second identification information that establishes an association relationship with the first data structure;
[0021] The second data interface is called according to the second identification information to obtain the corresponding first functional module from the template library.
[0022] In one embodiment, after writing the second target template into the reserved location of the first target template and generating a corresponding microservice file, the method further includes:
[0023] Obtaining the modified microservice function, parsing the modified microservice function information to obtain a second data structure and second annotation information of the second data structure;
[0024] Obtaining a second functional module corresponding to the second data structure, and writing the second annotation information into the second functional module to generate a third target template;
[0025] According to the third target template, the second target template in the current microservice file is modified to generate a modified microservice file.
[0026] In one embodiment, after writing the second target template into the reserved location of the first target template and generating a corresponding microservice file, the method further includes:
[0027] Get the pre-set web page interface;
[0028] According to the interface specification of the web page interface, a connection is established between the microservice file and the web page interface; the web page interface is used to establish a connection between the microservice file and other microservice files, so that data transmission can be carried out between multiple microservice files.
[0029] A second aspect of an embodiment of the present application provides a microservice generation device, including:
[0030] A first acquisition module is used to acquire a first configuration guide list, where the first configuration guide list is used to describe microservice framework information and microservice functions;
[0031] A calling module, configured to call a first data interface to obtain a corresponding first target template according to the microservice framework information described in the first configuration guide list;
[0032] a parsing module, configured to parse the microservice function and obtain a second target template corresponding to the microservice function; the second target template is used to be written into the first target template to implement the microservice function;
[0033] A generation module is used to write the second target template into the reserved position of the first target template and generate a corresponding microservice file.
[0034] A fourth aspect of an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the terminal device, wherein when the processor executes the computer program, each step of the microservice generation method provided by the first solution is implemented.
[0035] A fifth aspect of an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps of the microservice generation method provided by the first solution.
[0036] The microservice generation method, apparatus, terminal device, and computer-readable storage medium provided by the embodiments of the present application have the following beneficial effects:
[0037] The embodiment of the present application provides a microservice generation method, which obtains a first configuration guide list pre-configured by the user, calls the corresponding first data interface to obtain a specified first target template from the template library based on the service framework information in the guide list, and obtains the corresponding second target template in the template library by parsing the microservice function. After writing the second target template to the reserved position of the first target template, the corresponding microservice file is generated, which can realize the data structure requirements that need to be met by the current microservice function. This solves the problem of needing to rewrite script files applicable to business functions and the data structures corresponding to business functions every time a new system is developed. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0039] Figure 1 This is a flowchart of a microservice generation method provided in an embodiment of the present application;
[0040] Figure 2 This is a flowchart of an implementation method of a microservice generation method provided by another embodiment of the present application;
[0041] Figure 3 This is a flowchart of a microservice generation method provided in another embodiment of the present application;
[0042] Figure 4 This is a structural block diagram of a microservice generation device provided in an embodiment of the present application;
[0043] Figure 5 This is a structural block diagram of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solutions and advantages of this application more clearly understood, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0045] The microservice generation method involved in the embodiments of the present application can be executed by a control device or terminal (hereinafter referred to as a "mobile terminal").
[0046] See also Figure 1 , Figure 1 A flowchart illustrating an implementation of a microservice generation method provided in an embodiment of the present application is shown.
[0047] S101. Obtain a first configuration guideline list, where the first configuration guideline list is used to describe microservice framework information and microservice functions.
[0048] In the application, the above-mentioned first configuration instruction list can be a table pre-set by the user and stored in the database. The terminal can generate the corresponding microservice files in sequence according to the first configuration instruction list stored in the database; or, the above-mentioned first configuration instruction list can be a first configuration instruction list formed according to the user's operation instructions when the user operates on the application interface of the terminal, and there is no limitation on this. The above-mentioned microservice framework information is used to describe the basic template information for generating microservices, and the template information used for different microservice framework information is different. The above-mentioned microservice functions include the functions that the generated microservices need to meet for the corresponding data structure at runtime. It can be pre-configured in the database or quickly generated according to the user's operation instructions, and there is no limitation on this.
[0049] Specifically, there is a generation tool for automatically generating microservices inside the terminal, and the application interface of the generation tool has all the microservice framework information and the microservice functions that need to be implemented. For example, the microservice framework information that needs to be generated includes but is not limited to whether single sign-on (Single Sign On, SSO) is supported and the basic functions of the technology type, whether the function of improving login authentication is improved, how long the login authentication is valid, etc. Exemplarily, for the above-mentioned service framework information that supports single sign-on, the technology type of single sign-on can be set to any one of keycloak type, jeesite type, and shiro type, without limitation. For the service framework information of the above-mentioned login authentication function, it has a temporary credential (Token), which represents the access rights of a single client to a specific resource. When generating a microservice according to the selected microservice framework information, it can have a login authentication function, and the generated microservice can manage client applications and manage Token services.
[0050] For example, if the microservice framework information supports single sign-on, users will need to provide their account and password when logging in through the generated microservice. Passwords are extremely private information, and many people use the same password for different accounts. Storing passwords in plain text in a database is highly insecure. The microservice function can then process the entered password based on whether the user has selected encryption. If encryption is selected, the password is encrypted using the corresponding encryption method.
[0051] For example, if the above-mentioned microservice framework information provides a login authentication function, then after the microservice has the login authentication function, the specific application scenario corresponding to the microservice can be as follows: the user uses the applet corresponding to the microservice in the terminal to upload user information to the generated microservice, and the microservice calls the application program interface (API) of the applet to decrypt and obtain user information (mobile phone number, ID number), and then queries the database to match the permission information. After the match is successful, the encrypted authentication information is generated according to the digital identity recognition framework (openId), and the encrypted authentication information is cached and returned to the terminal, which is saved by the terminal. Among them, the encrypted authentication information includes a token, a refresh token, and an APIKey (API KEY is an authorization method for interface access). Among them, the token is the credential for obtaining protected resources, and the validity period of its login authentication can be 1 hour or 1 day, which can be set according to the actual situation. The refresh token is used to refresh the token. The token and refresh token saved by the terminal can be used to continue logging in to access the server next time. By generating tools based on pre-configured service framework information, the microservice login authentication function is implemented. The currently popular token mechanism is used for authentication, and the time is written into the token to provide a login timeout service, which effectively guarantees the security of microservices.
[0052] S102: According to the microservice framework information described in the first configuration guide list, call a first data interface to obtain a corresponding first target template.
[0053] In applications, the first data interface can be an application program interface (API) for querying, recording, and indexing corresponding files. The first target template can be considered a target file, consisting of a code segment and a data segment. The code segment primarily contains program instructions and is generally readable and executable. The data segment primarily stores various global variables or static data used in the program and is generally readable, writable, or executable.
[0054] In the application, the above-mentioned first target template can be developed in advance by the developer and cached in the template library. When the microservice is generated, it can be obtained according to the corresponding microservice framework information. Among them, the acquisition method can be a one-to-one mapping relationship between the first data structure and the first target template, and the association relationship between each service framework information and the first data interface is pre-set. When the service framework information is obtained, the corresponding first data interface can be called according to the association relationship, and the storage location of the first target template can be found according to the mapping relationship for calling. Alternatively, the access path of the first data interface is pre-set, and the first data interface is given the function of obtaining files under the specified location. For example, when calling the first data interface, the terminal can query the storage location of the first target template according to the access path pre-set by the first data interface, and obtain it through the first data interface, and there is no limitation on this.
[0055] S103: Analyze the microservice function and obtain a second target template corresponding to the microservice function.
[0056] In the application, the above-mentioned parsing microservice function can be to parse the table content of the specified area in the first configuration guide list, and the information obtained is the microservice function. For example, if the encrypted cell in the table is in the first row and first column, the information in the cell under the second row and first column can be used to indicate whether the encryption function is selected. When parsing the microservice function in the form of a table, if the information obtained by parsing the code corresponding to the cell is "encrypt=Y", it means that the microservice function is to choose encryption, and if the information obtained by parsing the code corresponding to the cell is "encrypt=N", it means that the microservice function is to choose not to encrypt. Among them, "encrypt" is used to indicate that the current cell is a cell with encryption function, "Y" indicates that the microservice function is to encrypt the password, and "N" indicates that the microservice function is not to encrypt the password. In other examples, the microservice functions in the first configuration guide list can also be generated by tools in other forms and parsed, and there is no limitation on this.
[0057] In the application, when obtaining the second target template, the association between each microservice function and the remaining data interfaces can be pre-set, and the second target template stored in the specified path can be retrieved based on the data interface. This method can be consistent with the above-mentioned acquisition of the first target template and will not be described in detail. The second target template can also be considered a target file, which, like the first target template, can be composed of code segments and data segments.
[0058] S104: Write the second target template into the reserved position of the first target template, and generate a corresponding microservice file.
[0059] In the application, the above-mentioned microservice files include but are not limited to files that can be directly loaded and executed by the operating system, web interfaces that can be directly accessed and called by network protocols (http and / or https protocols), etc., and there is no limitation on this. For example, the microservice file can be a web interface, the interface specification of which corresponds to a Restful (a software architecture style that only provides a set of design principles and constraints) interface, which can be called by a Hypertext Transfer Protocol (HTTP) request. The code information (second target template) corresponding to the microservice function is written into the first target template by writing a file, and the code content in the first target template is modified to generate a microservice file corresponding to the microservice function. The above-mentioned reserved position is a placeholder position in the first target template. The parameter information is not entered in the position where the parameter should be assigned in the first target template. After the parameter information is obtained and passed in, it will replace the placeholder.
[0060] Exemplarily, for generating a user registration service (service framework information), the generation tool can first select a user registration template from the template library through the corresponding first data interface based on the customized user registration service. Then, based on the parsed customized data table structure (microservice function), after obtaining the microservice function marked with "registration function parameters", the corresponding code information (second target template) is obtained, and the data structure is automatically written into the position reserved for the user registration template (placeholder in the first target template) to generate a registration interface (user registration microservice file). Among them, the placeholder can be set in the form of "${parameter=A}", where A represents the script file of the registration function, and the script file of the registration function can be added at the position corresponding to A in the first target template. In addition, after generating the user registration interface, a unique ID can also be generated by the snowflake algorithm as the user's unique identifier to identify the user's registration information. The corresponding "registration function parameter" template or code information is placed in the reserved position in the user registration template, so that the generation tool can automatically complete the development of the interface to form an account registration interface.
[0061] As can be seen from the above, the present embodiment provides a microservice generation method, which obtains a first configuration guide list pre-configured by the user, calls the corresponding first data interface to obtain the specified first target template from the template library based on the service framework information in the guide list, and obtains the corresponding second target template in the template library by parsing the microservice function. After writing the second target template into the reserved position of the first target template, the corresponding microservice file is generated, which can realize the data structure requirements that need to be met by the current microservice function. This solves the problem of needing to rewrite the script file applicable to the business function and the data structure corresponding to the business function every time a new system is developed.
[0062] See also Figure 2 , Figure 2 This is a flowchart of a microservice generation method provided by another embodiment of the present application. Figure 1 Corresponding to the embodiment, the microservice generation method provided in this embodiment further includes steps S201 to S203 in step S101. The details are as follows:
[0063] S201. According to the microservice framework information, obtain first identification information that is associated with the microservice framework information.
[0064] In the application, the above-mentioned first identification information is unique identification information and is unique. The above-mentioned microservice framework information generally has multiple. Therefore, in order to distinguish each microservice framework information, it is necessary to pre-set the corresponding first identification information for the service framework information to uniquely identify it. After setting the microservice framework information, the user must pre-develop the first target module of the corresponding microservice framework information and cache it in the template library. The first identification information can be numbers, letters, or special symbols, without limitation.
[0065] S202. Call the first data interface according to the first identification information; wherein the first data interface is used to establish an interface connection with a template library when called.
[0066] In the application, the above-mentioned first data interface is also pre-associated with the first identification information, that is, the first data interface and the microservice framework information have the same first identification information. When there are multiple such associations, the multiple associations can be cached in the database in the form of a chart, wherein the association chart can be a table that records the association between each first identification information and the microservice framework. For example, the table is divided into microservice framework information cells, identification cells, first data interface cells, etc. Correspondingly, the corresponding microservice framework information is filled in the table, and the corresponding first identification information, first data interface, etc. are filled in the cells in the same row of the table in sequence.
[0067] S203: Acquire a first target template corresponding to the first identification information from the template library through the first data interface.
[0068] In the application, the specific steps of obtaining the first target template from the template library through the first data interface may refer to the description in S102 above, which will not be described in detail again.
[0069] As can be seen from the above, the microservice generation method provided in this embodiment can save the association relationship between microservice framework information, first identification information, and the first data interface by generating an association chart. Based on the association relationship, the first identification information can be easily obtained, and the first data interface can be quickly determined to obtain the first target template corresponding to the microservice framework information. At the same time, users can also update the association relationship in the association chart by adding, modifying, or deleting, for example, adding an association relationship between microservice framework information, first identification information, and the first data interface, to facilitate user management.
[0070] See also Figure 3 , Figure 3 This is a flowchart of a microservice generation method provided by another embodiment of the present application. Figure 1 Correspondingly, the microservice generation method provided in this embodiment further includes steps S301 to S303 in step S103. The details are as follows:
[0071] S301. Analyze the microservice function to obtain a first data structure and first annotation information of the first data structure.
[0072] In the application, after the microservice is generated, it needs to meet the corresponding requirements of the business functions and the data structure corresponding to the business. Specifically, the first data structure in the microservice function can be set in the form of a table, which can be divided into a main table and an appendix, wherein the main table includes necessary structural functions such as account number and password, and the appendix can select different data structures according to the actual business of the user (such as medical information appendix, user detailed information appendix, user education information appendix, etc.), and each corresponding appendix can choose to fill in the parameter name, parameter type, parameter size, whether it is required, whether to register the function parameter, whether to modify the function parameter, whether it can be modified, whether it is encrypted, whether the query is desensitized, etc. The above-mentioned first annotation information can be considered as information that explains the above-mentioned parameter name, parameter type, parameter size, whether it is required, whether to register the function parameter, whether to modify the function parameter, whether it can be modified, whether it is encrypted, whether the query is desensitized, etc. For example, for the first data structure of functions such as parameter name, parameter type, parameter size, the information in the parameter annotation is the first annotation information, and for the first data result of functions such as encryption and desensitization, the encryption method and desensitization method are the first annotation information. In other applications, the above-mentioned microservice function may also only include the first data structure without including the first annotation information, and this is not limited to this.
[0073] In an application, the table corresponding to the microservice can contain multiple data structures, and the information entered in the table is the first data structure corresponding to the current microservice function. That is, although the table contains options for multiple data structures, the microservice does not need to implement all the data processing functions in the table at runtime. The generation tool will only generate microservice functions corresponding to the first data structure selected by the user to implement data processing during the microservice runtime.
[0074] S302: Obtain a first functional module corresponding to the first data structure.
[0075] S303: Write the first annotation information into the first functional module to generate a second target template corresponding to the microservice function.
[0076] In the application, the above-mentioned first functional module is used to process the data input by the user when the microservice is running. Different businesses correspond to different types of data structures (medical information business, academic information business, etc.). Therefore, the microservices generated according to the configured first data structure also process the data input by the user differently. The above-mentioned method of obtaining the first functional module can be to pre-set the data interface of each first data structure, and set the function of the data interface to establish an interface connection with the template library when it is called, and set each data interface to obtain the file under the specified path in the template library, and correspond the file to the first functional module. In the application, if the above-mentioned first data structure does not have the corresponding first annotation information, the first functional module corresponding to the first data structure is the second target template.
[0077] For example, the generation tool generates a microservice function for "encryption" and a first annotation for "encryption method." The encryption method can be selected from a template library (for example, the template library pre-stores code information for multiple encryption methods, such as symmetric encryption and asymmetric encryption). Alternatively, the encryption method can be a specific encryption method code entered by the user in a form, which serves as the first annotation for the encryption function. This allows for encrypted storage and verification of the user's password when logging into the microservice, converting the password into an unreadable string. For example, for the encryption function, when the generation tool parses the data structure, it will obtain "encrypt=yes." "encrypt" indicates encryption, and the "encryption" script file (the first functional module) is retrieved and added to the reserved location of the first target template. The reserved location can be ${encrypt=A}, where A is used to write the encryption script file. The encryption method can be added in the reserved placeholder A, or a placeholder for the encryption method can also be present in the reserved location of the first target template, without limitation. Among them, for unencrypted data structures, a script file B that does not encrypt the password can also be written in the template library in advance, and when the data structure is not encrypted, the B script file is written to the location of the reserved placeholder A. There is no limitation on this.
[0078] From the above, it can be seen that the microservice generation method provided by this embodiment can pre-set the code information of various basic data structures that the microservice needs to process. When faced with data structures that need to be satisfied by different businesses, users can flexibly configure the first data structure of the data required to be processed by the microservice function, and then obtain the corresponding first functional module, and generate the second target module in combination with the configured first annotation information, so that the generated microservice can perform the above-mentioned functional processing on the data at runtime, without the need to rewrite the script file of the basic service required by the business data structure.
[0079] In one embodiment, after S104, the method further includes:
[0080] The first data structure is written into a database of the microservice file, so that when the microservice file is running, the login information of the user logging into the microservice can be written into the database according to the corresponding first data structure.
[0081] In the application, the above-mentioned database is used to store data information. Specifically, according to the microservice functions in the first guidance list configured by the user, the generation tool can first write the data table structures required for the microservice functions to be processed into the database in sequence. When the user logs in to the microservice, the microservice can save the user's registration information (account + password) in the database according to the corresponding data structure to record the user's registration information. That is, there will be a table with a first data structure in the database, which is used to fill in the user's registration information and process the registration information according to the annotation information. For example, the password is stored in the table in an encrypted manner. In addition, the microservice will also generate a user operation log table in the database to record the user's operation information. Among them, the operation log table includes but is not limited to services that record the user's addition, modification, deletion, search, etc. of the content of the first data structure stored in the database, and this is not limited to this.
[0082] In one embodiment, S302 includes:
[0083] According to the first data structure, obtaining second identification information that establishes an association relationship with the first data structure;
[0084] The second data interface is called according to the second identification information to obtain the corresponding first functional module from the template library.
[0085] In applications, the second identification information serves the same purpose as the first identification information, both being unique identification information. There are multiple first data structures. To distinguish each first data structure, each first data structure must be uniquely identified by pre-assigning corresponding second identification information. The second data structure is a user-developed general function code. The data segment within the code typically stores various global variables or static data used in the program. The various global variables within this data segment can be replaced based on the content of the first annotation information, or modified by the user based on actual circumstances.
[0086] In application, the relationship between the second data interface and the second identification information is consistent with the relationship between the first data interface and the first identification information, which will not be described in detail. They can all be stored in a correlation chart in a table form.
[0087] As can be seen from the above, the microservice generation method provided in this embodiment can generate and save the association relationship consistent with the above-mentioned microservice framework information, first identification information, and first data interface. Based on the association relationship, the first identification information can be successfully obtained, and the first data interface can be quickly determined to obtain the first target template corresponding to the microservice framework information. At the same time, users can also update the association relationship by adding, modifying, or deleting it in the association chart, for example, adding an association relationship between the first data structure, the first functional module, and the second data interface, to facilitate user management.
[0088] In one embodiment, after S104, the method further includes:
[0089] Obtaining the modified microservice function, parsing the modified microservice function information to obtain a second data structure and second annotation information of the second data structure;
[0090] Obtaining a second functional module corresponding to the second data structure, and writing the second annotation information into the second functional module to generate a third target template;
[0091] According to the third target template, the second target template in the current microservice file is modified to generate a modified microservice file.
[0092] In an application, the modified microservice functionality is defined as the modification of the previously generated microservice functionality to the required microservice functionality. This means that the data structure (first data structure) required by the previous microservice is modified so that it satisfies the remaining data structure (second data structure) during runtime.
[0093] In the application, the differences between the third target template and the second target template include but are not limited to: changes in data structure (addition of new data structure, deletion of data structure), unchanged data structure but changes in corresponding annotation information, etc., which are not limited to this.
[0094] For example, when modifying the second target template corresponding to the original microservice file, for an existing encryption function, if the second data structure is not encrypted, the generation tool will obtain "encrypt=no" when parsing the second data structure. The generation tool will then replace the encrypted script file added in the original reserved location. The modified second function template may be ${encrypt=B}, where B represents the script file that is not encrypted.
[0095] In this embodiment, by developing and modifying the original microservice file based on the parsed third target template, the repeated development of script files required for generating new microservices is reduced, the development time is reduced, and reliable microservice files are quickly generated.
[0096] In one embodiment, after S104, the method further includes:
[0097] Get the pre-set web page interface;
[0098] According to the interface specification of the web page interface, a connection is established between the microservice file and the web page interface; the web page interface is used to establish a connection between the microservice file and other microservice files, so that data transmission can be carried out between multiple microservice files.
[0099] In an application, if the generated microservice file is not a web interface that conforms to the RESTful interface specification, a separate connection can be established between the microservice file and the web interface. Specifically, as described above, a RESTful interface is an application programming interface that pre-defines the corresponding interface specifications (request protocol, request method, request parameters, return parameters, etc.). This web interface can be developed in advance by the user and dynamically stored in a database so that the generation tool can access it at any time.
[0100] In an application, when these microservice files need to connect to other microservice files, a data connection can be pre-established between the microservice file and a web interface according to the corresponding interface specifications (request protocol, request method), and then connected to other microservice files through the web interface. Data transmission between microservice files is achieved through the defined web interface, allowing one microservice to run while other microservice functions are also compatible.
[0101] In other applications, if there are multiple of the above-mentioned service framework information at the same time, there will also be multiple corresponding first target templates. In order to connect multiple first target templates to each other, a reference symbol can be added to the head or tail of each first target template and connected with the definition of the symbol in the remaining first target templates, so that all the first target templates become a unified whole that can be executed simultaneously by the operating system corresponding to the microservice.
[0102] In this embodiment, by providing a restful interface for the generated microservice file, the data transmission between the microservice files is interconnected through the defined web interface, so that the purpose of being compatible with running other microservice functions during the operation of one microservice is achieved. When an existing microservice file is developed, the connection is achieved through the web interface, reducing the development of unnecessary script files.
[0103] See also Figure 4 , Figure 4 This is a structural block diagram of a microservice generation device provided in an embodiment of the present application. In this embodiment, the mobile terminal includes various units for executing Figures 1 to 3 Each step in the corresponding embodiment. Please refer to Figures 1 to 3 as well as Figures 1 to 3 For the convenience of explanation, only the parts related to this embodiment are shown. Figure 4 The microservice generation device 100 includes: a first acquisition module 10, a calling module 20, a parsing module 30 and a generation module 40, wherein:
[0104] The first acquisition module 10 is used to obtain a first configuration guideline list, where the first configuration guideline list is used to describe microservice framework information and microservice functions.
[0105] The calling module 20 is used to call the first data interface to obtain the corresponding first target template according to the microservice framework information described in the first configuration guide list.
[0106] The parsing module 30 is used to parse the microservice function and obtain a second target template corresponding to the microservice function; the second target template is used to write into the first target template to implement the microservice function.
[0107] The generation module 40 is used to write the second target template into the reserved position of the first target template and generate a microservice file accordingly.
[0108] As an embodiment of the present application, the calling module 20 is further configured to:
[0109] According to the microservice framework information, obtaining first identification information that establishes an association relationship with the microservice framework information;
[0110] Calling the first data interface according to the first identification information; wherein the first data interface is used to establish an interface connection with the template library when called;
[0111] A first target template corresponding to the first identification information is obtained from the template library through the first data interface.
[0112] As an embodiment of the present application, the parsing module 30 is further configured to:
[0113] Parsing the microservice function to obtain a first data structure and first annotation information of the first data structure;
[0114] Obtaining a first functional module corresponding to the first data structure;
[0115] The first annotation information is written into the first functional module to generate a second target template corresponding to the microservice function.
[0116] As an embodiment of the present application, the microservice generation device 100 further includes:
[0117] The writing module is used to write the first data structure into the database of the microservice file, so that when the microservice file is running, the login information of the user logging into the microservice can be written into the database according to the corresponding first data structure.
[0118] As an embodiment of the present application, the parsing module 30 is further configured to:
[0119] The first receiving module is used to receive the modification instruction issued by the tester according to the test result.
[0120] According to the first data structure, obtaining second identification information that establishes an association relationship with the first data structure;
[0121] The second data interface is called according to the second identification information to obtain the corresponding first functional module from the template library.
[0122] As an embodiment of the present application, the microservice generation device 100 further includes:
[0123] The second acquisition module is used to obtain the modified microservice function, parse the modified microservice function information to obtain a second data structure, and second annotation information of the second data structure.
[0124] The third acquisition module is used to acquire the second functional module corresponding to the second data structure, and write the second annotation information into the second functional module to generate a third target template.
[0125] The modification module is used to modify the second target template in the current microservice file according to the third target template to generate a modified microservice file.
[0126] As an embodiment of the present application, the microservice generation device 100 further includes:
[0127] The fourth acquisition module is used to acquire a preset web page interface.
[0128] An establishment module is used to establish a connection between the microservice file and the web interface according to the interface specification of the web interface; the web interface is used to establish a connection between the microservice file and other microservice files, so that data transmission can be carried out between multiple microservice files.
[0129] It should be understood that Figure 4In the structural diagram of the microservice generation device shown, each unit / module is used to execute Figures 1 to 3 The steps in the corresponding embodiment, and for Figures 1 to 3 Each step in the corresponding embodiment has been explained in detail in the above embodiment. Figures 1 to 3 as well as Figures 1 to 3 The relevant descriptions in the corresponding embodiments will not be repeated here.
[0130] Figure 5 This is a structural block diagram of a terminal device provided by another embodiment of the present application. Figure 5 As shown, the terminal device 50 of this embodiment includes: a processor 51, a memory 52, and a computer program 53 stored in the memory 52 and executable on the processor 51, such as a program of the method. When the processor 51 executes the computer program 53, the steps in each embodiment of the method described above are implemented, such as Figure 1 S101 to S104 shown, or Figure 2 and Figure 3 Alternatively, the processor 51 executes the computer program 53 to implement the above Figure 4 The functions of each module / unit in the corresponding embodiment are, for example, Figure 4 For details on the functions of modules 10 to 40, please refer to Figure 4 The relevant descriptions in the corresponding embodiments are not repeated here.
[0131] Exemplarily, the computer program 53 may be divided into one or more units, which are stored in the memory 52 and executed by the processor 51 to complete the present application. The one or more units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution process of the computer program 53 in the terminal device 50. For example, the computer program 53 may be divided into a first acquisition unit, a first determination unit, a first adjustment unit, a second adjustment unit, and an execution unit, and the specific functions of each unit are as described above.
[0132] The turntable device may include, but is not limited to, a processor 51 and a memory 52. Those skilled in the art will understand that Figure 5 It is merely an example of the terminal device 50 and does not constitute a limitation on the terminal device 50. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the turntable device may also include input and output devices, network access devices, buses, etc.
[0133] The processor 51 may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0134] The memory 52 may be an internal storage unit of the terminal device 50, such as a hard disk or memory of the terminal device 50. The memory 52 may also be an external storage device of the terminal device 50, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 50. Furthermore, the memory 52 may include both an internal storage unit of the terminal device 50 and an external storage device. The memory 52 is used to store computer programs and other programs and data required by the turntable device. The memory 52 may also be used to temporarily store data that has been output or is about to be output.
[0135] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.
Claims
1. A microservice generation method, characterized in that: The method comprises: Obtain a first configuration guide list, where the first configuration guide list is used to describe microservice framework information and microservice functions; According to the microservice framework information described in the first configuration guide list, calling a first data interface to obtain a corresponding first target template; wherein the first data interface is an application program interface for querying, recording, and indexing corresponding files; Parsing the microservice function to obtain a second target template corresponding to the implementation of the microservice function includes: parsing the microservice function to obtain a first data structure and first annotation information of the first data structure; obtaining a first function module corresponding to the first data structure; writing the first annotation information into the first function module to generate a second target template corresponding to the microservice function; wherein the first annotation information is information explaining a parameter name, a parameter type, a parameter size, whether it is required, whether the function parameter is registered, whether the function parameter is modified, whether it is modifiable, whether it is encrypted, and whether the query is desensitized; Writing the second target template into the reserved position of the first target template to generate a corresponding microservice file includes: writing the code information corresponding to the microservice function into the first target template by writing a file, modifying the code content in the first target template, and then generating a microservice file corresponding to the microservice function, wherein the reserved position is a placeholder position in the first target template. If the parameter information is not entered in the position where the parameter should be assigned in the first target template, the placeholder will be replaced after the parameter information is obtained and passed in; After writing the second target template into the reserved location of the first target template and generating a corresponding microservice file, the method further includes: The first data structure is written into a database of the microservice file, so that when the microservice file is running, the login information of the user logging into the microservice can be written into the database according to the corresponding first data structure.
2. The microservice generation method according to claim 1, characterized in that: The calling a first data interface to obtain a corresponding first target template according to the microservice framework information described in the first configuration guide list includes: According to the microservice framework information, obtaining first identification information that establishes an association relationship with the microservice framework information; Calling the first data interface according to the first identification information; wherein the first data interface is used to establish an interface connection with the template library when called; A first target template corresponding to the first identification information is obtained from the template library through the first data interface.
3. The microservice generation method according to claim 1, characterized in that: The obtaining of the first functional module corresponding to the first data structure includes: According to the first data structure, obtaining second identification information that establishes an association relationship with the first data structure; The second data interface is called according to the second identification information to obtain the corresponding first functional module from the template library.
4. The microservice generation method according to claim 1, characterized in that: After writing the second target template into the reserved location of the first target template and generating a corresponding microservice file, the method further includes: Obtaining the modified microservice function, parsing the modified microservice function information to obtain a second data structure and second annotation information of the second data structure; Obtaining a second functional module corresponding to the second data structure, and writing the second annotation information into the second functional module to generate a third target template; According to the third target template, the second target template in the current microservice file is modified to generate a modified microservice file.
5. The microservice generation method according to claim 1, characterized in that: After writing the second target template into the reserved location of the first target template and generating a corresponding microservice file, the method further includes: Get the pre-set web page interface; According to the interface specification of the web page interface, a connection is established between the microservice file and the web page interface; the web page interface is used to establish a connection between the microservice file and other microservice files, so that data transmission can be carried out between multiple microservice files.
6. A microservice generation device, characterized in that: include: A first acquisition module is used to acquire a first configuration guide list, where the first configuration guide list is used to describe microservice framework information and microservice functions; A calling module, configured to call a first data interface to obtain a corresponding first target template according to the microservice framework information described in the first configuration guide list; wherein the first data interface is an application program interface for querying, recording, and indexing corresponding files; a parsing module, configured to parse the microservice function and obtain a second target template corresponding to the microservice function; the second target template is used to be written into the first target template to implement the microservice function; A generation module is used to write the second target template into the reserved position of the first target template and generate a corresponding microservice file, including: writing the code information corresponding to the microservice function into the first target template by writing a file, modifying the code content in the first target template, and then generating a microservice file corresponding to the microservice function, wherein the reserved position is a placeholder position in the first target template. If the parameter information is not entered in the position where the parameter should be assigned in the first target template, the placeholder will be replaced after the parameter information is obtained and passed in; The parsing module is also used to: Parsing the microservice function to obtain a first data structure and first annotation information of the first data structure; wherein the first annotation information is information explaining the parameter name, parameter type, parameter size, whether it is required, whether the function parameter is registered, whether the function parameter is modified, whether it is modifiable, whether it is encrypted, and whether the query is desensitized; Obtaining a first functional module corresponding to the first data structure; Writing the first annotation information into the first functional module to generate a second target template corresponding to the microservice function; The microservice generation device further includes: A writing template is used to write the first data structure into the database of the microservice file, so that when the microservice file is running, the login information of the user logging into the microservice can be written into the database according to the corresponding first data structure.
7. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Method for generating micro-service of intelligent equipment
CN109951564A
Software function expansion method and apparatus based on micro service architecture
WO2017067230A1