Micro-service field division method and device, electronic equipment and storage medium
By embedding proxy classes in business code to collect execution information and generate domain knowledge graphs, the long cycle problem caused by relying on developers' domain knowledge understanding ability is solved, and rapid domain division and microservice transformation are realized.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-17
- Publication Date
- 2026-03-27
AI Technical Summary
Existing technologies rely on developers' understanding of domain knowledge, resulting in long domain-driven design and microservice transformation cycles for software systems.
By obtaining request messages, the embedded proxy class collects execution information of the call relationship chain in the business code, generates a domain knowledge graph, and divides the domain according to the graph to achieve non-intrusive microservice decomposition.
It enables rapid domain partitioning, effectively shortening the domain-driven design cycle and microservice transformation cycle of software systems.
Smart Images

Figure CN116243910B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of computers, further to the field of microservices, and in particular to a microservice field division method and device, electronic equipment and storage medium. BACKGROUND
[0002] Domain-Driven Design (DDD) is mainly used to guide how to decouple a business system, divide a business module, define a business domain model and its interaction mode. The separated domain in the domain-driven design refers to separating domain objects and other functions in the system in the process of software development, avoiding confusion between domain knowledge and software technology-related concepts, so as to maintain domain knowledge in the software system and clearly microservice large systems. In related technologies, the event storm method is usually used for domain-driven design. This method relies on the understanding ability of the developers for the domain knowledge when dividing the domain model, which prolongs the domain-driven design cycle and the microservice transformation cycle of the software system. SUMMARY
[0003] The present disclosure provides a microservice field division method, device, electronic equipment and storage medium to at least solve the technical problem that the domain-driven design cycle and the microservice transformation cycle of the software system are long due to the reliance on the understanding ability of the developers for the domain knowledge when dividing the domain model in related technologies.
[0004] According to an aspect of the present disclosure, a microservice field division method is provided, comprising: obtaining a request message, wherein the request message is used to request access to a target microservice; embedding an agent class in a business code of the request message, wherein the agent class is used to collect execution information of a call relationship chain in the business code; obtaining the execution information by using the agent class; generating a domain knowledge graph based on the execution information, wherein the domain knowledge graph is a knowledge graph of a microservice field; performing domain division according to the domain knowledge graph to obtain a division result, wherein the division result is used to indicate microservice splitting of the target microservice.
[0005] According to a further aspect of the present disclosure, a microservice field division apparatus is provided, comprising: a first obtaining module configured to obtain a request message, wherein the request message is used to request access to a target microservice; an embedding module configured to embed a proxy class in a business code of the request message, wherein the proxy class is used to collect execution information of a call relationship chain in the business code; a second obtaining module configured to obtain the execution information by using the proxy class; a generating module configured to generate a field knowledge graph based on the execution information, wherein the field knowledge graph is a knowledge graph of a microservice field; and a division module configured to perform field division according to the field knowledge graph to obtain a division result, wherein the division result is used to indicate microservice-based splitting of the target microservice.
[0006] According to a further aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the microservice field division method proposed by the present disclosure.
[0007] According to a further aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to perform the microservice field division method proposed by the present disclosure.
[0008] According to a further aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein the computer program is used to enable a processor to perform the microservice field division method proposed by the present disclosure.
[0009] In the present disclosure, by obtaining a request message used to request access to a target microservice, then embedding a proxy class in a business code of the request message, obtaining execution information by using the proxy class, subsequently generating a field knowledge graph based on the execution information, and performing field division according to the field knowledge graph to obtain a division result, the purpose of quickly performing field division based on the request message is achieved, and the effect of effectively shortening the field-driven design cycle and the microservice-based transformation cycle of a software system is realized, thereby solving the technical problem that the field-driven design cycle and the microservice-based transformation cycle of a software system are relatively long due to the dependence on the understanding ability of a developer for field knowledge when performing field model division in the related art.
[0010] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the present disclosure, nor is it used to limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0011] The accompanying drawings are used to better understand the present scheme, and do not constitute a limitation on the present disclosure. Among them:
[0012] Figure 1 is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a microservice field division method according to an embodiment of the present disclosure;
[0013] Figure 2 is a flow chart of a microservice field division method according to an embodiment of the present disclosure;
[0014] Figure 3 is a schematic diagram of a microservice field division method according to an embodiment of the present disclosure;
[0015] Figure 4 is a schematic diagram of a proxy class starting process according to an embodiment of the present disclosure;
[0016] Figure 5 is a schematic diagram of a process of generating a field knowledge graph according to an embodiment of the present disclosure;
[0017] Figure 6 is a schematic diagram of a field knowledge graph unit according to an embodiment of the present disclosure;
[0018] Figure 7 is a schematic diagram of another microservice field division method according to an embodiment of the present disclosure;
[0019] Figure 8 is a schematic diagram of a field division process according to an embodiment of the present disclosure;
[0020] Figure 9 is a structure block diagram of a microservice field division apparatus according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0021] Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, which include various details of the embodiments of the present disclosure to help the understanding of the present disclosure. These should be considered in the context of the overall description and should not be considered limiting in nature. Thus, one of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of known functions and constructions are omitted in the following description for the sake of clarity and conciseness.
[0022] It should be noted that the terms "first", "second", and the like in the description and claims of the present disclosure and the above drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present disclosure described herein can be implemented in other than the order illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a list of steps or units does not necessarily limit those steps or units to the clearly listed ones, but can include other steps or units not clearly listed or inherent to such processes, methods, products or devices.
[0023] In the early stage of business, the functions of the software system are mostly very simple, and the common Create Read Update Delete (CRUD) functions can be implemented, and the software system at this time is clear. With the continuous iteration and evolution of the software system, the business logic becomes more and more complex, and the software system becomes more and more redundant, and different modules in the system are associated with each other, and it is difficult to clearly define the specific functions of each module. Therefore, when modifying a function, a lot of time is often spent on tracing the modification points required by the function, and the modification performed will also bring unpredictable impact.
[0024] Micro-service reconstruction is a basic paradigm in the current large project development and reconstruction, and most of the project research and development team will choose micro-service as the direction of system evolution in the process of design, selection, and reconstruction. The separation of fields in domain-driven design can clearly micro-service the large system.
[0025] In the related art, the domain-driven design is performed in an event storm manner. The event storm is an activity in the form of a flexible workshop aimed at exploring complex business fields in collaboration. This manner explores the most valuable places for improvement in the existing healthy business lines, explores the feasibility of new business models, and designs new services, thereby bringing ideal positive results for each participant, and can design clean and maintainable event-driven software to support rapidly developing business event storms. The adaptability of the event storm. The event storm allows project stakeholders with different backgrounds to communicate and exchange complex and interdisciplinary information, and can provide a new type of collaboration that crosses information silos and professional boundaries.
[0026] The event storm is generally organized by the technical director of the team, and first needs to switch the individual perspective to the role of a system designer, and the main focus is on the operation process of the software system in a specific scenario, and the details outside the system can be temporarily ignored; then the business object needs to be identified, the business object life cycle is analyzed, the aggregate root analysis is refined, the context and calling relationship are identified, and the software system can be micro-serviced by continuously identifying the business object and splitting the business model based on the event storm.
[0027] However, the existing domain-driven design method is more dependent on the understanding of the domain knowledge and the expert knowledge of the software developers when dividing the domain model. A big limitation of this method is that not all software developers are technical experts in the field, so the splitting of the business model by the software developers will not quickly reach a good running and decoupling state, thereby prolonging the period of domain-driven design and micro-service transformation of the system. At present, there is no effective solution to the above problems.
[0028] According to the embodiments of the present disclosure, a micro-service domain division method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described herein can be executed in an order different from that shown herein.
[0029] The method embodiments provided by the embodiments of the present disclosure can be executed in a mobile terminal, a computer terminal, or a similar electronic device. The electronic device is intended to represent various forms of digital computers, such as a laptop computer, a desktop computer, a workstation, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as a personal digital processor, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein. Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing the micro-service domain division method is shown.
[0030] As Figure 1As shown, the computer terminal 100 includes a computing unit 101 that can perform various appropriate actions and processes in accordance with a computer program stored in a read-only memory (ROM) 102 or a computer program loaded from a storage unit 108 into a random access memory (RAM) 103. Various programs and data required for the operation of the computer terminal 100 can also be stored in the RAM 103. The computing unit 101, the ROM 102, and the RAM 103 are connected to each other through a bus 104. An input / output (I / O) interface 105 is also connected to the bus 104.
[0031] A plurality of components in the computer terminal 100 are connected to the I / O interface 105, including: an input unit 106, such as a keyboard, a mouse, and the like; an output unit 107, such as various types of displays, speakers, and the like; the storage unit 108, such as a magnetic disk, an optical disk, and the like; and a communication unit 109, such as a network card, a modem, a wireless communication transceiver, and the like. The communication unit 109 allows the computer terminal 100 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.
[0032] The computing unit 101 can be various general and / or special-purpose processing components having processing and computing capabilities. Some examples of the computing unit 101 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, and the like. The computing unit 101 performs the microservice domain partitioning method described herein. For example, in some embodiments, the microservice domain partitioning method can be implemented as a computer software program that is tangibly embodied in a machine-readable medium, such as the storage unit 108. In some embodiments, part or all of the computer program can be loaded and / or installed on the computer terminal 100 via the ROM 102 and / or the communication unit 109. When the computer program is loaded into the RAM 103 and executed by the computing unit 101, one or more steps of the microservice domain partitioning method described herein can be performed. Alternatively, in other embodiments, the computing unit 101 can be configured to perform the microservice domain partitioning method by other any appropriate means, such as by means of firmware.
[0033] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transferring data and instructions to the storage system, the at least one input device, and the at least one output device.
[0034] It should be noted here that, in some optional embodiments, the above... Figure 1 The electronic device shown may include hardware elements (including circuitry), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware and software elements. It should be noted that... Figure 1 This is only one instance of a specific particular example, and is intended to illustrate the types of components that may exist in the aforementioned electronic devices.
[0035] Under the aforementioned operating environment, this disclosure provides, for example... Figure 2 The microservice domain partitioning method shown can be derived from... Figure 1 The computer terminal or similar electronic device shown is used for execution. Figure 2 This is a flowchart of a microservice domain partitioning method according to an embodiment of this disclosure, which can be executed by a server. Figure 2 As shown, the method may include the following steps:
[0036] Step S21: Obtain the request message, wherein the request message is used to request access to the target microservice;
[0037] The aforementioned request message can be a user request received by the backend service system. The backend service system is a software system, and the user request may specifically include the requested network path, the requested parameters, and the requested Hypertext Transfer Protocol (HTTP) method. The requested network path and HTTP method can be used to determine the code snippet corresponding to the target microservice. After receiving the user request, the backend service system processes it internally using business logic and ultimately returns a system response to the user.
[0038] Specifically, the request message contains multiple actions, so the business logic for processing the request message can be regarded as a link of multiple methods (method A, method B, method C, method D), and the link of multiple methods can specifically include a link of user requests, which can be used to map user requests to a code segment in the system; and a requested business process, which is used to process user requests such as adding shopping cart items and purchasing items. The system response response information can include any of the following: request message access success prompt information, error prompt information, wherein the error prompt information further includes an error code and the like.
[0039] Step S22, embedding an agent class in the business code of the request message, wherein the agent class is used to collect execution information of a call relationship chain in the business code;
[0040] Specifically, the business code of the request message is the business code of the backend service system for processing the request message, and the agent is a probe in the java (computer programming language) technology, which can be a java code. By injecting the java code into the business code of the backend service system for processing the request message, the execution information of the call relationship chain in the business code can be collected. The call relationship chain can describe the call relationship between multiple business logics in the backend service, for example, method A calls method B, method B calls method C, and method C calls method D.
[0041] Step S23, obtaining the execution information by using the agent class;
[0042] The execution information can specifically include at least one of the following: a method name, a method class name, and parameter information.
[0043] Step S24, generating a domain knowledge graph based on the execution information, wherein the domain knowledge graph is a knowledge graph in the microservice field;
[0044] Step S25, performing domain division according to the domain knowledge graph to obtain a division result, wherein the division result is used to indicate microservice division of the target microservice.
[0045] Figure 3 is a schematic diagram of a microservice domain division method according to an embodiment of the present disclosure, as shown in Figure 3As shown, in order to assist the code development team to carry out the field-driven design code reconstruction on the project which has been developed at present, in a typical backend service system, method A calls method B, method B calls method C, method C calls method D, the bytecode is injected into the system through the probe, and finally the domain knowledge graph of the system is generated to guide the micro-service and reconstruction of the large system. The embodiment of the disclosure adopts a non-invasive splitting method, automatically divides the fields through the agent and the domain knowledge graph, and the business team can continuously split the micro-service after the division, that is, split the service boundary, the bounded context and other information.
[0046] According to the above steps S21 to S25 of the disclosure, by obtaining the request message for requesting to access the target micro-service, further embedding the agent class in the business code of the request message, obtaining the execution information by using the agent class, then generating the domain knowledge graph based on the execution information, dividing the fields according to the domain knowledge graph, and obtaining the division result, the purpose of quickly dividing the fields based on the request message is achieved, the effect of effectively shortening the field-driven design cycle and the micro-service transformation cycle of the software system is realized, and thus the technical problem that the field-driven design cycle and the micro-service transformation cycle of the software system are long due to the dependence on the understanding ability of the developers for the field knowledge when dividing the field model in the related art is solved.
[0047] Optionally, the micro-service field division method of the embodiment of the disclosure can be but not limited to used in the field-driven design scene, and specifically can be the continuous micro-service splitting scene, that is, splitting the service boundary, the bounded context and other information, and the embodiment of the disclosure is not specifically limited.
[0048] The micro-service field division method of the above embodiment is further introduced below.
[0049] As an optional implementation, in step S22, embedding the agent class in the business code includes:
[0050] Step S221, determining the identification information of the target micro-service based on the request message;
[0051] Step S222, obtaining the call relationship chain through the identification information, wherein the call relationship chain is used to describe the call relationship between the methods of the plurality of classes in the business code;
[0052] Step S223, embedding the agent class in the call relationship chain in an aspect manner, wherein the aspect manner is used to cut the call relationship chain and embed the agent class at the cutting position.
[0053] Specifically, the identification information of the target microservice can be a package prefix of the current application service, for example, the package prefix is com.baidu.xxx, and the package prefix can be configured in a process environment. Further, the call relationship chain is obtained according to the package prefix of the current application service, so that the proxy class is embedded in the call relationship chain in an aspect manner.
[0054] Based on the above optional implementation, the identification information of the target microservice is determined based on the request message, and then the call relationship chain is obtained based on the identification information, and then the proxy class is embedded in the call relationship chain in an aspect manner. The aspect manner is used to cut the call relationship chain and embed the proxy class at the cutting position, so that the bytecode can be injected into the backend service system by the probe in a non-intrusive manner, so as to efficiently perform the domain model analysis of the system.
[0055] As an optional implementation, in step S222, obtaining the call relationship chain based on the identification information includes:
[0056] In step S2221, in response to the target microservice being in a starting state, all class files in the software system are scanned, wherein the software system is used to carry the target microservice;
[0057] In step S2222, a plurality of classes are obtained from all class files based on the identification information, and the call relationship chain is obtained.
[0058] Specifically, by adding the specified code package of the code analysis to the software system startup command developed using the Java language through a preset startup command, the package prefix of the current application service is configured in the process environment. Further, the code analysis tool automatically matches the class with the package prefix, and analyzes the project code structure through bytecode enhancement technology at the time of compilation. The code is enhanced on the method of each class of the software system, and the method name and class name of the calling party of the method in the software system are recorded, that is, the cascade relationship in the software system is recorded, so as to obtain the call relationship chain.
[0059] Based on the above optional implementation, in response to the target microservice being in a starting state, all class files in the software system are scanned, and then a plurality of classes are obtained from all class files based on the identification information, so that the call relationship chain can be efficiently obtained.
[0060] As an optional implementation, in step S223, the proxy class is embedded in the call relationship chain in an aspect manner, including:
[0061] In step S2231, the methods of the plurality of classes contained in the call relationship chain are determined;
[0062] In step S2232, the aspect method is used to cut the methods of the plurality of classes, and the proxy class is embedded before the methods of the plurality of classes.
[0063] Specifically, the aspect method is an aspect oriented programming (AOP), which can realize unified maintenance of program functions through pre-compilation and dynamic proxy at runtime, and is a derivative paradigm of functional programming. By using the AOP, each part of the business logic can be isolated, so that the coupling degree between the parts of the business logic is reduced, the reusability of the program is improved, and the development efficiency is improved.
[0064] Based on the optional implementation, the methods of the plurality of classes contained in the call relationship chain are determined, and then the aspect method is used to cut the methods of the plurality of classes, and the proxy class is embedded before the methods of the plurality of classes, so that the development efficiency is further improved, and the time consumption of the domain driven design is reduced.
[0065] As an optional implementation, the micro-service domain division method of the embodiment of the disclosure further includes:
[0066] In step S231, the proxy class is generated based on the plurality of classes, and it is verified whether the collection method of the proxy class is in an available state;
[0067] In step S232, in response to the fact that the proxy class has been generated and the collection method is in the available state, it is determined that the proxy class is started and completed, so as to obtain the execution information.
[0068] Specifically, when the plurality of classes in the scanned class files are classes under the specified code package name, the aspect proxy method is generated based on the plurality of classes, and it is verified whether the collection method of the proxy class is in an available state. When the aspect proxy method has been generated and the collection method is in the available state, it can be determined that the proxy class is started and completed. During the scanning of the class files, the scanning based on the wildcard is supported, so that the constant information and the exception processing information in the system can be accurately excluded, and the noise in the information collection process is reduced. For example, the wildcard is generally “*”, and com.baidu.xxx.* can match all package paths of com.baidu.xxx.{any letter}. Generally, the utility class belongs to the same package, so the package information of the utility class can be excluded through the wildcard, so that the accuracy of the collected information is improved.
[0069] Figure 4 FIG. 2 is a schematic diagram of a starting process of a proxy class according to the embodiment of the disclosure, as shown in Figure 4As shown, after the target microservice is started, all class files in the software system are scanned, a plurality of classes are obtained from all class files based on the identification information, it is judged whether the plurality of classes are classes under the specified code package name, if not, the processing is ignored; if yes, a proxy class is generated based on the plurality of classes, and it is verified whether the collection mode of the proxy class is in an available state, which can be specifically verified by verifying whether the collection mode can return a usable status code from the target microservice. After the proxy class is generated and the collection mode is in the available state, it is determined that the proxy class is started.
[0070] Based on the above optional implementation, by generating a proxy class based on a plurality of classes and verifying whether the collection mode of the proxy class is in an available state, and then determining that the proxy class is started in response to the proxy class being generated and the collection mode being in the available state, the execution information is obtained, so that the rapid start of the proxy class can be realized.
[0071] As an optional implementation, in step S24, generating the domain knowledge graph based on the execution information includes:
[0072] In step S241, the execution information obtained by the proxy class is imported according to a preset information collection mode, wherein the preset information collection mode includes one of the following: file writing mode, socket mode, and message queue mode.
[0073] In step S242, the execution information is analyzed by a knowledge graph to generate a domain knowledge graph.
[0074] Specifically, the code analysis tool will automatically write the analysis result into a specified file, for example, a text type file, and after the system completes a full function test, the analysis result file can be extracted as the basis for subsequent domain driven design, at which time the analysis tool can be removed from the production environment to prevent affecting the running performance of the system. In addition to the above-mentioned file writing mode for collecting execution information, performance-insensitive services can use message queues and other methods to continuously obtain execution information.
[0075] Figure 5 is a process diagram for generating a domain knowledge graph according to an embodiment of the present disclosure, as shown in Figure 5 As shown, when collecting execution information, the proxy class can be obtained by any one of the file writing mode, the socket mode, and the message queue mode, and further knowledge graph analysis is performed on the execution information to generate a domain knowledge graph.
[0076] In the file writing mode, the agent stores the call chain embedded in the software system into a local file, and the user manually imports the file into the knowledge graph reading module to generate the domain knowledge graph; in the socket mode, the domain knowledge graph can be connected to the embedded service through the socket mode, and the agent can continuously send the collected information through the socket; in the message queue mode, the module for generating the domain knowledge graph is taken as a consumer through the message queue (Kafka, RabbitMQ) and other middleware, so as to consume the execution messages generated by the probe part.
[0077] It is easy to understand that the message queue mode or the socket mode is used for execution information collection, which can ensure continuous updating of data, so that the domain knowledge graph can continuously update the information of nodes and edges.
[0078] Based on the above optional implementation mode, the execution information obtained by the agent class is imported according to the preset information collection mode, and the execution information is analyzed by the knowledge graph, so that the domain knowledge graph can be quickly generated, and the domain knowledge graph can be continuously updated, and the accuracy of the domain knowledge graph is further improved.
[0079] As an optional implementation mode, in step S242, the execution information is analyzed by the knowledge graph, and the domain knowledge graph is generated, including:
[0080] In step S2421, the execution information is analyzed by the knowledge graph, a plurality of classes in the business code are determined as the main node, the class variables in the plurality of classes are determined as the secondary node, and the method call between the plurality of classes is determined as the edge.
[0081] In step S2422, the domain knowledge graph is constructed based on the main node, the secondary node and the edge.
[0082] Specifically, the code analysis tool is used to analyze the execution information by the knowledge graph, so that the analysis result can be obtained, and the analysis result records which method and which attribute of other classes are accessed by the method of a class in the software system. The system call chain identified in the analysis result is analyzed, a plurality of classes in the business code are taken as the main node, the class variables in the plurality of classes are taken as the secondary node, and the method call between the plurality of classes is taken as the edge, so that the minimum unit of the domain knowledge graph can be constructed.
[0083] Figure 6 is a unit schematic diagram of a domain knowledge graph according to an embodiment of the disclosure, as shown in Figure 6 In one unit of the domain knowledge graph, the A class has attributes A, B and method b, the method b calls the method in the B class, the B class has a method a, and the execution logic of a is to call a certain attribute value or method in the A class.
[0084] Based on the above optional implementation, by performing knowledge graph analysis on the execution information, a plurality of classes in the business code are determined as master nodes, class variables in the plurality of classes are determined as secondary nodes, and method calls between the plurality of classes are determined as edges, and then a domain knowledge graph can be quickly constructed based on the master nodes, the secondary nodes and the edges.
[0085] As an optional implementation, in step S25, the domain is divided according to the domain knowledge graph, and the division result includes:
[0086] In step S251, the number of edges associated with the master node is determined by the domain knowledge graph.
[0087] In step S252, the domain is divided based on the number of edges, and the division result is obtained.
[0088] The calling relationship in the software system can be visualized by using the domain knowledge graph, and then the number of edges associated with the plurality of classes in the business code can be quickly determined by the domain knowledge graph, the domain is divided based on the number of edges, and the division result is obtained.
[0089] Based on the above optional implementation, the number of edges associated with the master node is determined by the domain knowledge graph, and then the domain is divided based on the number of edges, so that the division result can be quickly obtained, and the target microservice is indicated by the division result for microservice splitting, further shortening the cycle of microservice splitting.
[0090] As an optional implementation, in step S252, the domain is divided based on the number of edges, and the division result includes:
[0091] In step S2521, the density threshold is determined by the number of edges, wherein the density threshold is the separation basis for domain division.
[0092] In step S2522, the master nodes are classified by using the density threshold and / or a preset value, and a classification result is obtained.
[0093] In step S2523, the domain is divided based on the classification result, and a division result is obtained.
[0094] Specifically, when dividing the domain, the number of connection relationships between each class and other classes can be used as the basis for separation. First, the number of edges of each class node in the software system is counted, and then the median of the number of edges is taken as the density threshold. When the master nodes are classified by using the density threshold and / or a preset value, the master nodes in the domain knowledge graph can be divided into four categories: high-density nodes, boundary nodes, protected nodes and noise nodes.
[0095] Based on the above optional implementation, the density threshold is determined by the number of edges, and then the main nodes are classified by using the density threshold and / or the preset value to obtain a classification result, and finally the domain division is performed based on the classification result, so that the division result can be quickly obtained.
[0096] As an optional implementation, in step S2522, the classification processing of the main nodes by using the density threshold and / or the preset value to obtain a classification result includes:
[0097] In step S31, the nodes in the main nodes with the number of edges greater than or equal to the density threshold are classified as first category nodes.
[0098] In step S32, the nodes in the main nodes with the number of edges equal to the preset value are classified as second category nodes.
[0099] In step S33, the nodes in the main nodes with the number of edges greater than the preset value and less than the density threshold are classified as third category nodes.
[0100] In step S34, the nodes in the main nodes that are not traversed are classified as fourth category nodes.
[0101] In step S35, the classification result is determined based on the first category nodes, the second category nodes, the third category nodes, and the fourth category nodes.
[0102] Specifically, the first category nodes are high-density nodes, which can also be high-latitude nodes, and the number of edges of the high-density nodes is greater than or equal to the density threshold; the second category nodes are protection nodes, which are nodes connected to the high-density nodes with a degree of 1; the third category nodes are boundary nodes, which are nodes connected to the high-density nodes with a degree greater than 1, and the number of edges of the boundary nodes is less than the density threshold; and the fourth category nodes are noise nodes, which are nodes that are not traversed.
[0103] When the main nodes are classified by using the density threshold and / or the preset value, all nodes in the domain knowledge graph need to be traversed first. If a high-latitude node that has not been visited is encountered, it is marked as visited, and a new cluster is created, and the high-latitude node is added to the cluster. Then, a Breadth First Search (BFS) algorithm is started from the high-latitude node as the starting point. If other high-latitude nodes are found nearby, they are marked as visited, and then added to the cluster.
[0104] Based on the above optional implementation, by classifying the nodes in the main node with the number of edges greater than or equal to the density threshold as the first category nodes, classifying the nodes in the main node with the number of edges equal to the preset value as the second category nodes, classifying the nodes in the main node with the number of edges greater than the preset value and less than the density threshold as the third category nodes, and classifying the nodes in the main node that have not been traversed as the fourth category nodes, the classification result can be quickly determined based on the first category nodes, the second category nodes, the third category nodes and the fourth category nodes, so that the field division is efficiently performed, and the period involved in the field driving is effectively shortened.
[0105] As an optional implementation, in step S2523, the field division is performed based on the classification result to obtain a division result, including: based on the classification result, dividing the first category nodes into a target field, and dividing the second category nodes and the third category nodes into a target field object to obtain the division result.
[0106] Specifically, each edge in the field knowledge graph is traversed, if the number of edges of a node is greater than or equal to the median threshold, that is, the node is a high-density node, the high-density node is divided into a unified field, if a node is only related to another node, that is, the node can be a protection node and a boundary node, it is regarded as a unified field object, and finally the division result can be obtained.
[0107] Figure 7 is a schematic diagram of another microservice field division method according to an embodiment of the present disclosure, as shown in Figure 7 the method further includes:
[0108] Step S701, obtaining a request message, wherein the request message is used to request access to a target microservice;
[0109] Step S702, determining identification information of the target microservice based on the request message;
[0110] Step S703, in response to the target microservice being in a starting state, scanning all class files in a software system, wherein the software system is used to carry the target microservice;
[0111] Step S704, obtaining a plurality of classes from the all class files based on the identification information to obtain a call relationship chain;
[0112] Step S705, determining the methods of the plurality of classes contained in the call relationship chain;
[0113] Step S706, cutting the methods of the plurality of classes in an aspect manner, and embedding a proxy class before the methods of the plurality of classes;
[0114] Step S707, obtaining execution information by using the proxy class;
[0115] Step S708, importing the execution information obtained by the agent class according to the preset information collection mode;
[0116] Step S709, performing knowledge graph analysis on the execution information to generate a domain knowledge graph;
[0117] Step S710, performing domain division according to the domain knowledge graph to obtain a division result, wherein the division result is used to indicate microservice decomposition of the target microservice.
[0118] Based on the above steps S701 to S710, by obtaining a request message for requesting access to a target microservice, embedding an agent class in the business code of the request message, obtaining execution information by using the agent class, then generating a domain knowledge graph based on the execution information, performing domain division according to the domain knowledge graph, and obtaining a division result, the purpose of quickly performing domain division based on a request message is achieved, and the effect of effectively shortening the domain-driven design cycle and the microservice transformation cycle of a software system is realized, thereby solving the technical problem that the domain-driven design cycle and the microservice transformation cycle of a software system are long due to the dependence on the understanding ability of developers for domain knowledge when performing domain model division in related technologies.
[0119] Figure 8 is a process schematic diagram of domain division according to an embodiment of the present disclosure, as shown in Figure 8 The method further includes:
[0120] Step S801, determining the number of edges associated with the main node through the domain knowledge graph;
[0121] Step S802, determining a density threshold value through the number of edges, wherein the density threshold value is a separation basis for domain division;
[0122] Step S803, classifying nodes in the main node with the number of edges greater than or equal to the density threshold value as first category nodes;
[0123] Step S804, classifying nodes in the main node with the number of edges equal to a preset value as second category nodes;
[0124] Step S805, classifying nodes in the main node with the number of edges greater than the preset value and less than the density threshold value as third category nodes;
[0125] Step S806, classifying nodes in the main node that have not been traversed as fourth category nodes;
[0126] Step S807, determining a classification result based on the first category nodes, the second category nodes, the third category nodes, and the fourth category nodes;
[0127] Step S808, based on the classification result, dividing the first category node into the target domain, and dividing the second category node and the third category node into the target domain object, to obtain a division result.
[0128] Based on the above steps S801 to S808, by performing domain division based on the domain knowledge graph, the division result is obtained, which can realize micro-service splitting of the target micro-service, thereby effectively shortening the domain-driven design period and micro-service transformation period of the software system.
[0129] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the technical solution comply with relevant laws and regulations and do not violate public order and good customs.
[0130] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and the necessary general hardware platform, of course, it can also be realized by hardware, but in many cases the former is a better embodiment. Based on such understanding, the technical solution of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes a plurality of instructions for causing an end device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the method described in the embodiments of the present disclosure.
[0131] In the present disclosure, a micro-service domain division device is also provided, which is used to implement the above-mentioned embodiments and preferred embodiments, and will not be described again. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware or a combination of software and hardware is also possible and is contemplated.
[0132] Figure 9 is a structural block diagram of a micro-service domain division device according to an embodiment of the present disclosure, as shown in Figure 9 The micro-service domain division device 900 includes:
[0133] The first acquisition module 901 is configured to acquire a request message, wherein the request message is used to request access to a target micro-service;
[0134] The embedding module 902 is configured to embed an agent class in the business code of the request message, wherein the agent class is used to collect execution information of a call relationship chain in the business code;
[0135] The second acquisition module 903 is configured to acquire the execution information by using the agent class;
[0136] The generating module 904 is configured to generate a domain knowledge graph based on the execution information, where the domain knowledge graph is a knowledge graph of a microservice domain.
[0137] The dividing module 905 is configured to divide the domain according to the domain knowledge graph to obtain a division result, where the division result is used to indicate that the target microservice is microservice-divisional.
[0138] Optionally, the embedding module 902 is further configured to: determine identification information of the target microservice based on the request message; obtain a call relationship chain through the identification information, where the call relationship chain is used to describe a call relationship between methods of a plurality of classes in the business code; and embed a proxy class in the call relationship chain in an aspect manner, where the aspect manner is used to cut the call relationship chain and embed the proxy class at a cutting position.
[0139] Optionally, the embedding module 902 is further configured to: in response to the target microservice being in a starting state, scan all class files in a software system, where the software system is used to carry the target microservice; and obtain a plurality of classes from the all class files based on the identification information to obtain the call relationship chain.
[0140] Optionally, the embedding module 902 is further configured to: determine methods of the plurality of classes contained in the call relationship chain; and cut the methods of the plurality of classes in an aspect manner and embed the proxy class before the methods of the plurality of classes.
[0141] Optionally, the microservice domain dividing apparatus 900 further includes: a processing module 906, configured to generate the proxy class based on the plurality of classes and verify whether a collection manner of the proxy class is in an available state; and a determining module 907, configured to determine that the proxy class is started completely to obtain the execution information in response to the proxy class being generated and the collection manner being in the available state.
[0142] Optionally, the generating module 904 is further configured to: import the execution information obtained by the proxy class according to a preset information collection manner, where the preset information collection manner includes one of the following: a file writing manner, a socket manner, and a message queue manner; and perform knowledge graph analysis on the execution information to generate the domain knowledge graph.
[0143] Optionally, the generating module 904 is further configured to: perform knowledge graph analysis on the execution information, determine a plurality of classes in the business code as master nodes, determine class variables in the plurality of classes as secondary nodes, and determine method calls between the plurality of classes as edges; and construct the domain knowledge graph based on the master nodes, the secondary nodes, and the edges.
[0144] Optionally, the dividing module 905 is further configured to: determine a number of edges associated with the master nodes through the domain knowledge graph; and divide the domain based on the number of edges to obtain the division result.
[0145] Optionally, the dividing module 905 is further configured to: determine a density threshold value based on the number of edges, wherein the density threshold value is a separation basis for domain division; perform classification processing on the master nodes using the density threshold value and / or a preset numerical value to obtain a classification result; and perform domain division based on the classification result to obtain a division result.
[0146] Optionally, the dividing module 905 is further configured to: classify a node in the master nodes as a first category node if the number of edges of the node is greater than or equal to the density threshold value; classify a node in the master nodes as a second category node if the number of edges of the node is equal to the preset numerical value; classify a node in the master nodes as a third category node if the number of edges of the node is greater than the preset numerical value and less than the density threshold value; and classify a node in the master nodes that is not traversed as a fourth category node; and determine the classification result based on the first category node, the second category node, the third category node, and the fourth category node.
[0147] Optionally, the dividing module 905 is further configured to: based on the classification result, divide the first category node into a target domain, and divide the second category node and the third category node into a target domain object to obtain the division result.
[0148] It should be noted that each of the above modules can be implemented by software or hardware, and for the latter, the following implementation manners can be used, but are not limited thereto: all of the above modules are located in the same processor; or the above modules are located in different processors in any combination.
[0149] According to an embodiment of the present disclosure, the present disclosure further provides an electronic device including a memory and at least one processor, the memory storing computer instructions, and the processor being configured to run the computer instructions to perform the steps in the above method embodiments.
[0150] Optionally, the electronic device can further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0151] Optionally, in the present disclosure, the processor can be configured to perform the following steps by using a computer program:
[0152] S1, obtaining a request message, wherein the request message is used to request access to a target microservice;
[0153] S2, embedding an agent class in a business code of the request message, wherein the agent class is used to collect execution information of a call relationship chain in the business code;
[0154] S3, obtaining the execution information by using the agent class;
[0155] S4, generating a domain knowledge graph based on the execution information, wherein the domain knowledge graph is a knowledge graph of a microservice domain;
[0156] S5, performing field division according to the field knowledge graph to obtain a division result, wherein the division result is used to indicate microservice division of the target microservice.
[0157] Optionally, specific examples in this embodiment can refer to examples described in the above embodiments and optional implementation manners, which will not be described herein again.
[0158] According to embodiments of the present disclosure, the present disclosure also provides a non-transitory computer-readable storage medium having computer instructions stored therein, wherein the computer instructions are configured to execute steps in the above method embodiments when running.
[0159] Optionally, in the present embodiment, the above non-transitory computer-readable storage medium can be configured to store computer programs for executing the following steps:
[0160] S1, obtaining a request message, wherein the request message is used to request access to a target microservice;
[0161] S2, embedding an agent class in a business code of the request message, wherein the agent class is used to collect execution information of a call relationship chain in the business code;
[0162] S3, obtaining the execution information by using the agent class;
[0163] S4, generating a field knowledge graph based on the execution information, wherein the field knowledge graph is a knowledge graph of a microservice field;
[0164] S5, performing field division according to the field knowledge graph to obtain a division result, wherein the division result is used to indicate microservice division of the target microservice.
[0165] Optionally, in the present embodiment, the above non-transitory computer-readable storage medium can include but is not limited to electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or apparatus, or any suitable combination of the above. More specific examples of a readable storage medium would include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the above.
[0166] According to embodiments of the present disclosure, the present disclosure also provides a computer program product. Program codes for implementing the embodiments of the method of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general purpose computer, a special purpose computer, or other programmable data processing apparatus, so that the program codes, when executed by the processor or controller, cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program codes can be executed entirely on a machine, partially on a machine, partially on a machine as a separate software package, or entirely on a remote machine or server.
[0167] In the above-described embodiments of the present disclosure, the description of each embodiment focuses on different aspects, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0168] In several embodiments provided by the present disclosure, it should be understood that the disclosed technology can be implemented in other ways. For example, the division of the units described above is merely illustrative, and in actual implementation, another division manner can be used, for example, a plurality of units or components can be combined or integrated into another system, or some features can be omitted or not executed. In addition, the coupling or direct coupling or communication connection between the units or modules shown or discussed can be indirect coupling or communication connection through some interfaces, and can be electrical or other forms.
[0169] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on multiple units. Part or all of the units can be selected according to actual needs to achieve the purpose of the present embodiment.
[0170] In addition, each functional unit in each embodiment of the present disclosure can be integrated into a processing unit, or each unit can exist physically, or two or more units can be integrated into one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0171] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present disclosure, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes several instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present disclosure. The aforementioned storage medium includes various media that can store program codes, such as a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, etc.
[0172] The above only describes the preferred embodiments of the present disclosure, and it should be pointed out that, for those skilled in the art, without departing from the principles of the present disclosure, a number of improvements and refinements can be made, and these improvements and refinements should also be considered as the protection scope of the present disclosure.
Claims
1. A method for partitioning microservice domains, comprising: Obtain a request message, wherein the request message is used to request access to the target microservice; A proxy class is embedded in the business code of the request message, wherein the proxy class is used to collect execution information of the call relationship chain in the business code; The execution information is obtained using the proxy class. The execution information is analyzed using a knowledge graph. Multiple classes in the business code are identified as main nodes, class variables in the multiple classes are identified as secondary nodes, and method calls between the multiple classes are identified as edges. A domain knowledge graph is constructed based on the master node, the sub-nodes, and the edges, wherein the domain knowledge graph is a knowledge graph of the microservice domain; The number of edges associated with the main node is determined using the domain knowledge graph. The density threshold is determined by the number of edges, wherein the density threshold is the dividing criterion for neighborhood partitioning; Nodes in the main node whose number of edges is greater than or equal to the density threshold are classified as first category nodes; Nodes in the main node whose number of edges equals a preset value are classified as second-category nodes; Nodes in the main node whose number of edges is greater than the preset value but less than the density threshold are classified as third-category nodes; The nodes that have not been traversed in the main node are classified into the fourth category of nodes; The classification result is determined based on the first category node, the second category node, the third category node, and the fourth category node; Based on the classification results, the first category nodes are classified as target domains, and the second category nodes and the third category nodes are classified as target domain objects, to obtain a partitioning result, wherein the partitioning result is used to indicate the microservice splitting of the target microservice.
2. The microservice domain partitioning method according to claim 1, wherein, Embedding the proxy class in the business code includes: The identification information of the target microservice is determined based on the request message; The call relationship chain is obtained through the identification information, wherein the call relationship chain is used to describe the call relationship between methods of multiple classes in the business code; The proxy class is embedded in the call relationship chain using an aspect-oriented approach, wherein the aspect-oriented approach is used to cut the call relationship chain and embed the proxy class at the cut position.
3. The microservice domain partitioning method according to claim 2, wherein, Obtaining the call relationship chain through the identification information includes: In response to the target microservice being in a running state, all class files in the software system are scanned, wherein the software system is used to host the target microservice; Based on the identification information, the multiple classes are obtained from all the class files to obtain the call relationship chain.
4. The microservice domain partitioning method according to claim 2, wherein, Embedding the proxy class in the call chain using the aspect-oriented approach includes: Determine the methods of the multiple classes included in the call relationship chain; The methods of the multiple classes are segmented using the aspect method, and the proxy class is embedded before the methods of the multiple classes.
5. The microservice domain partitioning method according to claim 2, wherein, The microservice domain partitioning method also includes: The proxy class is generated based on the multiple classes, and the collection method of the proxy class is verified to be available. In response to the fact that the proxy class has been generated and the collection method is in the available state, it is determined that the proxy class has been started successfully in order to obtain the execution information.
6. The microservice domain partitioning method according to claim 1, wherein, The method further includes: The execution information obtained by the proxy class is imported according to a preset information collection method, wherein the preset information collection method includes one of the following: file writing method, socket method, and message queue method.
7. A microservice domain partitioning device, comprising: The first acquisition module is used to acquire a request message, wherein the request message is used to request access to the target microservice; An embedding module is used to embed a proxy class in the business code of the request message, wherein the proxy class is used to collect execution information of the call relationship chain in the business code; The second acquisition module is used to acquire the execution information using the proxy class; A generation module is used to perform knowledge graph analysis on the execution information, identify multiple classes in the business code as main nodes, class variables in the multiple classes as secondary nodes, and method calls between the multiple classes as edges; and construct a domain knowledge graph based on the main nodes, the secondary nodes, and the edges, wherein the domain knowledge graph is a knowledge graph of the microservice domain; A partitioning module is used to determine the number of edges associated with the master node through the domain knowledge graph; determine a density threshold based on the number of edges, wherein the density threshold is the dividing criterion for domain partitioning; classify the master nodes whose number of edges is greater than or equal to the density threshold as first-category nodes; classify the master nodes whose number of edges is equal to a preset value as second-category nodes; classify the master nodes whose number of edges is greater than the preset value and less than the density threshold as third-category nodes; classify the master nodes that have not been traversed as fourth-category nodes; determine a classification result based on the first-category nodes, the second-category nodes, the third-category nodes, and the fourth-category nodes; and based on the classification result, partition the first-category nodes into the target domain, and partition the second-category nodes and the third-category nodes into target domain objects, thereby obtaining a partitioning result, wherein the partitioning result is used to indicate the microservice decomposition of the target microservice.
8. The microservice domain partitioning apparatus according to claim 7, wherein, The embedding module is also used for: The identification information of the target microservice is determined based on the request message; The call relationship chain is obtained through the identification information, wherein the call relationship chain is used to describe the call relationship between methods of multiple classes in the business code; The proxy class is embedded in the call relationship chain using an aspect-oriented approach, wherein the aspect-oriented approach is used to cut the call relationship chain and embed the proxy class at the cut position.
9. The microservice domain partitioning apparatus according to claim 8, wherein, The embedding module is also used for: In response to the target microservice being in a running state, all class files in the software system are scanned, wherein the software system is used to host the target microservice; Based on the identification information, the multiple classes are obtained from all the class files to obtain the call relationship chain.
10. The microservice domain partitioning apparatus according to claim 8, wherein, The embedding module is also used for: Determine the methods of the multiple classes included in the call relationship chain; The methods of the multiple classes are segmented using the aspect method, and the proxy class is embedded before the methods of the multiple classes.
11. The microservice domain partitioning apparatus according to claim 8, wherein, The microservice domain partitioning device also includes: The processing module is used to generate the proxy class based on the multiple classes and verify whether the collection method of the proxy class is available. The determination module is further configured to, in response to the generation of the proxy class and the availability of the collection method, determine that the proxy class has completed startup in order to obtain the execution information.
12. The microservice domain partitioning apparatus according to claim 7, wherein, The generation module is also used for: The execution information obtained by the proxy class is imported according to a preset information collection method, wherein the preset information collection method includes one of the following: file writing method, socket method, and message queue method.
13. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the microservice domain partitioning method according to any one of claims 1-6.
14. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to execute the microservice domain partitioning method according to any one of claims 1-6.
15. A computer program product comprising a computer program that, when executed by a processor, implements the microservice domain partitioning method according to any one of claims 1-6.
Citation Information
Patent Citations
Single system micro-service splitting method based on domain event driving
CN113961173A
Method and system for monitoring link data in micro-service architecture system
CN114546756A