Remote service calling method, device, equipment and storage medium
By using preset mapping rules and dynamic proxy framework in distributed systems, the microservice calls are automatically executed, which solves the problem of high design cost of remote service calls and realizes efficient microservice configuration and execution.
Patent Information
- Application Number
- CN202110289782.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-17
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2041-03-17
AI Technical Summary
In distributed systems, when microservices are transformed or improved, the design cost of remote service calls is high, and the configuration file redesign is large, resulting in an increase in design cost.
Through preset mapping rules and dynamic proxy framework, microservices in distributed systems are automatically acquired and executed, and preset mapping identification and input parameters are used to realize automated calls of microservices, reducing configuration difficulties.
It reduces the design cost of remote service calls, improves the efficiency and automation of calls, and simplifies the rapid configuration and execution of microservices.
Smart Images

Figure CN113010332B_ABST
Abstract
Description
Technical Field
[0001] This article belongs to the field of distributed systems, and specifically relates to a remote service calling method, device, equipment and storage medium. Background Art
[0002] Due to the characteristics of distributed systems, the functionality of a transaction service in a stand-alone system may be split into multiple microservices in a distributed system, implemented through combined calls of microservices. Currently, distributed systems are essentially implemented using the RPC (Remote Procedure Call) framework. The main goal of the RPC framework is to make it easier to build distributed applications while providing powerful remote service call capabilities without sacrificing the semantic simplicity of local procedures (LPC). Currently, combined calls of microservices mainly rely on operators to fully configure the microservices to implement remote service calls of microservices. However, when renovating a distributed system or improving microservices, especially when improving the underlying microservices, the microservice configuration files must be redesigned. This design cost and workload are very high, which increases the cost of remote service calls. Therefore, reducing the design cost of remote service calls has become a technical problem that needs to be solved urgently. Summary of the Invention
[0003] In response to the above-mentioned problems in the prior art, the purpose of this article is to provide a remote service calling method, apparatus, device and storage medium, which can reduce the cost of remote service calling design in a distributed system.
[0004] In order to solve the above technical problems, the specific technical solutions of this article are as follows:
[0005] In one aspect, this document provides a remote service invocation method, the method comprising:
[0006] Obtaining service information to be requested, where the service information to be requested includes a plurality of microservices to be executed according to a preset time sequence;
[0007] Determine mapping parameters for each microservice in the distributed system according to preset mapping rules, where the mapping parameters include a preset mapping identifier and input parameters;
[0008] Determine mapping parameters of the initial microservice according to the preset timing, and obtain and execute the initial microservice in the distributed system according to the preset mapping identifier and input parameters of the initial microservice;
[0009] When the initial microservice is successfully executed, the execution status of the initial microservice and the mapping parameters of the next microservice are written into the output message of the initial microservice;
[0010] Continue executing the next microservice according to the mapping parameters of the next microservice in the output message.
[0011] Furthermore, the establishment of the preset mapping rule includes:
[0012] Obtain all microservices based on the distributed system and determine attribute information of the microservices, wherein the attribute information includes microservice type and microservice location;
[0013] According to the attribute information of the microservice and the preset mapping identifier, a mapping relationship between the microservice and the preset mapping identifier is established, so that the microservice corresponding to the preset mapping identifier is obtained from the distributed system through the preset mapping identifier.
[0014] Preferably, the obtaining of the service information to be requested includes:
[0015] A dynamic proxy framework is established, and dynamic proxy annotations are performed on all microservices on the distributed system, and the automatic execution of the microservices corresponding to the preset mapping identifiers is achieved through the dynamic proxy annotations.
[0016] Furthermore, determining the mapping parameters of each microservice in the distributed system according to a preset mapping rule includes:
[0017] Determine the input parameters of each microservice based on the service information to be requested;
[0018] Determine the preset mapping identifier of each microservice in the distributed system according to the preset mapping rules;
[0019] The mapping parameters are determined according to the preset mapping identifier and the input parameters using a preset format conversion rule.
[0020] Furthermore, determining the mapping parameters according to the preset mapping identifier and the input parameters by using preset format conversion rules includes:
[0021] Converting the input parameters into parameters in a preset format according to the preset format conversion rules;
[0022] The mapping parameters are determined according to the converted preset format parameters and the preset mapping identifier, and the mapping parameters are stored in the memory.
[0023] Preferably, the preset format conversion rule is JSON string conversion.
[0024] Furthermore, the obtaining of the service information to be requested includes:
[0025] Determine multiple microservices in the service information to be requested;
[0026] Determine whether all of the microservices are in the local database;
[0027] If all of the multiple microservices are in the local database, the microservices are executed according to a preset time sequence to implement the requested service;
[0028] If the plurality of microservices are not all in the local database, a mapping process is performed on each microservice to implement the execution of all microservices.
[0029] Furthermore, if the plurality of microservices are not all in the local database, a mapping process is performed on each microservice to implement the execution of all microservices, including:
[0030] Determine whether all of the plurality of microservices are in a database based on a distributed system;
[0031] If all of the plurality of microservices are in a database based on a distributed system, determining a mapping parameter of each microservice in the distributed system according to a preset mapping rule;
[0032] If the plurality of microservices are not all in the database based on the distributed system, the database based on the distributed system is updated so that the plurality of microservices are all in the updated database based on the distributed system.
[0033] Furthermore, the updating of the database based on the distributed system includes:
[0034] Get the target microservice that is not in the database based on the distributed system;
[0035] Determine a matching microservice based on the target microservice, wherein the matching microservice is a microservice in a database based on a distributed system whose matching degree with the target microservice reaches a preset value;
[0036] The matching microservice is updated so that the updated matching microservice is consistent with the target microservice.
[0037] Furthermore, the updating of the database based on the distributed system includes:
[0038] Get the target microservice that is not in the database based on the distributed system;
[0039] When the matching degree between the target microservice and all microservices in the database based on the distributed system does not reach a preset value;
[0040] The target microservice is added to a database based on a distributed system, so that an updated database based on a distributed system includes the target microservice.
[0041] Furthermore, the updating of the distributed system-based database so that all of the plurality of microservices are in the updated distributed system-based database includes:
[0042] According to the updated target microservice in the distributed system-based database, determining a preset mapping identifier of the target microservice by using an established preset mapping rule;
[0043] Determine the mapping parameters of the target microservice according to the preset mapping identifier and the input parameters corresponding to the target microservice, and store the mapping parameters in the memory.
[0044] Furthermore, the acquiring and executing the initial microservice in the distributed system according to the preset mapping identifier and input parameters of the initial microservice includes:
[0045] According to the preset mapping identifier, an initial microservice in a database based on a distributed system is obtained;
[0046] The input parameters are input into the initial microservice, the initial microservice is executed, and an execution status of the initial microservice is obtained.
[0047] Furthermore, the next microservice is determined by the preset timing.
[0048] The continuing to execute the next microservice according to the mapping parameter of the next microservice in the output message includes:
[0049] Determine a preset mapping identifier and input parameters in a mapping parameter of a next microservice in the output message, and update the next microservice to the current microservice;
[0050] Execute the current microservice according to the preset mapping identifier and input parameters of the current microservice;
[0051] When the current microservice is successfully executed, the execution status of the current microservice and the mapping parameters of the next microservice are written into the output message of the current microservice;
[0052] According to the output message of the current microservice, the next microservice is executed, and so on, until all microservices are fully executed.
[0053] On the other hand, this document also provides a remote service invocation device, the device comprising:
[0054] A service acquisition module to be requested is used to obtain information about services to be requested, wherein the information about services to be requested includes a plurality of microservices to be executed according to a preset time sequence;
[0055] A mapping module, configured to determine mapping parameters of each microservice in a distributed system according to a preset mapping rule, wherein the mapping parameters include a preset mapping identifier and input parameters;
[0056] An initial microservice execution module, configured to determine mapping parameters of the initial microservice according to the preset timing, and acquire and execute the initial microservice in the distributed system according to the preset mapping identifier and input parameters of the initial microservice;
[0057] An output message acquisition module is used to write the execution status of the initial microservice and the mapping parameters of the next microservice into the output message of the initial microservice when the initial microservice is successfully executed;
[0058] The microservice execution module is configured to continue executing the next microservice according to the mapping parameters of the next microservice in the output message.
[0059] On the other hand, this document also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method described above when executing the computer program.
[0060] On the other hand, this document also provides a computer-readable storage medium, which stores an executable computer program, and when the computer program is executed by a processor, it implements the steps of the method described above.
[0061] By adopting the above technical solution, a remote service calling method, apparatus, device and storage medium described in this article obtains the mapping parameters of multiple microservices in the service information to be requested by setting preset mapping rules, and determines the execution of the next microservice according to the execution status of the previous microservice based on the mapping parameters and the execution order of the microservices, thereby realizing automatic remote service calling of the service to be requested. The remote service calling method provided in this article is simple in design, and realizes the rapid acquisition and execution of different microservices through preset mapping rules and a dynamic proxy framework, saving the design cost of remote service calling of distributed systems.
[0062] In order to make the above and other purposes, features and advantages of this article more obvious and easy to understand, the following specifically cites preferred embodiments and provides detailed descriptions in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] In order to more clearly illustrate the technical solutions in the embodiments of this article or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of this article. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0064] Figure 1 A schematic diagram of an implementation environment of the remote service calling method provided in the embodiments of this document is shown;
[0065] Figure 2 A schematic diagram showing the steps of the remote service calling method provided in the embodiment of this document is shown;
[0066] Figure 3 A schematic diagram showing the steps of the remote service calling method provided in the embodiment of this document is shown;
[0067] Figure 4 A schematic diagram of the steps for determining mapping parameters in the embodiment of this document is shown;
[0068] Figure 5 A schematic diagram of the judgment steps of microservices in a distributed system in the embodiment of this article is shown;
[0069] Figure 6 It shows a schematic structural diagram of the remote service calling device provided in the embodiments of this article;
[0070] Figure 7 A schematic structural diagram of a computer device provided in the embodiments of this document is shown.
[0071] Description of the accompanying symbols:
[0072] 01. Configuration terminal;
[0073] 02. Server;
[0074] 100. Module for obtaining services to be requested;
[0075] 200, mapping module;
[0076] 300. Initial microservice execution module;
[0077] 400, output message acquisition module;
[0078] 500. Microservice execution module;
[0079] 702. Computer equipment;
[0080] 704, processor;
[0081] 706. Memory;
[0082] 708, driving mechanism;
[0083] 710, input / output module;
[0084] 712. Input devices;
[0085] 714. Output device;
[0086] 716. Presentation equipment;
[0087] 718. Graphical User Interface;
[0088] 720, network interface;
[0089] 722, communication link;
[0090] 724. Communication bus. DETAILED DESCRIPTION
[0091] The following will be combined with the accompanying drawings to clearly and completely describe the technical solutions in the embodiments of this document. Obviously, the embodiments described are only part of the embodiments of this document, not all of the embodiments. Based on the embodiments of this document, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this document.
[0092] It should be noted that the terms "first," "second," and the like in the specification and claims herein and in the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, apparatus, product, or device comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to these processes, methods, products, or devices.
[0093] The implementation of a service function is completed through calls between multiple program modules and multiple functions. In a distributed system, the logic of a function may become a remote method call (RPC). In order to implement the call of remote services in a distributed system, the existing technology usually uses an integration unit (or processing unit) to implement the call of the corresponding database of different servers. The call path of each integration unit needs to be configured in advance by the operator on the back end. Therefore, when facing the transformation of a distributed system or the transformation of a large number of ground-level microservices, the configuration of the integration unit will be a big problem, which greatly increases the design cost and configuration difficulty of the integration unit.
[0094] Therefore, if Figure 1 As shown in FIG, it is a schematic diagram of the implementation environment of the method provided in the embodiment of this specification. Figure 1 As shown, the implementation environment may include at least a configuration terminal 01 and a server 02 .
[0095] Specifically, the configuration terminal 01 may include devices such as smartphones, desktop computers, tablet computers, laptops, digital assistants, smart wearable devices, monitoring devices, and voice interaction devices. It may also include software running on the device, such as web pages provided by service providers to users, or applications provided by these service providers to users. Specifically, the configuration terminal 01 can be used to obtain user configuration information, dynamically proxy the microservices in the server 02, store user operation command data, and extract and execute microservices in the server 02 based on user operation commands.
[0096] Specifically, the server 02 can be a distributed system. Optionally, it can be an independent physical server, or a server cluster composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server 02 may include a network communication unit, a processor, a memory, and the like. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application. Specifically, the server 02 can be used to store microservice information corresponding to the service.
[0097] In order to solve the above problems, the embodiments of this article provide a remote service calling method, which can reduce the design cost of remote service calling and improve the efficiency of remote service calling. Figure 2 This is a step diagram of a remote service calling method provided in the embodiment of this article. This specification provides the method operation steps described in the embodiment or flowchart, but it may include more or fewer operation steps based on conventional or non-creative work. The order of steps listed in the embodiment is only one way of executing the steps among many steps, and does not represent the only execution order. When the actual system or device product is executed, it can be executed in the order or in parallel according to the method shown in the embodiment or the accompanying drawings. Specifically, Figure 2 As shown, the method may include:
[0098] S101: Obtaining service information to be requested, where the service information to be requested includes a plurality of microservices to be executed according to a preset time sequence;
[0099] S102: Determine mapping parameters for each microservice in the distributed system according to a preset mapping rule, where the mapping parameters include a preset mapping identifier and input parameters;
[0100] S103: Determine mapping parameters of the initial microservice according to the preset time sequence, and obtain and execute the initial microservice in the distributed system according to the preset mapping identifier and input parameters of the initial microservice;
[0101] S104: When the initial microservice is successfully executed, the execution status of the initial microservice and the mapping parameters of the next microservice are written into the output message of the initial microservice;
[0102] S105: Continue executing the next microservice according to the mapping parameters of the next microservice in the output message.
[0103] In the embodiments of this specification, mapping parameters of each microservice in the microservice to be requested are determined through preset mapping rules, wherein the microservices in the distributed system can be obtained through the preset mapping identifier, and the input parameters are brought into the corresponding microservice, thereby realizing the automatic execution of the microservice, and then the mapping parameters of the next microservice are determined by the execution success status of the initial microservice, and so on to realize the execution of all microservices. The method provided in this article can quickly design the received information to be requested through pre-configuration, thereby reducing the design cost of remote service calls and improving the efficiency of remote service calls.
[0104] The requested service can be a specific business request, and each business request can be implemented by multiple sub-businesses (microservices). For example, a transfer business can include two sub-businesses: transferring the payer's account amount out and transferring the payee's account amount in. In a distributed system, not all microservices are on the local server, so it is necessary to use remote service calls to execute microservices. The remote service call can be understood as calling the service of the remote server through an http request to complete the processing of the method logic. Each microservice can refer to an independent program module, which can include functions corresponding to specific execution methods, and of course can also include multiple functions. Multiple functions can also be presented in a distributed setting, which is not limited in this specification.
[0105] The preset mapping rule can be understood as the relationship between the microservices in the distributed system and their preset mapping identifiers. The microservice corresponding to the preset mapping identifier can be obtained through the preset mapping identifier. Optionally, the type and location of the microservice can be determined through the preset mapping identifier. After obtaining the specific location, the microservice can be obtained by establishing a call path.
[0106] In the embodiment of this specification, establishing the preset mapping rule includes the following steps:
[0107] Obtain all microservices based on the distributed system and determine attribute information of the microservices, wherein the attribute information includes microservice type and microservice location;
[0108] According to the attribute information of the microservice and the preset mapping identifier, a mapping relationship between the microservice and the preset mapping identifier is established, so that the microservice corresponding to the preset mapping identifier is obtained from the distributed system through the preset mapping identifier.
[0109] It can be understood that after the original system has been distributedly transformed, the microservices in the distributed system have been determined, including the type of microservice and its location. Therefore, by establishing a mapping relationship between a preset mapping identifier and a microservice, the microservice can be quickly determined through the preset mapping identifier, wherein the preset mapping identifier is an artificially set identifier, which can be a transaction code for the remote service call of the microservice. The preset mapping identifier is configured in the memory. After different microservices are determined through the requested service, the preset mapping identifier can be determined through the determined microservice. For example, the preset mapping identifier can be determined by the microservice type. The microservice type can represent the method type or function type corresponding to the microservice, etc., which is not limited in this specification.
[0110] In the prior art, the remote service call logic of each microservice in the requested service is manually configured, and the microservices are executed in sequence through the integration unit. Therefore, the configuration process is relatively labor-intensive for scenarios with a large number of microservices, and it is difficult to achieve rapid configuration and execution of the requested service. Therefore, in order to achieve automatic execution of each microservice with less configuration, in the embodiment of this specification, Figure 3 As shown, before obtaining the service information to be requested, the following steps are also included:
[0111] S100: Establish a dynamic proxy framework and perform dynamic proxy annotations on all microservices on the distributed system, and automatically execute the microservices corresponding to the preset mapping identifiers through the dynamic proxy annotations.
[0112] It can be understood that the dynamic proxy framework is a framework established on a distributed system. In this way, when the microservices that need to be executed are determined, the automatic operation of the microservices can be realized on the server (distributed system) side, avoiding the configuration of the integration unit of each microservice execution file on the caller (such as the application side) in the existing technology. Through a single dynamic proxy configuration, the automatic execution of microservices in the distributed system can be realized, which reduces the difficulty of configuring request information and improves automation.
[0113] Specifically, dynamic proxy processing can be implemented using Aspect Orient Programming (AOP), a mature dynamic proxy technology in Java. It can add functionality without code intrusion and is widely used to process system-level services with cross-cutting nature. AOP can be used to intercept various business items in a business class (such as a business method), thereby reducing the coupling between various parts of the business class, improving program reusability, and increasing development efficiency. In some other embodiments, dynamic proxy can be implemented through the Spring framework by configuring it through Spring XML. The specific dynamic proxy method is not limited in the embodiments of this specification.
[0114] In actual work, dynamic proxy annotations, such as Java annotations, can be used on the dynamic proxy framework to implement dynamic proxying of all microservices (methods) in the distributed system. In this way, when obtaining a request for the corresponding microservice through a preset mapping identifier, the preset mapping identifier and input parameters are intercepted, and the microservice corresponding to the preset mapping identifier is called using the reflection mechanism of the dynamic proxy framework, and the execution of the microservice is implemented in combination with the input parameters. When the previous microservice is executed successfully and returns an output message, the mapping parameters of the next microservice in the output message are obtained, and then the next microservice is automatically executed. The execution request of the next microservice (including the preset mapping identifier and input parameters of the next microservice) is intercepted by the dynamic proxy framework, and the reflection mechanism of the dynamic proxy framework is used to call the microservice corresponding to the preset mapping identifier. The execution of the next microservice is realized in combination with the input parameters. This process is repeated until all services are automatically executed. Therefore, this article realizes the automatic execution of remote service calls through the execution results of the previous microservice and the dynamic proxy, reducing the design cost of each microservice configuration. It should be noted that the next microservice after each microservice is executed is determined by a preset timing. When the service information to be requested is determined, the preset timing is also determined and automatically generated through the configuration file.
[0115] The execution process of the initial microservice may be:
[0116] According to the preset mapping identifier, an initial microservice in a database based on a distributed system is obtained;
[0117] The input parameters are input into the initial microservice, the initial microservice is executed, and an execution status of the initial microservice is obtained.
[0118] It can be understood that the initial microservice can be the first microservice in the microservice execution sequence, and the automatic execution of the initial microservice can be achieved through the above dynamic proxy framework.
[0119] In the embodiment of this specification, continuing to execute the next microservice according to the mapping parameters of the next microservice in the output message may include the following steps:
[0120] Determine a preset mapping identifier and input parameters in a mapping parameter of a next microservice in the output message, and update the next microservice to the current microservice;
[0121] Execute the current microservice according to the preset mapping identifier and input parameters of the current microservice;
[0122] When the current microservice is successfully executed, the execution status of the current microservice and the mapping parameters of the next microservice are written into the output message of the current microservice;
[0123] According to the output message of the current microservice, the next microservice is executed, and so on, until all microservices are fully executed.
[0124] In the embodiments of this specification, Figure 4 As shown, determining the mapping parameters of each microservice in the distributed system according to the preset mapping rule may include the following steps:
[0125] S201: Determine input parameters for each microservice based on the service information to be requested;
[0126] S202: Determine a preset mapping identifier for each microservice in the distributed system according to a preset mapping rule;
[0127] S203: Determine the mapping parameters according to the preset mapping identifier and the input parameters using preset format conversion rules.
[0128] The input parameters may be parameter names and parameter values for executing the corresponding method of each microservice. When the requested service information is received, the input parameters are already determined. The preset mapping identifier corresponding to each microservice can be determined by the above-mentioned steps of establishing the preset mapping rule.
[0129] Since the data in the input parameters, such as parameter names, cannot be directly identified, the input parameters can be converted into preset format parameters through preset format conversion rules for storage, thereby facilitating parameter reading and input during storage and automatic execution of the method. Therefore, the acquisition process of the mapping parameters may include:
[0130] Converting the input parameters into parameters in a preset format according to the preset format conversion rules;
[0131] The mapping parameters are determined according to the converted preset format parameters and the preset mapping identifier, and the mapping parameters are stored in the memory.
[0132] In actual work, the preset format conversion rule can be JSON string conversion. JSON string is a lightweight data storage format in the form of key-value pairs, which can achieve fast transmission between function methods and improve the efficiency of microservice processing.
[0133] The method provided in the embodiments of this specification is applicable to scenarios where remote service calls are made. Not all scenarios require remote service calls. Therefore, after obtaining the service information to be requested, a determination may be made as to whether to make a remote service call. The determination may be as follows:
[0134] Determine multiple microservices in the service information to be requested;
[0135] Determine whether all of the microservices are in the local database;
[0136] If all of the multiple microservices are in the local database, the microservices are executed according to a preset time sequence to implement the requested service;
[0137] If the plurality of microservices are not all in the local database, a mapping process is performed on each microservice to implement the execution of all microservices.
[0138] Among them, the local database can be the database corresponding to the server where the user inputs the requested service. When all the microservices in the requested information are in the local database, local calls can be made directly to implement the methods corresponding to all microservices. This can increase the calling speed and reduce the design cost of the remote service call configuration file.
[0139] In actual work, the judgment can be made through the preset mapping identifier, which can represent the microservice type (method type or method name). By determining the preset mapping identifiers of multiple microservices corresponding to the requested service and comparing them with the preset mapping identifiers of the microservices in the local database, if all can be matched, it indicates that all microservices of the requested service are in the local database. If not all can be matched, it indicates that not all microservices of the requested microservice are in the local database. It should be noted that in some special cases, some microservices do not determine the preset mapping identifiers, indicating that the microservice is not in all databases of the distributed system, and the database needs to be updated. The specific update process is described below.
[0140] When the multiple microservices corresponding to the requested service are not all in the local database, the automatic execution of the microservices can be achieved through the above-mentioned remote service call method. It should be noted that as the requested services become more and more complex and the scenarios become more and more abundant, the microservices required to implement some special scenarios may not be in the existing distributed system database. Therefore, the database needs to be updated in a timely manner, such as Figure 5 As shown, the following steps may be used to determine whether all microservices corresponding to the requested service are in the database of the distributed system:
[0141] S301: Determine whether all of the plurality of microservices are in a database based on a distributed system;
[0142] S302: If all of the plurality of microservices are in a database based on a distributed system, determining a mapping parameter of each microservice in the distributed system according to a preset mapping rule;
[0143] S303: If not all of the plurality of microservices are in the database based on the distributed system, update the database based on the distributed system so that all of the plurality of microservices are in the updated database based on the distributed system.
[0144] In actual work, it is also possible to make a judgment by using a preset mapping identifier. The specific judgment process is consistent with the above and will not be described in detail in this embodiment of the specification. By timely judging the microservice, the efficiency of updating the database can be improved, thereby improving the adaptability to different scenarios and enhancing the user experience.
[0145] Wherein, updating the database based on the distributed system may include the following steps:
[0146] Get the target microservice that is not in the database based on the distributed system;
[0147] Determine a matching microservice based on the target microservice, wherein the matching microservice is a microservice in a database based on a distributed system whose matching degree with the target microservice reaches a preset value;
[0148] The matching microservice is updated so that the updated matching microservice is consistent with the target microservice.
[0149] It can be understood that the type, structure, parameters, etc. of the microservice corresponding method can be matched to obtain a microservice with a high degree of matching with the target microservice. In this way, when updating, only the microservice with a high degree of matching with the target microservice needs to be adjusted, which can improve the efficiency of adjustment and avoid the consumption of database memory resources, saving memory costs. Optionally, the preset value can be a parameter set according to actual conditions, which is not limited in the embodiments of this specification.
[0150] When there is no microservice matching the target microservice in all databases of the distributed system, it is necessary to further adjust the database. Specifically, the following steps may be included:
[0151] Get the target microservice that is not in the database based on the distributed system;
[0152] When the matching degree between the target microservice and all microservices in the database based on the distributed system does not reach a preset value;
[0153] The target microservice is added to a database based on a distributed system, so that an updated database based on a distributed system includes the target microservice.
[0154] In actual work, the target microservice can be added to the local database, which can improve the speed of database update and ensure the accuracy of microservice addition.
[0155] After updating the database by the above adjustment or addition method, the updated microservices also need to determine the corresponding preset mapping identifiers to facilitate the acquisition of the microservices. Therefore, the updating of the distributed system-based database so that the plurality of microservices are all in the updated distributed system-based database further includes the following steps:
[0156] According to the updated target microservice in the distributed system-based database, determining a preset mapping identifier of the target microservice by using an established preset mapping rule;
[0157] Determine the mapping parameters of the target microservice according to the preset mapping identifier and the input parameters corresponding to the target microservice, and store the mapping parameters in the memory.
[0158] It can be understood that through the above update process, microservices that cannot be automatically matched can be manually injected into the automatically executed program, which can improve the adaptability of the remote service call method to services in different scenarios and improve the user experience.
[0159] The remote service calling method provided in the embodiments of this specification obtains mapping parameters of multiple microservices in the service information to be requested by setting preset mapping rules, and determines the execution of the next microservice according to the execution status of the previous microservice based on the mapping parameters and the execution order of the microservices, thereby realizing automatic remote service calling of the service to be requested. The remote service calling method provided in this article is simple in design, and realizes rapid acquisition and execution of different microservices through preset mapping rules and a dynamic proxy framework, saving the design cost of remote service calling of distributed systems.
[0160] Based on the same inventive concept, on the basis of the above-mentioned method, the embodiment of this specification also provides a remote service calling device, such as Figure 6 As shown, the device includes:
[0161] The service acquisition module 100 is used to acquire information about the service to be requested, where the information includes a plurality of microservices to be executed in a preset sequence.
[0162] A mapping module 200 is configured to determine mapping parameters for each microservice in the distributed system according to a preset mapping rule, wherein the mapping parameters include a preset mapping identifier and input parameters;
[0163] The initial microservice execution module 300 is configured to determine the mapping parameters of the initial microservice according to the preset timing, and obtain and execute the initial microservice in the distributed system according to the preset mapping identifier and input parameters of the initial microservice;
[0164] The output message acquisition module 400 is configured to write the execution status of the initial microservice and the mapping parameters of the next microservice into the output message of the initial microservice when the initial microservice is successfully executed;
[0165] The microservice execution module 500 is configured to continue executing the next microservice according to the mapping parameters of the next microservice in the output message.
[0166] The beneficial effects achieved by the above-mentioned device are consistent with the beneficial effects achieved by the above-mentioned method, and will not be described in detail in the embodiments of this specification.
[0167] like Figure 7As shown, a computer device provided in an embodiment of the present invention is shown. The computer device 702 may include one or more processors 704, such as one or more central processing units (CPUs), each of which may implement one or more hardware threads. The computer device 702 may also include any memory 706 for storing any type of information, such as code, settings, data, etc. For example, without limitation, the memory 706 may include any one or more combinations of the following: any type of RAM, any type of ROM, a flash memory device, a hard disk, an optical disk, etc. More generally, any memory may use any technology to store information. Furthermore, any memory may provide volatile or non-volatile retention of information. Furthermore, any memory may represent a fixed or removable component of the computer device 702. In one embodiment, when the processor 704 executes associated instructions stored in any memory or combination of memories, the computer device 702 may perform any operation of the associated instructions. The computer device 702 also includes one or more drive mechanisms 708, such as a hard disk drive mechanism, an optical disk drive mechanism, etc., for interacting with any memory.
[0168] Computer device 702 may also include an input / output module 710 (I / O) for receiving various inputs (via input devices 712) and providing various outputs (via output devices 714). A specific output mechanism may include a presentation device 716 and an associated graphical user interface (GUI) 718. In other embodiments, input / output module 710 (I / O), input devices 712, and output devices 714 may not be included, and the computer device 702 may simply be a computer device in a network. Computer device 702 may also include one or more network interfaces 720 for exchanging data with other devices via one or more communication links 722. One or more communication buses 724 couple the components described above together.
[0169] The communication link 722 may be implemented in any manner, for example, via a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 722 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc., governed by any protocol or combination of protocols.
[0170] Corresponding to Figure 2-Figure 5 The embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which executes the steps of the above method when executed by a processor.
[0171] The embodiment of the present invention also provides a computer readable instruction, wherein when the processor executes the instruction, the program causes the processor to execute the following Figures 2 to 5The method shown.
[0172] It should be understood that in the various embodiments of this document, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this document.
[0173] It should also be understood that in the embodiments herein, the term "and / or" merely describes an association between associated objects, indicating that three possible relationships exist. For example, "A and / or B" could represent: A alone, A and B simultaneously, or B alone. Furthermore, the character " / " in this document generally indicates an "or" relationship between the associated objects.
[0174] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the composition and steps of each example according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this document.
[0175] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0176] In the several embodiments provided herein, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices, or units, or can be an electrical, mechanical, or other form of connection.
[0177] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments herein.
[0178] In addition, the functional units in the various embodiments herein may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0179] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this article is essentially or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of this article. The aforementioned storage medium includes: various media that can store program code, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0180] This article uses specific embodiments to illustrate the principles and implementation methods of this article. The description of the above embodiments is only used to help understand the methods and core ideas of this article. At the same time, for those skilled in the art, based on the ideas of this article, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation to this article.
Claims
1. A remote service calling method, characterized in that: The method comprises: Obtaining service information to be requested, where the service information to be requested includes a plurality of microservices to be executed according to a preset time sequence; Determine mapping parameters for each microservice in the distributed system according to preset mapping rules, where the mapping parameters include a preset mapping identifier and input parameters; Determine mapping parameters of the initial microservice according to the preset timing, and obtain and execute the initial microservice in the distributed system according to the preset mapping identifier and input parameters of the initial microservice; When the initial microservice is successfully executed, the execution status of the initial microservice and the mapping parameters of the next microservice are written into the output message of the initial microservice; Continue executing the next microservice according to the mapping parameters of the next microservice in the output message; The obtaining of the service information to be requested previously includes: Establish a dynamic proxy framework and perform dynamic proxy annotations on all microservices on the distributed system, and automatically execute the microservices corresponding to the preset mapping identifiers through the dynamic proxy annotations; According to the preset mapping identifier and input parameters of the initial microservice, obtaining and executing the initial microservice in the distributed system further includes: Intercepting the preset mapping identifier and input parameters, using the reflection mechanism of the dynamic proxy framework to call the microservice corresponding to the preset mapping identifier, and implementing the execution of the microservice in combination with the input parameters; Continuing to execute the next microservice according to the mapping parameters of the next microservice in the output message further includes: The preset mapping identifier and input parameters of the next microservice are intercepted by the dynamic proxy framework, the microservice corresponding to the preset mapping identifier is called using the reflection mechanism of the dynamic proxy framework, and the execution of the next microservice is realized in combination with the input parameters.
2. The method according to claim 1, characterized in that The establishment of the preset mapping rule includes: Obtain all microservices based on the distributed system and determine attribute information of the microservices, wherein the attribute information includes microservice type and microservice location; According to the attribute information of the microservice and the preset mapping identifier, a mapping relationship between the microservice and the preset mapping identifier is established, so that the microservice corresponding to the preset mapping identifier is obtained from the distributed system through the preset mapping identifier.
3. The method according to claim 1, characterized in that Determining the mapping parameters of each microservice in the distributed system according to the preset mapping rules includes: Determine the input parameters of each microservice based on the service information to be requested; Determine the preset mapping identifier of each microservice in the distributed system according to the preset mapping rules; The mapping parameters are determined according to the preset mapping identifier and the input parameters using a preset format conversion rule.
4. The method according to claim 3, characterized in that The determining the mapping parameters according to the preset mapping identifier and the input parameters by using a preset format conversion rule includes: Converting the input parameters into parameters in a preset format according to the preset format conversion rules; The mapping parameters are determined according to the converted preset format parameters and the preset mapping identifier, and the mapping parameters are stored in the memory.
5. The method according to claim 4, characterized in that The preset format conversion rule is JSON string conversion.
6. The method according to claim 1, characterized in that The step of obtaining the service information to be requested includes: Determine multiple microservices in the service information to be requested; Determine whether all of the microservices are in the local database; If all of the multiple microservices are in the local database, the microservices are executed according to a preset time sequence to implement the requested service; If the plurality of microservices are not all in the local database, a mapping process is performed on each microservice to implement the execution of all microservices.
7. The method according to claim 6, characterized in that If the plurality of microservices are not all in the local database, a mapping process is performed on each microservice to implement the execution of all microservices, including: Determine whether all of the plurality of microservices are in a database based on a distributed system; If all of the plurality of microservices are in a database based on a distributed system, determining a mapping parameter of each microservice in the distributed system according to a preset mapping rule; If the plurality of microservices are not all in the database based on the distributed system, the database based on the distributed system is updated so that the plurality of microservices are all in the updated database based on the distributed system.
8. The method according to claim 7, characterized in that The updating of the distributed system-based database includes: Get the target microservice that is not in the database based on the distributed system; Determine a matching microservice based on the target microservice, wherein the matching microservice is a microservice in a database based on a distributed system whose matching degree with the target microservice reaches a preset value; The matching microservice is updated so that the updated matching microservice is consistent with the target microservice.
9. The method according to claim 8, characterized in that The updating of the distributed system-based database includes: Get the target microservice that is not in the database based on the distributed system; When the matching degree between the target microservice and all microservices in the database based on the distributed system does not reach a preset value; The target microservice is added to a database based on a distributed system, so that an updated database based on a distributed system includes the target microservice.
10. The method according to claim 9, characterized in that The updating of the distributed system-based database so that all of the plurality of microservices are in the updated distributed system-based database includes: According to the updated target microservice in the distributed system-based database, determining a preset mapping identifier of the target microservice by using an established preset mapping rule; Determine the mapping parameters of the target microservice according to the preset mapping identifier and the input parameters corresponding to the target microservice, and store the mapping parameters in the memory.
11. The method according to claim 1, wherein The acquiring and executing the initial microservice in the distributed system according to the preset mapping identifier and input parameters of the initial microservice includes: According to the preset mapping identifier, an initial microservice in a database based on a distributed system is obtained; The input parameters are input into the initial microservice, the initial microservice is executed, and an execution status of the initial microservice is obtained.
12. The method according to claim 1, characterized in that The next microservice is determined by the preset timing.
13. The method according to claim 1, wherein The continuing to execute the next microservice according to the mapping parameter of the next microservice in the output message includes: Determine a preset mapping identifier and input parameters in a mapping parameter of a next microservice in the output message, and update the next microservice to the current microservice; Execute the current microservice according to the preset mapping identifier and input parameters of the current microservice; When the current microservice is successfully executed, the execution status of the current microservice and the mapping parameters of the next microservice are written into the output message of the current microservice; According to the output message of the current microservice, the next microservice is executed, and so on, until all microservices are fully executed.
14. A remote service calling device, characterized in that: The device comprises: A service acquisition module to be requested is used to obtain information about services to be requested, wherein the information about services to be requested includes a plurality of microservices to be executed according to a preset time sequence; A mapping module, configured to determine mapping parameters of each microservice in a distributed system according to a preset mapping rule, wherein the mapping parameters include a preset mapping identifier and input parameters; An initial microservice execution module, configured to determine mapping parameters of the initial microservice according to the preset timing, and acquire and execute the initial microservice in the distributed system according to the preset mapping identifier and input parameters of the initial microservice; An output message acquisition module is used to write the execution status of the initial microservice and the mapping parameters of the next microservice into the output message of the initial microservice when the initial microservice is successfully executed; A microservice execution module, configured to continue executing the next microservice according to the mapping parameters of the next microservice in the output message; The device is further configured to: before obtaining the service information to be requested, establish a dynamic proxy framework and perform dynamic proxy annotations on all microservices on the distributed system, and automatically execute the microservice corresponding to the preset mapping identifier through the dynamic proxy annotations; According to the preset mapping identifier and input parameters of the initial microservice, obtaining and executing the initial microservice in the distributed system further includes: Intercepting the preset mapping identifier and input parameters, using the reflection mechanism of the dynamic proxy framework to call the microservice corresponding to the preset mapping identifier, and implementing the execution of the microservice in combination with the input parameters; Continuing to execute the next microservice according to the mapping parameters of the next microservice in the output message further includes: The preset mapping identifier and input parameters of the next microservice are intercepted by the dynamic proxy framework, the microservice corresponding to the preset mapping identifier is called using the reflection mechanism of the dynamic proxy framework, and the execution of the next microservice is realized in combination with the input parameters.
15. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 13 are implemented.
16. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 13 are implemented.
Citation Information
Patent Citations
All-link-road monitoring method, device and system under micro service architecture
CN107135276A
Request processing method and device based on microservice
CN110519379A