Micro-service calling method and device and micro-service configuration method and device
By configuring domain name mapping rules in the microservice architecture, allowing local microservices to directly use the service domain name to call remote microservices, the call failure problem caused by network instability is solved, and the stability and flexibility of the microservice architecture is improved.
Patent Information
- Application Number
- CN202510562118.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-07-25
AI Technical Summary
In the microservice architecture, when the network between the local microservice and the registry is poor, the remote microservice cannot be called, resulting in the service request failure.
By configuring domain name mapping rules in local microservices, directly use the service domain name to call remote microservices, avoiding relying on the registry discovery mechanism.
It realizes that remote microservices can be called normally even in the case of network instability, improves the stability and flexibility of the microservice architecture and reduces the risk of network dependence.
Smart Images

Figure CN120378491A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technologies, and in particular, to a microservice call method and apparatus, and a microservice configuration method and apparatus. Background Art
[0002] With the continuous development of science and technology, the microservice architecture has been widely used in the online services of Internet enterprises.
[0003] In related technologies, a microservice architecture consists of multiple microservices. To complete a business, the microservice architecture usually divides multiple microservices into local microservices for processing the business and remote microservices for local microservices to call. Secondly, all microservices within the microservice architecture are usually deployed in their respective Docker containers to enhance the overall security and independence of the microservice architecture by virtue of the network isolation characteristics of the Docker containers themselves. To facilitate the mutual calls between different microservices in the microservice architecture, after the microservices are deployed in Docker containers, they are usually registered in a registration center. Thus, when a local microservice that processes service requests in the microservice architecture needs to call a remote microservice, it can request the registration domain name registered by the remote microservice in the registration center from the registration center, and call the remote microservice according to the registration domain name, so that the remote microservice can assist the local microservice in processing the service request.
[0004] However, during the process of a local microservice calling a remote microservice, it is necessary to rely on the network to request the registration domain name from the registration center. If the network condition between the local microservice and the registration center is poor, the local microservice may not be able to call the remote microservice due to network disconnection. Summary of the Invention
[0005] To solve the above technical problems, embodiments of this application provide a microservice call method and apparatus, a microservice configuration method and apparatus, a computer-readable storage medium, and an electronic device.
[0006] According to one aspect of the embodiments of this application, a microservice call method is provided. The method is applied to a microservice architecture, and the microservice architecture includes a local microservice and a remote microservice. The method is executed by the local microservice, and the method includes: determining a target remote microservice to be called based on a current service request; determining a service domain name corresponding to the target remote microservice according to a domain name mapping rule in the local microservice, where the service domain name is a domain name for accessing the target remote microservice, and the domain name mapping rule includes a mapping rule when the target remote microservice configures the service domain name; and calling the target remote microservice through the service domain name and the current service request.
[0007] According to one aspect of the embodiments of the present application, a microservice configuration method is provided. The method is applied to a microservice architecture, which includes a local microservice and a remote microservice. The method is executed by the remote microservice and includes: sending a registration request to a registration center based on microservice information; if a registration result indicating successful registration is received, configuring a corresponding service domain name according to a mapping rule, so that when the local microservice with the mapping rule calls the remote microservice, it can determine the service domain name according to the mapping rule and call the remote microservice through the service domain name.
[0008] According to one aspect of the embodiments of the present application, a microservice call device is provided. The device is applied to a microservice architecture, which includes a local microservice and a remote microservice. The device includes: a service module configured to determine a target remote microservice to be called based on a current service request; a mapping module configured to determine a service domain name corresponding to the target remote microservice according to a domain name mapping rule in the local microservice, where the service domain name is the domain name for accessing the target remote microservice, and the domain name mapping rule includes the mapping rule when the target remote microservice configures the service domain name; a call module configured to call the target remote microservice through the service domain name and the current service request.
[0009] In some embodiments of the present application, based on the foregoing solution, the mapping module is further configured to: before determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice, determine whether there is a first configuration item in the preset environment variable of the local microservice, where the first configuration item is used to instruct a communication client in the local microservice to replace a default routing rule with a target routing rule; if the determination result is no, control the communication client to request a registration domain name of the target remote microservice from the registration center according to the default routing rule and use the registration domain name as the service domain name; if the determination result is yes, control the communication client to determine the service domain name according to the domain name mapping rule in the target routing rule.
[0010] In some embodiments of the present application, based on the foregoing solution, the mapping module is further configured to: before determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice, determine whether there is a second configuration item in the preset environment variable of the local microservice, where the second configuration item is used to indicate a specified domain name corresponding to the target remote microservice; if the determination result is yes, use the specified domain name as the service domain name; if the determination result is no, determine the service domain name according to the domain name mapping rule.
[0011] In some embodiments of the present application, based on the foregoing solution, the mapping module is further configured to: determine the service priority of the current service request; determine the mapping rule corresponding to the target remote microservice under the service priority from the domain name mapping rules; generate the service domain name for the target remote microservice based on the mapping rule.
[0012] In some embodiments of the present application, based on the foregoing solution, the invocation module is further configured to: obtain the load conditions and service addresses of different service instances in the target remote microservice based on the service domain name; determine the target service instance according to the load conditions of the different service instances; send the current service request to the target service instance based on the service address of the target service instance, so that the target service instance processes the service indicated by the current service request.
[0013] In some embodiments of the present application, based on the foregoing solution, the microservice invocation device further includes an identification module, which is configured to: start timing after invoking the target remote microservice through the service domain name and the current service request; if the timing duration reaches the target preset duration and the invocation of the target remote microservice fails, request the registration domain name of the target remote microservice from the registration center, and update the service domain name based on the registration domain name, so as to invoke the target remote microservice through the updated service domain name and the current invocation request.
[0014] In some embodiments of the present application, based on the foregoing solution, the identification module is further configured to: determine the service priority of the current service request; use the preset duration corresponding to the service priority as the target preset duration.
[0015] According to one aspect of the embodiments of the present application, a microservice configuration device is provided. The device is applied to a microservice architecture, and the microservice architecture includes a local microservice and a remote microservice. The device includes: a registration module configured to send a registration request to a registration center based on microservice information; a configuration module configured to, if a registration result indicating successful registration is received, configure a corresponding service domain name according to a mapping rule, so that when the local microservice with the mapping rule invokes the remote microservice, it can determine the service domain name according to the mapping rule and invoke the remote microservice through the service domain name.
[0016] According to one aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the microservice invocation method or the microservice configuration method as described in the above embodiments.
[0017] According to one aspect of the embodiments of the present application, an electronic device is provided, including: one or more processors; a storage device for storing one or more programs, which when executed by the one or more processors, enable the electronic device to implement the microservice call method or the microservice configuration method as described in the above embodiments.
[0018] In the technical solution of the embodiments of the present application, first, a target remote microservice to be called is determined based on the current service request, then the service domain name corresponding to the target remote microservice is determined according to the domain name mapping rule in the local microservice, and then the target remote microservice is called through the service domain name and the current service request, so that the local microservice can directly access the target remote microservice through the service domain name without necessarily using the registration center discovery mechanism, and drive the target remote microservice to assist the local microservice in processing the service indicated by the current service request according to the current service request, thereby avoiding the situation where the remote microservice cannot be called due to the network connection between the local microservice and the registration center being unavailable. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present application and used together with the specification to explain the principles of the present application. Obviously, the accompanying drawings in the following description are only some embodiments of the present application, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts. In the drawings:
[0020] Figure 1 is a flowchart of a microservice configuration method shown in an exemplary embodiment of the present application;
[0021] Figure 2 is a flowchart of a microservice call method shown in an exemplary embodiment of the present application;
[0022] Figure 3 is Figure 2 a flowchart in an exemplary embodiment before step S220 in the shown embodiment;
[0023] Figure 4 is Figure 2 a flowchart in another exemplary embodiment before step S220 in the shown embodiment;
[0024] Figure 5 is Figure 2 a flowchart of step S230 in an exemplary embodiment in the shown embodiment;
[0025] Figure 6 is a block diagram of a microservice configuration device shown in an exemplary embodiment of the present application;
[0026] Figure 7 It is a block diagram of a microservice call device shown in an exemplary embodiment of the present application;
[0027] Figure 8 It is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present application. Detailed implementation manners
[0028] Example embodiments will now be described more fully with reference to the accompanying drawings. However, the example embodiments can be implemented in various forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more complete and comprehensive, and will fully convey the concept of the example embodiments to those skilled in the art.
[0029] In addition, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of the embodiments of the present application. However, those skilled in the art will realize that the technical solutions of the present application can be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, well-known methods, devices, implementations, or operations are not shown or described in detail to avoid obscuring aspects of the present application.
[0030] The block diagrams shown in the drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0031] The flowcharts shown in the drawings are only exemplary illustrations and do not necessarily include all the contents and operations / steps, nor do they necessarily have to be executed in the described order. For example, some operations / steps can be decomposed, while some operations / steps can be combined or partially combined, so the actual execution order may change according to the actual situation.
[0032] It should be noted that: "a plurality" mentioned herein refers to two or more. "And / or" describes the association relationship of associated objects and indicates that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0033] In the related art, all microservices within a microservices architecture are typically deployed in Docker containers to enhance the security and independence of the microservices architecture by leveraging the network isolation characteristics inherent in Docker containers. To facilitate the mutual invocation between different microservices in the microservices architecture, after deploying the microservices in Docker containers, they are usually registered with a registration center. Thus, when a local microservice that processes service requests in the microservices architecture needs to invoke a remote microservice, it can request the registration domain name registered by the remote microservice in the registration center from the registration center, and then invoke the remote microservice based on the registration domain name, enabling the remote microservice to assist the local microservice in processing service requests. However, during the process of the local microservice invoking the remote microservice, it is necessary to rely on the network to request the registration domain name from the registration center. If the network condition between the local microservice and the registration center is poor, the local microservice may be unable to invoke the remote microservice due to network unavailability.
[0034] To address the above problems, embodiments of the present application propose corresponding microservice configuration methods, microservice invocation methods, and also propose corresponding microservice configuration devices and microservice invocation devices. Additionally, an electronic device and a computer-readable storage medium are proposed. The following provides a detailed description of the content of these embodiments.
[0035] A microservice configuration method proposed by the technical solution of the embodiments of the present application is specifically as follows Figure 1 as shown. This method can be executed by a remote microservice in the microservices architecture, where the remote microservice is a microservice that can be invoked by a local microservice in the microservices architecture. This method at least includes steps S110 to S120, which are introduced in detail as follows:
[0036] In step S110, a registration request is sent to the registration center based on microservice information.
[0037] Among them, the microservice information includes but is not limited to microservice name, IP address, port number, metadata, etc.
[0038] In step S120, if a registration result indicating successful registration is received, a corresponding service domain name is configured according to the mapping rule.
[0039] In an embodiment of the present application, after sending a registration request to the registration center, the registration result feedback by the registration center based on the microservice information can be received. If the registration result indicating successful registration is received, it means that the remote microservice already meets the requirements for being called by the local microservice. Then, the corresponding service domain name can be configured according to the mapping rule, so that when the local microservice with the mapping rule calls the remote microservice, it can determine the service domain name according to the mapping rule and call the remote microservice through the service domain name. As a result, the local microservice can choose not to use the registration center discovery mechanism and instead access and call the remote microservice through the service domain name, driving the remote microservice to assist the local microservice in processing the business, thereby avoiding the situation where the remote microservice cannot be called due to network disconnection between the local microservice and the registration center.
[0040] Among them, the method of configuring the corresponding service domain name according to the mapping rule can be through the Dockerfile. That is, after the remote microservice is registered in the registration center, the Dockerfile automatically configures the service domain name according to the mapping rule. In addition, to improve the security of the remote microservice, the service domain name can be configured on the reverse proxy server (such as Nginx, Squid, and Skipper, etc.). That is, the Dockerfile can automatically configure the service domain name corresponding to the remote microservice on the reverse proxy server to reduce the risk of exposure of the real IP address of the remote microservice when other microservices call the remote microservice.
[0041] The technical solution of the embodiment of the present application also proposes a microservice call method, specifically as shown in Figure 2 The method can be executed by the local microservice in the microservice architecture. The local microservice is a microservice used to process business in the microservice architecture. The method at least includes step S210 to step S230, which are introduced in detail as follows:
[0042] In step S210, determine the target remote microservice to be called based on the current service request.
[0043] Among them, the current service request is used to indicate the business currently to be processed by the local microservice, and the target remote microservice represents the remote microservice that the local microservice needs to call when processing the business indicated by the current service request.
[0044] The method of determining the target remote microservice to be called based on the current service request can be flexibly set according to needs. In one example, the remote microservice can be determined from the current service request, and the determined remote microservice is used as the target remote microservice. That is to say, the current service request can contain the remote microservice that the local microservice needs to call when indicating the local microservice to process the business.
[0045] In another example, considering that when the local microservice processes the business indicated by the service request, there may be a situation where different remote microservices need to be called. Based on this, whenever the current service request indicates a call to a remote microservice, the indicated remote microservice to be called can be used as the target remote microservice.
[0046] In step S220, the service domain name corresponding to the target remote microservice is determined according to the domain name mapping rule in the local microservice.
[0047] Among them, the service domain name is the domain name for accessing the target remote microservice, that is, the target remote microservice can be directly accessed and called through this service domain name. And the domain name mapping rule includes the mapping rule when the target remote microservice configures the service domain name.
[0048] In the implementation manner of this application, after determining the target remote microservice to be called, the service domain name corresponding to the target remote microservice can be determined according to the domain name mapping rule in the local microservice, so as to directly determine the access path to call the target remote microservice by skipping the registration center.
[0049] Among them, the method of determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice can be flexibly set according to needs. In one example, the mapping rule corresponding to the target remote microservice can be determined from the domain name mapping rule, and then a domain name is generated for the target remote microservice based on this mapping rule, and the generated domain name is used as the service domain name.
[0050] For example, after determining the mapping rule corresponding to the target remote microservice from the domain name mapping rule, if the determined mapping rule is "http: / / application name of microservice.microservice.cn:8001", then the domain name generated for the target remote microservice based on this mapping rule is "http: / / application name of target remote microservice.microservice.cn:8001", that is to say, the service domain name for accessing the target remote microservice is "http: / / application name of target remote microservice.microservice.cn:8001".
[0051] In another example, considering the diversity and dynamics of service requests, different service requests vary in terms of business importance, urgency, and resource requirements. To ensure that each service request can be processed efficiently, promptly, and stably, the service priority of the current service request can be determined first, and then the mapping rule corresponding to the target remote microservice under the service priority can be determined from the domain name mapping rules. Then, a service domain name can be generated for the target remote microservice based on this mapping rule, so that the local microservice can generate a service domain name for accessing the target remote microservice according to the importance of the current service request. The target remote microservice can then allocate corresponding service resources to the local microservice based on the service domain name to process the current service request, thereby improving the service effect of the local microservice for different service requests.
[0052] In step S230, the target remote microservice is called through the service domain name and the current service request.
[0053] In an embodiment of the present application, after determining the service domain name corresponding to the target remote microservice, the target remote microservice can be called through the service domain name and the current service request, so that the local microservice does not have to adopt the registry discovery mechanism and can directly access the target remote microservice through the service domain name, driving the target remote microservice to assist the local microservice in processing the business indicated by the current service request according to the current service request, thereby avoiding the situation where the remote microservice cannot be called due to network disconnection between the local microservice and the registry.
[0054] See Figure 3 , Figure 3 is a flowchart of a microservice call method shown according to another exemplary embodiment. As Figure 3 shown, before step S220 in the embodiment shown in Figure 2 , the method may further include steps S310 to S330, which are introduced in detail as follows:
[0055] Step S310, determine whether there is a first configuration item in the preset environment variables of the local microservice, where the first configuration item is used to instruct the communication client in the local microservice to replace the default routing rule with the target routing rule;
[0056] Step S320, if the judgment is negative, control the communication client to request the registration domain name of the target remote microservice from the registry according to the default routing rule, and use the registration domain name as the service domain name;
[0057] Step S330, if the judgment is positive, control the communication client to determine the service domain name according to the domain name mapping rule in the target routing rule.
[0058] Among them, the preset environment variables are used to configure the running parameters of the local microservice, including but not limited to database connection configuration, API interface configuration, security settings, logging configuration, and function switches, etc.
[0059] In the above process, before determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice, it can be first determined whether there is a configuration item in the preset environment variables of the local microservice for instructing the communication client in the local microservice to replace the default routing rule with the target routing rule, that is, the first configuration item, so as to achieve the purpose of controlling the local microservice not to adopt the service registry discovery mechanism according to the needs of developers, and to improve the flexibility of the local microservice when calling the remote microservice.
[0060] Specifically, if the judgment result is no, that is, there is no first configuration item in the preset environment variables of the local microservice, it means that the developer currently has no need to make the local microservice not adopt the service registry discovery mechanism. Then, the communication client of the local microservice can be controlled to request the registration domain name of the target remote microservice from the service registry according to the default routing rule, and use the registration domain name as the service domain name. Thus, after subsequently calling the target remote microservice through the service domain name and the current service request, the needs of the developer to test the process of the local microservice calling the remote microservice through the service registry can be met.
[0061] If the judgment result is yes, that is, there is a first configuration item in the preset environment variables of the local microservice, it means that the developer currently needs to make the local microservice not adopt the service registry discovery mechanism. Then, the communication client can be controlled to determine the service domain name according to the domain name mapping rule in the target routing rule. Thus, after subsequently calling the target remote microservice through the service domain name and the current service request, the purpose of enabling the local microservice to call the remote microservice without adopting the service registry discovery mechanism can be achieved.
[0062] For example, when the first configuration item is "feign.local.enable=true". In the process of determining whether there is a first configuration item in the preset environment variables of the local microservice, it can be checked whether there is a configuration item with "feign.local.enable=true" in the preset environment variables. If this configuration item is detected, it is determined that there is a first configuration item in the preset environment variables. Correspondingly, if the developer currently has no need to make the local microservice not adopt the service registry discovery mechanism, this configuration item can be configured as "feign.local.enable=false". On the one hand, it can avoid determining that there is a first configuration item in the preset environment variables of the local microservice. On the other hand, it can improve the convenience of the developer when configuring the local microservice not to adopt the service registry discovery mechanism, that is, changing the "false" in this configuration item to "true".
[0063] Secondly, in some embodiments of the present application, before determining whether the first configuration item exists in the preset environment variables of the local microservice, the current permission level of the local microservice can be determined first, and then the target routing rule can be generated based on the domain name mapping rule corresponding to the permission level, so as to adjust the domain name mapping rule in the target routing rule according to the importance of the local microservice, so that the remote microservice can understand the importance of the local microservice based on the service domain name determined by the local microservice according to the domain name mapping rule in the target routing rule, thereby facilitating the remote microservice to allocate corresponding service resources to the local microservice to process the current service request of the local microservice, and further improving the overall service effect of the microservice architecture.
[0064] See Figure 4 , Figure 4 is a microservice call method shown according to another exemplary embodiment. As Figure 4 shown, before step S220 in the embodiment shown in Figure 2 , the method may further include steps S410 to S430, which are introduced in detail as follows:
[0065] Step S410, determine whether the second configuration item exists in the preset environment variables of the local microservice, where the second configuration item is used to indicate the specified domain name corresponding to the target remote microservice;
[0066] Step S420, if it is determined to be yes, use the specified domain name as the service domain name;
[0067] Step S430, if it is determined to be no, determine the service domain name according to the domain name mapping rule.
[0068] In the microservice architecture, in order to improve the overall service effect, multiple service instances are configured for each microservice in the microservice architecture. However, when developers test the microservice architecture, it will involve the situation of calling and testing specific service instances. Based on this, in order to facilitate developers to test the microservice architecture, in the above process, it can be determined first whether the second configuration item for indicating the specified domain name corresponding to the target remote microservice exists in the preset environment variables of the local microservice. If it is determined to be yes, it means that the developer requires the local microservice to call a specific service instance in the target remote microservice when calling the target remote microservice, and the specified domain name can be used as the service domain name, so as to facilitate subsequent calling of the specific service instance in the target remote microservice through the service domain name and the current service request, and enable the specific service instance to process the business indicated by the current service request. On the contrary, if it is determined to be no, it means that the developer does not require the local microservice to call a specific service instance in the target remote microservice, and the service domain name of the target remote microservice is continued to be determined according to the domain name mapping rule.
[0069] For example, when the second configuration item is "feign.url.remote microservice name: specified domain name", after the local microservice determines the target remote microservice, it can check whether the configuration item "feign.url.target remote microservice name: specified domain name" exists in the preset environment variables. If this configuration item is detected, it is determined that the second configuration item exists in the preset environment variables. This indicates that the developer requires the local microservice to call the service instance corresponding to the specified domain name in the target remote microservice to process the business indicated by the current service request. Then, the specified domain name can be used as the service domain name, so that after the target remote microservice is called through the service domain name and the current service request subsequently, the developer's requirements can be met.
[0070] See Figure 5 , Figure 5 is the flowchart of step S230 in the exemplary embodiment shown in Figure 2 As shown in Figure 5 shown, the process of calling the target remote microservice through the service domain name and the current service request may include steps S510 to S530, which are introduced in detail as follows:
[0071] In step S510, obtain the load conditions and service addresses of different service instances in the target remote microservice based on the service domain name.
[0072] In the implementation manner of the present application, after determining the service domain name corresponding to the target remote microservice, the load conditions and service addresses of different service instances in the target remote microservice can be obtained first, so as to determine the running conditions and access paths of each service instance in the target remote microservice. Among them, the load condition represents the workload currently borne by the service instance, and the service address represents the address for accessing the service instance.
[0073] Among them, in the manner of obtaining the load conditions and service addresses of different service instances in the target remote microservice based on the service domain name, the local microservice can first generate an access request, which is used to obtain the load conditions and service addresses of each service instance, and then send the access request to the target remote microservice based on the service domain name, so that after the target remote microservice receives the access request, it feeds back the load conditions and service addresses of different service instances in the target remote microservice to the local microservice, thereby achieving the purpose of obtaining the load conditions and service addresses of different service instances in the target remote microservice.
[0074] In step S520, determine the target service instance according to the load conditions of different service instances.
[0075] In the implementation manner of the present application, after obtaining the load conditions and service addresses of different service instances in the target remote microservice, the target service instance can be determined according to the load conditions of different service instances.
[0076] Among them, the method for determining the target service instance according to the load conditions of different service instances can be flexibly set as needed. In one instance, the minimum workload can be determined from the load conditions of each service instance, and then the service instance corresponding to the minimum workload is used as the target service instance. On the one hand, the load conditions of each service instance in the remote microservice can be balanced. On the other hand, the service effect achieved by the local microservice when calling the remote microservice can be improved.
[0077] In another instance, service instances with workloads within a preset range can be first determined from the load conditions of each service instance, then the response time corresponding to each service instance within the preset range is determined, and then the minimum response time is selected according to the response time corresponding to each service instance within the preset range. After that, the service instance corresponding to the minimum response time is used as the target service instance, so as to further improve the service effect achieved by the local microservice when calling the remote microservice by combining the load conditions and response time of the service instances.
[0078] In step S530, the current service request is sent to the target service instance based on the service address of the target service instance.
[0079] In the implementation manner of this application, after the target service instance is determined, the current service request can be sent to the target service instance based on the service address of the target service instance, so that the target service instance processes the service indicated by the current service request, and the purpose of calling the target remote microservice to assist the local microservice in processing the service indicated by the current service request is realized.
[0080] The technical solution of the embodiment of this application also proposes Figures 2 - 5 a microservice call method on this basis. This method includes step S610, which is introduced in detail as follows:
[0081] Step S610, start timing after calling the target remote microservice through the service domain name and the current service request. If the timing duration reaches the target preset duration and the call to the target remote microservice fails, request the registration domain name of the target remote microservice from the registration center, and update the service domain name based on the registration domain name, so as to call the target remote microservice through the updated service domain name and the current call request.
[0082] It should be noted that the service domain name mapped by the remote microservice is not fixed, but will be adaptively adjusted with the changes of various factors (such as changes in remote microservice providers, remote microservice upgrades, adjustments, etc.). Based on this, in the embodiments of the present application, timing can be started after the target remote microservice is called through the service domain name and the current service request. If the timing duration reaches the target preset duration and the call to the target remote microservice fails, it indicates that the service domain name of the remote microservice may have changed. Considering that the remote microservice usually updates its registration information in the registration center when the service domain name changes, in order to ensure that the local microservice can call the remote microservice, the registration domain name of the target remote microservice can be requested from the registration center and the service domain name can be updated based on the registration domain name, so as to call the target remote microservice through the updated service domain name and the current call request, thereby driving the local microservice to re-call the target remote microservice, and further reducing the risk of failure when the local microservice calls the target remote microservice.
[0083] In some embodiments of the present application, the determination method of the target preset duration can be flexibly set according to needs. In one example, the current permission level of the local microservice can be determined, and then the preset duration corresponding to the permission level can be used as the target preset duration, so as to determine the target preset duration through the importance of the local microservice and improve the efficiency of the local microservice when calling the remote microservice.
[0084] In another example, the service priority of the current service request can be determined, and then the preset duration corresponding to the service priority can be used as the target preset duration, so as to determine the target preset duration through the importance of the current service request and improve the efficiency of the local microservice when calling the remote microservice to process the service indicated by the current service request.
[0085] In another example, the current permission level of the local microservice can be determined, then the service priority of the current service request can be determined, and then the target preset duration can be determined according to the weight values and preset durations corresponding to the permission level and the service priority respectively, so as to determine the target preset duration by combining the current permission level of the local microservice and the service priority of the current service request, and further improve the efficiency of the local microservice when calling the remote microservice to process the service indicated by the current service request.
[0086] The device embodiments of the present application are introduced below, which can be used to execute the microservice configuration method in the above embodiments of the present application. For the details not disclosed in the device embodiments of the present application, please refer to the embodiments of the microservice configuration method above.
[0087] Figure 6 The block diagram of a microservice configuration device 100 according to an embodiment of the present application is shown.
[0088] Refer toFigure 6 As shown, according to an embodiment of the present application, a microservice configuration device 100 is provided. This device is applied to a microservice architecture, which includes local microservices and remote microservices. The device includes: a registration module 110, configured to send a registration request to a registration center based on microservice information; a configuration module 120, configured to, if receiving a registration result indicating successful registration, configure a corresponding service domain name according to a mapping rule, so that when a local microservice with a mapping rule calls a remote microservice, it can determine the service domain name according to the mapping rule and call the remote microservice through the service domain name.
[0089] It should be noted that the microservice configuration device 100 provided in the above embodiment and the microservice configuration method provided in the above embodiment belong to the same concept. The specific ways in which each module and unit perform operations have been described in detail in the method embodiment, and will not be elaborated here.
[0090] The following introduces another device embodiment of the present application, which can be used to execute the microservice call method in the above embodiment of the present application. For details not disclosed in the device embodiment of the present application, please refer to the embodiment of the microservice call method in the above of the present application.
[0091] Figure 7 Shows a block diagram of a microservice call device 200 according to an embodiment of the present application.
[0092] Refer to Figure 7 As shown, according to an embodiment of the present application, a microservice call device 200 is provided. This device is applied to a microservice architecture, which includes local microservices and remote microservices. The device includes: a service module 210, configured to determine a target remote microservice to be called based on a current service request; a mapping module 220, configured to determine a service domain name corresponding to the target remote microservice according to a domain name mapping rule in the local microservice; wherein, the service domain name is the domain name for accessing the target remote microservice; the domain name mapping rule includes the mapping rule when the target remote microservice configures the service domain name; a call module 230, configured to call the target remote microservice through the service domain name and the current service request.
[0093] In some embodiments of the present application, based on the foregoing solution, the mapping module 220 is further configured to: before determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice, determine whether there is a first configuration item in the preset environment variable of the local microservice, where the first configuration item is used to instruct the communication client in the local microservice to replace the default routing rule with the target routing rule; if the determination result is negative, control the communication client to request the registration domain name of the target remote microservice from the registration center according to the default routing rule, and use the registration domain name as the service domain name; if the determination result is positive, control the communication client to determine the service domain name according to the domain name mapping rule in the target routing rule.
[0094] In some embodiments of the present application, based on the foregoing solution, the mapping module 220 is further configured to: before determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice, determine whether there is a second configuration item in the preset environment variable of the local microservice, where the second configuration item is used to indicate the specified domain name corresponding to the target remote microservice; if the determination result is positive, use the specified domain name as the service domain name; if the determination result is negative, determine the service domain name according to the domain name mapping rule.
[0095] In some embodiments of the present application, based on the foregoing solution, the mapping module 220 is further configured to: determine the service priority of the current service request; determine the mapping rule corresponding to the target remote microservice under the service priority from the domain name mapping rule; and generate a service domain name for the target remote microservice based on the mapping rule.
[0096] In some embodiments of the present application, based on the foregoing solution, the invocation module 230 is further configured to: obtain the load conditions and service addresses of different service instances in the target remote microservice based on the service domain name; determine the target service instance according to the load conditions of different service instances; and send the current service request to the target service instance based on the service address of the target service instance, so that the target service instance processes the service indicated by the current service request.
[0097] In some embodiments of the present application, based on the foregoing solution, the microservice invocation device 200 further includes an identification module, configured to: start timing after invoking the target remote microservice through the service domain name and the current service request; if the timing duration reaches the target preset duration and the invocation of the target remote microservice fails, request the registration domain name of the target remote microservice from the registration center, and update the service domain name based on the registration domain name, so as to invoke the target remote microservice through the updated service domain name and the current invocation request.
[0098] In some embodiments of the present application, based on the foregoing solution, the identification module is further configured to: determine the service priority of the current service request; and use the preset duration corresponding to the service priority as the target preset duration.
[0099] It should be noted that the microservice call device 200 provided in the above embodiment and the microservice call method provided in the above embodiment belong to the same concept. The specific manners in which each module and unit perform operations have been described in detail in the method embodiment, and will not be elaborated here.
[0100] An embodiment of the present application further provides an electronic device, including a processor and a memory. Among them, computer-readable instructions are stored on the memory, and when the computer-readable instructions are executed by the processor, the method described above is implemented.
[0101] Figure 8 The structural schematic diagram of a computer system of an electronic device suitable for implementing the embodiments of the present application is shown.
[0102] It should be noted that Figure 8 The computer system 300 of the electronic device shown is only an example, and should not bring any limitation to the functions and usage scope of the embodiments of the present application.
[0103] As Figure 8 shown, the computer system 300 includes a central processing unit (CPU) 301, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 302 or the program loaded from the storage part 308 into the random access memory (RAM) 303, such as executing the method described in the above embodiment. In the RAM 303, various programs and data required for system operation are also stored. The CPU 301, ROM 302, and RAM 303 are connected to each other through a bus 304. The input / output (I / O) interface 305 is also connected to the bus 304.
[0104] The following components are connected to the I / O interface 305: an input section 306 including a keyboard, a mouse, etc.; an output section 307 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 308 including a hard disk, etc.; and a communication section 309 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 309 performs communication processing via a network such as the Internet. A drive 310 is also connected to the I / O interface 305 as needed. A removable medium 311 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc. is mounted on the drive 310 as needed so that a computer program read therefrom is installed into the storage section 308 as needed.
[0105] Specifically, according to an embodiment of the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for performing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 309, and / or installed from the removable medium 311. When the computer program is executed by a central processing unit (CPU) 301, various functions defined in the system of the present application are executed.
[0106] It should be noted that the computer-readable medium shown in the embodiments of the present application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, apparatus, or device. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable computer program. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and this computer-readable medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0107] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. Among them, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the above module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and the combination of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0108] The units involved in the embodiments of the present application can be implemented in software or in hardware, and the described units can also be provided in a processor. Among them, the names of these units do not, in some cases, constitute a limitation on the unit itself.
[0109] As another aspect, the present application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or may exist alone without being assembled into the electronic device. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiments.
[0110] It should be noted that although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of the two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0111] From the description of the above embodiments, those skilled in the art can easily understand that the example embodiments described herein can be implemented by software or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (such as a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.
[0112] After considering the specification and practicing the disclosed embodiments herein, those skilled in the art will readily conceive of other embodiments of the present application. The present application is intended to cover any variations, uses, or adaptations of the present application, which follow the general principles of the present application and include well-known knowledge or conventional technical means in the technical field not disclosed in the present application.
[0113] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present application is only limited by the appended claims.
Claims
1. A microservice call method, characterized in that The method is applied to a microservices architecture, which includes a local microservice and a remote microservice. The method is executed by the local microservice and includes: Determine a target remote microservice to be called based on the current service request; Determine the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice; wherein, the service domain name is the domain name for accessing the target remote microservice; the domain name mapping rule includes the mapping rule when the target remote microservice configures the service domain name; Call the target remote microservice through the service domain name and the current service request.
2. The method according to claim 1, wherein Before determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice, the method further includes: Judge whether there is a first configuration item in the preset environment variable of the local microservice, wherein the first configuration item is used to indicate that the communication client in the local microservice replaces the default routing rule with a target routing rule; If the judgment result is no, control the communication client to request the registration domain name of the target remote microservice from the registration center according to the default routing rule, and use the registration domain name as the service domain name; If the judgment result is yes, control the communication client to determine the service domain name according to the domain name mapping rule in the target routing rule.
3. The method according to claim 1, wherein Before determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice, the method further includes: Judge whether there is a second configuration item in the preset environment variable of the local microservice, wherein the second configuration item is used to indicate the specified domain name corresponding to the target remote microservice; If the judgment result is yes, use the specified domain name as the service domain name; If the judgment result is no, determine the service domain name according to the domain name mapping rule.
4. The method according to claim 1, wherein Determining the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice includes: Determine the service priority of the current service request; Determine the mapping rule corresponding to the target remote microservice under the service priority from the domain name mapping rule; Generate the service domain name for the target remote microservice based on the mapping rule.
5. The method according to claim 1, characterized in that, Calling the target remote microservice through the service domain name and the current service request includes: Obtain the load conditions and service addresses of different service instances in the target remote microservice based on the service domain name; Determine a target service instance according to the load conditions of the different service instances; Send the current service request to the target service instance based on the service address of the target service instance, so that the target service instance processes the service indicated by the current service request.
6. The method according to any one of claims 1-5, characterized in that, The method further includes: Start timing after invoking the target remote microservice through the service domain name and the current service request. If the timing duration reaches the target preset duration and the invocation of the target remote microservice fails, request the registration domain name of the target remote microservice from the registration center, and update the service domain name based on the registration domain name, so as to invoke the target remote microservice through the updated service domain name and the current invocation request.
7. The method according to claim 6, characterized in that, The method further includes: Determine the service priority of the current service request; Use the preset duration corresponding to the service priority as the target preset duration.
8. A microservice configuration method, characterized in that The method is applied to a microservice architecture, which includes a local microservice and a remote microservice. The method is executed by the remote microservice, and the method includes: Send a registration request to the registration center based on microservice information; If a registration result indicating successful registration is received, configure the corresponding service domain name according to the mapping rule, so that when the local microservice with the mapping rule invokes the remote microservice, it can determine the service domain name according to the mapping rule and invoke the remote microservice through the service domain name.
9. A microservice call device, characterized in that, The device is applied to a microservice architecture, which includes a local microservice and a remote microservice. The device includes: A service module configured to determine the target remote microservice to be invoked based on the current service request; A mapping module configured to determine the service domain name corresponding to the target remote microservice according to the domain name mapping rule in the local microservice; wherein, the service domain name is the domain name for accessing the target remote microservice; the domain name mapping rule includes the mapping rule when the target remote microservice configures the service domain name; An invocation module configured to invoke the target remote microservice through the service domain name and the current service request.
10. A microservice configuration device, characterized in that, The device is applied to a microservice architecture, which includes a local microservice and a remote microservice. The device includes: A registration module configured to send a registration request to the registration center based on microservice information; A configuration module configured to, if a registration result indicating successful registration is received, configure the corresponding service domain name according to the mapping rule, so that when the local microservice with the mapping rule invokes the remote microservice, it can determine the service domain name according to the mapping rule and invoke the remote microservice through the service domain name.
Citation Information
Cited By
Service request processing method and device, equipment, storage medium and program product
CN121664890A