Disclosure of Invention
The embodiment of the invention provides a method, a device, equipment and a storage medium for aggregating micro services, which can reduce the complexity of aggregation of the micro services and improve the stability of a service system.
In a first aspect, an embodiment of the present invention provides a method for aggregating microservices, including:
acquiring at least two micro services corresponding to the data request;
extracting target data in return results of the at least two micro services according to the data request;
performing data conversion on each target data according to a set rule;
and aggregating the converted at least two target data to form a data result set, and sending the data result set to a data requester.
Further, acquiring at least two microservices corresponding to the data request includes:
and acquiring at least two micro services corresponding to the data request according to the mapping relation between the data request and the micro services.
Further, extracting target data in the returned results of the at least two microservices according to the data request comprises:
obtaining the return results of the at least two micro services from a database;
and extracting target field parameters from each returned result according to the data request, and determining the target field parameters as target data.
Further, before acquiring at least two micro services corresponding to the data request, the method further includes:
and creating a mapping relation between the data request and each micro-service.
Further, before acquiring at least two micro services corresponding to the data request, the method further includes:
executing the code packet contained in each micro service to obtain the return result of each micro service;
and storing each return result into a database.
In a second aspect, an embodiment of the present invention further provides an aggregation apparatus for microservices, where the apparatus includes:
the micro-service acquisition module is used for acquiring at least two micro-services corresponding to the data request;
the target data acquisition module is used for extracting target data in return results of the at least two micro services according to the data request;
the data conversion module is used for performing data conversion on each target data according to a set rule;
and the aggregation module is used for aggregating the converted at least two target data to form a data result set and sending the data result set to a data request party.
Further, the micro-service obtaining module is further configured to:
and acquiring at least two micro services corresponding to the data request according to the mapping relation between the data request and the micro services.
Further, the target data obtaining module is further configured to:
obtaining the return results of the at least two micro services from a database;
and extracting target field parameters from the returned result according to the data request, and determining the target field parameters as target data.
In a third aspect, an embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor implements the aggregation method of the microservices according to the embodiment of the present invention when executing the program.
In a fourth aspect, the embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the aggregation method of the microservices according to the embodiment of the present invention.
The method comprises the steps of firstly obtaining at least two micro services corresponding to a data request, then extracting target data in return results of the at least two micro services according to the data request, then carrying out data conversion on each target data according to a set rule, finally aggregating the at least two converted target data to form a data result set, and sending the data result set to a data requester. According to the aggregation method of the micro-services, the target data in the return results of at least two micro-services are extracted according to the data request, and the target data are aggregated after data conversion is carried out according to the set rule, so that the aggregation of the interfaces of the micro-services is not needed, the complexity of the aggregation of the micro-services can be reduced, and the stability of a service system can be improved.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a method for aggregating microservices according to an embodiment of the present invention, where the embodiment is applicable to a case of aggregating microservices, and the method may be executed by an aggregation apparatus for microservices, where the apparatus may be composed of hardware and/or software, and may be generally integrated in a device having an aggregation function for microservices, and the device may be an electronic device such as a server, a mobile terminal, or a server cluster. As shown in fig. 1, the method specifically comprises the following steps:
step 110, at least two micro services corresponding to the data request are obtained.
The data request may include an http request initiated by the client to the server, or a Remote Procedure Call (RPC) request initiated by the server. The micro-service can be an independently running program and has the functions of increasing, deleting, modifying and the like of the fine granularity of the foundation.
Specifically, after a data request sent by a client or a server is received, at least two micro services corresponding to the data request are obtained according to a mapping relation between the data request and the micro services.
In this embodiment, before obtaining at least two micro services corresponding to the data request, the method further includes the following steps: and creating a mapping relation between the data request and each micro-service.
And in the process of creating the service system, creating a mapping relation between the data request and the micro-service according to the micro-service required to be called by each data request. Illustratively, to realize the function of the data request a, the business system needs to call the microservice a and the microservice B, and then creates a mapping relation between the data request a and the microservice B. The mapping relationship between the data request and the microservice may be embodied in a mapping relationship table.
And 120, extracting target data in the return results of the at least two micro services according to the data request.
Where the returned result may be a result obtained from executing a code package in the microservice. The returned result includes a series of fields and parameters.
Specifically, after at least two micro services corresponding to the data request are obtained, return results of the at least two databases are obtained from the databases, and then required target field parameters are extracted from the return results according to the data request to determine the target data.
Optionally, before obtaining at least two micro services corresponding to the data request, the method further includes the following steps: executing the code packet contained in each micro service to obtain the return result of each micro service; and storing each return result into a database.
In this embodiment, the return result of the micro service is stored in the database, and the return result of the micro service is directly obtained from the database without calling an interface of the micro service to execute the code packet in the micro service each time a data request is received. Thereby reducing the complexity of the operation of the service system.
And step 130, performing data conversion on each target data according to a set rule.
The setting rule may be a rule in which format the predetermined data is embodied, and in this embodiment, the setting rule may be set by a technician who develops the service system. The data conversion process is a process of converting target data into the same meaning and only representing different ways, such as case conversion and the like.
Specifically, after the target data is extracted from each returned result, the target data is subjected to data conversion according to a set rule.
And step 140, aggregating the converted at least two target data to form a data result set, and sending the data result set to the data requester.
Specifically, after data conversion is performed on the target data, a data result set is formed by aggregation, and the data result set is sent to the data request party.
Example two
Fig. 2 is a schematic structural diagram of a microservice aggregation apparatus according to a second embodiment of the present invention. As shown in fig. 2, the apparatus includes: a microservice acquisition module 210, a target data acquisition module 220, a data conversion module 230, and an aggregation module 240.
A microservice obtaining module 210, configured to obtain at least two microservices corresponding to the data request;
a target data obtaining module 220, configured to extract target data in return results of at least two micro services according to the data request;
the data conversion module 230 is used for performing data conversion on each target data according to a set rule;
and the aggregation module 240 is configured to aggregate the converted at least two target data to form a data result set, and send the data result set to the data requester.
Optionally, the micro-service obtaining module 210 is further configured to:
and acquiring at least two micro services corresponding to the data request according to the mapping relation between the data request and the micro services.
Optionally, the target data obtaining module 220 is further configured to:
obtaining return results of at least two micro services from a database;
and extracting target field parameters from the returned result according to the data request, and determining the target field parameters as target data.
Optionally, the method further includes: a mapping relationship creation module to:
and creating a mapping relation between the data request and each micro-service.
Optionally, the method further includes: a return result storage module for:
executing the code packet contained in each micro service to obtain the return result of each micro service;
and storing each return result into a database.
Fig. 3 is an architecture diagram of a microserver according to a second embodiment of the present invention. As shown in fig. 3, the architecture includes a data requestor, a service aggregation module, and a service management module. The data request party initiates a data request, the service management module firstly obtains the micro-service corresponding to the data request according to the mapping relation, then extracts the field parameters required in the micro-service return result, and finally performs data conversion on the extracted field parameters. And the service aggregation module aggregates the field parameters after the data conversion and then sends the aggregated field parameters to the data requester.
The device can execute the methods provided by all the embodiments of the invention, and has corresponding functional modules and beneficial effects for executing the methods. For details not described in detail in this embodiment, reference may be made to the methods provided in all the foregoing embodiments of the present invention.
EXAMPLE III
Fig. 4 is a schematic structural diagram of a computer device according to a third embodiment of the present invention. FIG. 4 illustrates a block diagram of a computer device 712 suitable for use to implement embodiments of the present invention. The computer device 712 shown in fig. 4 is only an example and should not bring any limitations to the functionality or scope of use of the embodiments of the present invention. Device 712 is typically a computing device that assumes the aggregation functionality of the microservices.
As shown in fig. 4, computer device 712 is embodied in the form of a general purpose computing device. Components of computer device 712 may include, but are not limited to: one or more processors 716, a storage device 728, and a bus 718 that couples the various system components (including the storage device 728 and the processors 716).
Bus 718 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MCA) bus, an enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
Computer device 712 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by computer device 712 and includes both volatile and nonvolatile media, removable and non-removable media.
Storage 728 may include computer system readable media in the form of volatile Memory, such as Random Access Memory (RAM) 730 and/or cache Memory 732. Computer device 712 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 734 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 4, commonly referred to as a "hard drive"). Although not shown in FIG. 4, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a Compact disk-Read Only Memory (CD-ROM), a Digital Video disk (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to the bus 718 by one or more data media interfaces. Storage 728 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
Program 736 having a set (at least one) of program modules 726, which may include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination thereof may comprise an implementation of a network environment, may be stored in, for example, storage 728. Program modules 726 generally perform the functions and/or methodologies of embodiments of the invention as described herein.
Computer device 712 may also communicate with one or more external devices 714 (e.g., keyboard, pointing device, camera, display 724, etc.), with one or more devices that enable a user to interact with computer device 712, and/or with any devices (e.g., network card, modem, etc.) that enable computer device 712 to communicate with one or more other computing devices. Such communication may occur through input/output (I/O) interfaces 722. Further, computer device 712 may also communicate with one or more networks (e.g., a Local Area Network (LAN), Wide Area Network (WAN), and/or a public Network, such as the internet) via Network adapter 720. As shown, network adapter 720 communicates with the other modules of computer device 712 via bus 718. It should be appreciated that although not shown, other hardware and/or software modules may be used in conjunction with computer device 712, including but not limited to: microcode, device drivers, Redundant processing units, external disk drive Arrays, disk array (RAID) systems, tape drives, and data backup storage systems, to name a few.
The processor 716 executes various functional applications and data processing, such as implementing the aggregation method of microservices provided by the above-described embodiments of the present invention, by executing programs stored in the storage 728.
Example four
The fourth embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the aggregation method for microservices as provided by the fourth embodiment of the present invention.
Of course, the computer program stored on the computer-readable storage medium provided by the embodiments of the present invention is not limited to the method operations described above, and may also perform related operations in the aggregation method of microservices provided by any embodiments of the present invention.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.