Background
In the field of software development, micro services have become mainstream, and many micro service frames such as Spring Cloud/Dubbo, etc. are mainstream in the market at present, and when a project is implemented, especially in the process of large-scale project transformation and iteration, different services generally have different choices for the micro service frames due to factors such as historical reasons and technical development trends, but application services adopting different micro service frames cannot be directly communicated with each other, and often need to be detoured to an interface or gateway layer through a standard protocol to be called, so that the efficiency is greatly reduced due to the interaction mode through detour, and the development cost and the system maintenance requirement are higher.
Disclosure of Invention
The application provides a micro-service calling method, a micro-service calling device, electronic equipment and a computer readable storage medium, which can solve the problem of micro-service calling among different micro-service architectures. The technical scheme is as follows:
in a first aspect, a method for invoking a micro service is provided, where the method includes:
receiving calling request information from a micro-service calling party, wherein the calling request information at least comprises the micro-service calling party information and architecture information of a micro-service architecture to which the micro-service calling party belongs;
generating virtual request information corresponding to the current micro service architecture according to the calling request information;
and executing the calling of the target micro service in the current micro service architecture according to the virtual request information.
In one possible implementation, the generating, according to the call request information, virtual request information corresponding to the current micro service architecture includes:
and converting the calling request information according to the architecture information of the micro service architecture to which the micro service calling party belongs and a preset information conversion method between the micro service architectures to generate virtual request information corresponding to the current micro service architecture.
In another possible implementation manner, converting the invocation request information according to an information conversion method between preset micro service architectures, and generating virtual request information corresponding to a current micro service architecture includes:
and performing protocol conversion on the calling request information according to a preset protocol conversion method between the micro service architectures to generate virtual request information corresponding to the protocol supported by the current micro service architecture.
In another possible implementation, the method further includes:
generating response information in response to executing a call to a target microservice in a current microservice architecture;
and converting the response information according to a preset information conversion method between the micro service frameworks to generate virtual response information corresponding to the micro service framework to which the micro service caller belongs.
In yet another possible implementation, the method further includes:
and outputting the virtual response information to the micro-service calling party for the micro-service calling party to perform service processing.
In a second aspect, a micro-service invocation apparatus is provided, the apparatus comprising:
the request receiving module is used for receiving calling request information from the micro-service calling party, wherein the calling request information at least comprises the micro-service calling party information and the architecture information of the micro-service architecture to which the micro-service calling party belongs;
the virtual request generating module is used for generating virtual request information corresponding to the current micro-service architecture according to the calling request information;
and the call execution module is used for executing the call of the target micro service in the current micro service architecture according to the virtual request information.
In one possible implementation, the generating, according to the call request information, virtual request information corresponding to the current micro service architecture includes:
and converting the calling request information according to the architecture information of the micro service architecture to which the micro service calling party belongs and a preset information conversion method between the micro service architectures to generate virtual request information corresponding to the current micro service architecture.
In another possible implementation manner, converting the invocation request information according to an information conversion method between preset micro service architectures, and generating virtual request information corresponding to a current micro service architecture includes:
and performing protocol conversion on the calling request information according to a preset protocol conversion method between the micro service architectures to generate virtual request information corresponding to the protocol supported by the current micro service architecture.
In a third aspect, an electronic device is provided, which includes:
one or more processors;
a memory;
one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs configured to: executing the microservice calling method according to any of claims 1 to 5.
For example, in a third aspect of the present application, there is provided a computing device comprising: the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the micro-service calling method as shown in the first aspect of the application.
In a fourth aspect, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the microservice invocation method of any of claims 1-5.
For example, in a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and the computer program, when executed by a processor, implements the micro service invocation method shown in the first aspect of the present application.
The beneficial effect that technical scheme that this application provided brought is:
according to the micro-service calling request information, the virtual request information corresponding to the current micro-service framework is generated, so that the micro-service between different micro-service frameworks is called without converting into a standard protocol but directly calling originally, and a calling party does not need to sense the heterogeneous micro-service framework, so that the micro-service interaction efficiency between different frameworks is improved, and the research and development cost is reduced.
Detailed Description
Reference will now be made in detail to the embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are exemplary only for the purpose of explaining the present application and are not to be construed as limiting the present invention.
As used herein, the singular forms "a", "an", "the" and "the" include plural referents unless the context clearly dictates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. As used herein, the term "and/or" includes all or any element and all combinations of one or more of the associated listed items.
For better understanding and description of the solution of the embodiments of the present application, the following briefly describes the technical terms involved in the embodiments of the present application:
micro-service: the microservice is a program or service which divides an application of a single architecture into individual and independent running programs according to business.
Micro-service architecture: a large single application and service is split into several or even tens of supporting microservices that can extend a single component rather than the entire application stack to meet service level agreements.
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
In the field of software development, micro services have become mainstream, many micro service architectures, such as Spring Cloud/Dubbo, etc., currently mainstream in the market, when a project is implemented, especially in the process of large project transformation and iteration, different services generally have different choices for the micro service architecture due to factors such as historical reasons and technical development trends, but application services adopting different micro service architectures cannot be directly communicated with each other, for example, as shown in fig. 1, the micro service architecture is a scene schematic diagram of a calling process of the micro service in the prior art of the embodiment of the present application, as shown in the drawing, when an application based on the micro service architecture a is called for an application based on the micro service architecture B, direct calling cannot be realized due to different micro service architecture systems, and therefore, a detour is often required to be realized through an interface platform or a service gateway of a standard protocol, thus, this interaction via detour results in a significant loss of efficiency.
Therefore, in order to solve the above technical problem, embodiments of the present application provide a method and an apparatus for invoking a micro service, an electronic device, and a computer-readable storage medium, which generate virtual request information corresponding to a current micro service architecture according to micro service invocation request information, so that direct native invocation is performed without converting into a standard protocol when micro service invocation is performed between different micro service architectures, thereby improving efficiency of micro service interaction between different architectures.
The following describes the technical solutions of the present application and how to solve the above technical problems with specific embodiments. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
The embodiment of the application provides a method for invoking micro-services, and an execution main body of the method can be terminals or server equipment of various application micro-service architecture systems, and can also be devices or chips integrated on the equipment, for example, computer equipment of the application micro-service architecture systems, and the like. As shown in fig. 2, which is a schematic flow chart of a method for invoking a micro service according to an embodiment of the present application, the method includes the following steps:
s201: and receiving calling request information from the micro-service caller.
The calling request information at least includes micro-service caller information and architecture information of a micro-service architecture to which the micro-service caller belongs. In addition, target microservice information in the current microservice architecture as the invoker of the microservice may also be included. Specifically, in a scenario of executing a service process, the micro service invoker may be a service application in the service system that executes a specific function, and the micro service invoker information may at least include network identification information of the micro service invoker, for example, the network identification information of the micro service invoker may be identified by predefined code or text information. For example, the network identification of the microservice order center for processing order traffic may be represented by the numerical code "001" or the textual information "order center". The architecture information of the micro service architecture to which the micro service invoker belongs may include at least network identification information of the micro service architecture and architecture type information of the micro service architecture. For example, the network identification information of the micro service architecture may be identified by predefined codes or text information, and the type of the micro service architecture to which the micro service invoker belongs may be one of Spring Cloud, Dubbo, and Golang.
S202: and generating virtual request information corresponding to the current micro service architecture according to the calling request information.
Specifically, the calling request information may be converted according to the architecture information of the micro service architecture to which the micro service caller belongs in the step S102 and according to a preset information conversion method between the micro service architectures, so as to generate the virtual request information corresponding to the current micro service architecture.
For example, the invocation request information may be converted according to the architecture type information of the micro service architecture to which the micro service invoker belongs and the architecture type information of the current micro service architecture, and according to a protocol conversion method, a data conversion method, and the like preset between the architecture types of the two micro service architectures, so as to generate the virtual request information corresponding to the protocol supported by the current micro service architecture. The virtual request information is generated by converting the calling request information based on the micro-service architecture to which the micro-service caller belongs and the architecture type of the current micro-service architecture, so that the virtual request information may include the virtual micro-service caller information corresponding to the current micro-service architecture, the architecture information of the micro-service architecture to which the virtual micro-service caller belongs, and the virtual target micro-service information in the current micro-service architecture as the micro-service callee.
S203: and executing the calling of the target micro service in the current micro service architecture according to the virtual request information.
Specifically, according to the virtual request information corresponding to the current micro service architecture generated in step S102, the micro service invoker is executed to invoke the target micro service in the current micro service architecture.
According to the micro-service calling request information, the virtual request information corresponding to the current micro-service framework is generated, so that the micro-service between different micro-service frameworks is called without converting into a standard protocol but directly calling originally, and a calling party does not need to sense the heterogeneous micro-service framework, so that the micro-service interaction efficiency between different frameworks is improved, and the research and development cost is reduced.
In an embodiment of the present application, a possible implementation manner is provided, as shown in fig. 3, which is a second flowchart of a method for invoking a micro service, provided in an embodiment of the present application, and the method includes the following steps:
s301: and receiving calling request information from the micro-service caller.
Specifically, step S301 is the same as step S201 in the embodiment shown in fig. 2, and is not described here again.
Step S202 in the embodiment shown in fig. 2 may specifically include the following steps S302 and S303.
S302: and performing protocol conversion on the calling request information according to a preset protocol conversion method between the micro service architectures to generate virtual request information corresponding to the protocol supported by the current micro service architecture.
Specifically, the call request information may be converted according to the architecture type information of the micro service architecture to which the micro service caller belongs and the architecture type information of the current micro service architecture, and according to a protocol conversion method preset between the two architecture types of the micro service architecture, so as to generate the virtual request information corresponding to the protocol supported by the current micro service architecture. Therefore, the virtual request information may include virtual micro service invoker information corresponding to a protocol supported by the current micro service architecture, architecture information of the micro service architecture to which the virtual micro service invoker belongs, and virtual target micro service information in the current micro service architecture as the micro service invoker.
S303: and executing the calling of the target micro service in the current micro service architecture according to the virtual request information.
Specifically, step S303 is the same as step S203 in the embodiment shown in fig. 2, and is not described here again.
S304: responsive to executing the call to the target microservice in the current microservice architecture, response information is generated.
Specifically, after the execution of the call to the target micro service in the current micro service architecture in step S303, response information corresponding to the execution of the target micro service is generated, where the response information may include execution result information of the execution call target micro service, and virtual micro service caller information corresponding to the current micro service architecture that receives the response information.
S305: and converting the response information according to a preset information conversion method between the micro service frameworks to generate virtual response information corresponding to the micro service framework to which the micro service caller belongs.
Specifically, the response information may be converted according to a preset protocol conversion method between the micro service architecture to which the micro service invoker belongs and the current micro service architecture, so as to generate virtual response information corresponding to a protocol supported by the architecture to which the micro service invoker belongs. Accordingly, the virtual response information may include virtual execution result information corresponding to the micro service architecture to which the micro service invoker belongs, and micro service invoker information that receives the virtual response information.
S306: and outputting the virtual response information to the micro-service calling party for the micro-service calling party to perform service processing.
According to the method, the protocol conversion is carried out on the calling request information according to the preset protocol conversion method between the micro service architectures, and the virtual request information corresponding to the protocol supported by the current micro service architecture is generated, so that the micro service between different micro service architectures is called directly and originally without being converted into a standard protocol, and the calling party does not need to sense the heterogeneous micro service architecture, the efficiency of micro service interaction between different architectures is improved, and the research and development cost is reduced.
In an embodiment of the present application, a possible implementation manner is provided, as shown in fig. 4, which is an application scenario diagram of a micro-service invocation method provided in the embodiment of the present application, and the following further describes a technical solution of the embodiment of the present application with reference to fig. 4.
As shown in fig. 4, the scenario is an order creation flow when a user purchases a commodity on the internet, and the micro-service invoking method of the present application will be described below with reference to a processing operation sequence of the order creation flow.
Specifically, in the scenario, in the order creation process for processing the online purchased goods of the user, the micro service for processing the order information is an order center, and the micro service for processing the goods information is a goods center, where the order center and the goods center may be based on multiple micro service architectures, for example, the order center may be based on a Dubbo architecture, and the goods center may be based on a Spring Cloud architecture, so that after the user clicks and submits the goods selected for purchase on the APP of the terminal device, the corresponding network request for creating the order is configured to the order center through the gateway, and the order center calls the goods center, so as to query the goods information selected by the user.
Since the order center as the micro-service caller and the commodity center as the micro-service callee are based on different micro-service architectures, when the order center calls the commodity center, the order center executes the micro-service calling method in the embodiment of the present application through the commodity center virtual service to realize the calling of the order center to the commodity center.
Specifically, after receiving a network request for creating an order, the order center sends, to the commodity center virtual service, invocation request information based on a Dubbo protocol supported by the Dubbo architecture, where the invocation request information may include network identification information of the order center, network identification information and architecture type information of a micro service architecture to which the order center belongs, and network identification information of a target micro service to be invoked, that is, network identification information of the commodity center. For convenience of description, the above information may be represented by text information and numerical information, for example, the network identification information of the order center may be represented as "order center-Dubbo", the network identification information of the micro service architecture to which the order center belongs may be represented as "order center architecture-Dubbo", the architecture type information may be represented as "001-Dubbo", and the network identification information of the target micro service to be invoked, i.e., the product center, may be represented as "product center-Dubbo".
After receiving the calling request information, the commodity center virtual service converts the calling request information according to a protocol conversion method between a Dubbo architecture to which the order center belongs and a Spring Cloud architecture to which the current commodity center belongs in the calling request information, and generates virtual request information of a restful protocol corresponding to the support of the Spring Cloud architecture of the current commodity center. For example, the virtual request information may include virtual micro-service invoker information "order center-restful", architecture information "order center architecture-restful" of a micro-service architecture to which the virtual micro-service invoker belongs, and architecture type information "001-restful", virtual target micro-service information "commodity center-restful" in a current micro-service architecture as the micro-service invoker. It should be noted that the above representations are only exemplary representations made for illustrating the micro service invocation method according to the embodiment of the present application.
Then, based on the virtual request information, a call to a target service, i.e., a commodity center, is executed.
Further, after the above-mentioned execution of the call to the commodity center, that is, the commodity center makes a commodity inquiry, a response message is generated accordingly, where the response message may include the execution result message and the virtual micro-service caller information corresponding to the accepted response message of the current micro-service architecture. Also, the response information is response information of the restful protocol based on the support of the Spring Cloud architecture, for example, for convenience of description, the execution result information included in the response information may be exemplarily represented as "result information-restful" and the virtual micro service invoker information corresponding to the acceptance response information of the current micro service architecture may be represented as "order center-restful".
Further, the product center virtual service converts the response information according to a protocol conversion method between the Dubbo architecture to which the order center belongs and the Spring Cloud architecture to which the current product center belongs, and generates virtual response information of the Dubbo protocol supported by the Dubbo architecture corresponding to the order center, for example, the virtual response information may include virtual execution result information "result information-Dubbo" corresponding to the micro-service architecture to which the micro-service invoker belongs, and micro-service invoker information "order center-Dubbo".
And further outputting the virtual response information to an order center for the order center to create an order according to the virtual response information.
According to the method, the protocol conversion is carried out on the calling request information according to the preset protocol conversion method between the micro service architectures, and the virtual request information corresponding to the protocol supported by the current micro service architecture is generated, so that the micro service between different micro service architectures is called directly and originally without being converted into a standard protocol, and the calling party does not need to sense the heterogeneous micro service architecture, the efficiency of micro service interaction between different architectures is improved, and the research and development cost is reduced.
An embodiment of the present application provides a micro service invoking device, as shown in fig. 5, which is a schematic structural diagram of the micro service invoking device provided in the embodiment of the present application, and the invoking device 50 may include: a request receiving module 501, a virtual request generating module 502, a call executing module 503, wherein,
a request receiving module 501, configured to receive call request information from a micro service caller.
Specifically, the call request information may include at least micro-service caller information and architecture information of a micro-service architecture to which the micro-service caller belongs. In addition, target microservice information in the current microservice architecture as the invoker of the microservice may also be included.
The virtual request generating module 502 is configured to generate virtual request information corresponding to the current micro service architecture according to the call request information.
Specifically, the calling request information may be converted according to architecture information of the micro service architecture to which the micro service caller belongs and a preset information conversion method between the micro service architectures, so as to generate virtual request information corresponding to the current micro service architecture.
Further, the call request information may be converted according to the architecture type information of the micro service architecture to which the micro service caller belongs and the architecture type information of the current micro service architecture, and according to a protocol conversion method preset between the two architecture types of the micro service architecture, so as to generate the virtual request information corresponding to the protocol supported by the current micro service architecture.
The call execution module 503 is configured to execute a call to a target microservice in the current microservice architecture according to the virtual request information.
In addition, the device can further comprise a response module and an output module, wherein the response module is used for responding to the calling of the target micro service in the current micro service architecture and generating response information; and converting the response information according to a preset information conversion method between the micro service frameworks to generate virtual response information corresponding to the micro service framework to which the micro service caller belongs. The output module is used for outputting the virtual response information to the micro-service calling party so as to be used for the micro-service calling party to carry out service processing.
The micro service invoking device of this embodiment may execute the micro service invoking method shown in the foregoing embodiments of this application, and the implementation principles thereof are similar, and are not described herein again.
According to the micro-service calling request information, the virtual request information corresponding to the current micro-service framework is generated, so that the micro-service between different micro-service frameworks is called without converting into a standard protocol but directly calling originally, and a calling party does not need to sense the heterogeneous micro-service framework, so that the micro-service interaction efficiency between different frameworks is improved, and the research and development cost is reduced.
An embodiment of the present application provides an electronic device, including: a memory and a processor; at least one program stored in the memory for execution by the processor, which when executed by the processor, implements: according to the micro-service calling request information, the virtual request information corresponding to the current micro-service framework is generated, so that the micro-service between different micro-service frameworks is called without converting into a standard protocol but directly calling originally, and a calling party does not need to sense the heterogeneous micro-service framework, so that the micro-service interaction efficiency between different frameworks is improved, and the research and development cost is reduced.
In an alternative embodiment, an electronic device is provided, as shown in fig. 6, the electronic device 4000 shown in fig. 6 comprising: a processor 4001 and a memory 4003. Processor 4001 is coupled to memory 4003, such as via bus 4002. Optionally, the electronic device 4000 may further include a transceiver 4004, and the transceiver 4004 may be used for data interaction between the electronic device and other electronic devices, such as transmission of data and/or reception of data. In addition, the transceiver 4004 is not limited to one in practical applications, and the structure of the electronic device 4000 is not limited to the embodiment of the present application.
The Processor 4001 may be a CPU (Central Processing Unit), a general-purpose Processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other Programmable logic device, a transistor logic device, a hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. The processor 4001 may also be a combination that performs a computational function, including, for example, a combination of one or more microprocessors, a combination of a DSP and a microprocessor, or the like.
Bus 4002 may include a path that carries information between the aforementioned components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 4002 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 6, but this is not intended to represent only one bus or type of bus.
The Memory 4003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical Disc storage, optical Disc storage (including Compact Disc, laser Disc, optical Disc, digital versatile Disc, blu-ray Disc, etc.), a magnetic Disc storage medium or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to these.
The memory 4003 is used for storing application codes for executing the scheme of the present application, and the execution is controlled by the processor 4001. Processor 4001 is configured to execute application code stored in memory 4003 to implement what is shown in the foregoing method embodiments.
Among them, electronic devices include but are not limited to: mobile phones, notebook computers, multimedia players, desktop computers, and the like.
The present application provides a computer-readable storage medium, on which a computer program is stored, which, when running on a computer, enables the computer to execute the corresponding content in the foregoing method embodiments. Compared with the prior art, the virtual request information corresponding to the current micro-service architecture is generated according to the micro-service calling request information, so that the micro-service calling between different micro-service architectures is realized without converting into a standard protocol, but direct primary calling is carried out, and a calling party does not need to sense the heterogeneous micro-service architecture, so that the micro-service interaction efficiency between different architectures is improved, and the research and development cost is reduced.
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and may be performed in other orders unless explicitly stated herein. Moreover, at least a portion of the steps in the flow chart of the figure may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
The foregoing is only a partial embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.