Micro-service calling method and device, equipment and medium
By receiving microservice call requests in a distributed system and obtaining a collection of client instances, the call of client instances is directly implemented based on the target communication framework, and the problems of delay and low efficiency of microservice call in the prior art are solved, and more efficient microservice calls are achieved.
Patent Information
- Application Number
- CN202311808228.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-26
- Publication Date
- 2025-06-27
AI Technical Summary
In distributed systems, microservice call delays are high and efficiency are low in the prior art.
A microservice calling method is proposed. By receiving microservice call requests, a collection of client instances corresponding to the target microservices, and a collection of client instances is realized based on the target communication framework, and a client is directly selected from the client instance collection to call the microservice interface, avoiding relying on hypertext transmission protocols and other remote calling mechanisms.
Through this method, the delay in microservice calling can be reduced and the call efficiency can be improved.
Smart Images

Figure CN120216216A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of distributed technologies, and in particular, to a microservice call method, apparatus, device, and medium. Background Art
[0002] In a distributed system, a remote call mechanism is widely used to achieve remote communication and remote calls between different computers.
[0003] In related technologies, the remote call mechanism is usually implemented using the Hypertext Transfer Protocol (HTTP), Transmission Control Protocol (TCP), User Datagram Protocol (UDP), etc.
[0004] In this way, the call latency is relatively large and the efficiency is relatively low. Summary of the Invention
[0005] The present disclosure aims to solve at least one of the technical problems in the related technologies to some extent.
[0006] To this end, the present disclosure provides a microservice call method, apparatus, electronic device, non-transitory computer-readable storage medium storing computer instructions, and computer program product, which can reduce call latency and improve call efficiency.
[0007] To achieve the above object, the microservice call method proposed in the first aspect embodiment of the present disclosure is executed by a first microservice, and the first microservice is implemented based on a first computer programming language; the method includes: receiving a microservice call request, where the microservice call request is used to trigger a call to a second microservice, the second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different; obtaining a set of client instances corresponding to the second microservice, where the set of client instances includes clients of each instance among a plurality of instances corresponding to the interface of the second microservice, and the clients are implemented based on a target communication framework; and calling the interface of the second microservice based on a first client among the plurality of clients.
[0008] To achieve the above object, the microservice call device provided in the second aspect of the present disclosure includes: a receiving module, configured to receive a microservice call request, where the microservice call request is used to trigger a first microservice to call a second microservice, the first microservice is implemented based on a first computer programming language, the second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different; an obtaining module, configured to obtain a set of client instances corresponding to the second microservice, where the set of client instances includes clients of each instance among a plurality of instances corresponding to the interface of the second microservice, and the clients are implemented based on a target communication framework; a calling module, configured to call the interface of the second microservice based on a first client among the plurality of clients.
[0009] The electronic device provided in the third aspect of the present disclosure includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the processor executes the program, it implements the microservice call method provided in the first aspect of the present disclosure.
[0010] The present disclosure provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the microservice call method provided in the first aspect of the present disclosure.
[0011] The present disclosure provides a computer program product, and when the instructions in the computer program product are executed by a processor, they execute the microservice call method provided in the first aspect of the present disclosure.
[0012] The microservice call method, device, electronic device, non-transitory computer-readable storage medium storing computer instructions, and computer program product provided by the present disclosure receive a microservice call request, where the microservice call request is used to trigger a call to a second microservice, the second microservice is implemented based on a second computer programming language, the first computer programming language and the second computer programming language are different, and obtain a set of client instances corresponding to the second microservice, where the set of client instances includes clients of each instance among a plurality of instances corresponding to the interface of the second microservice, the clients are implemented based on a target communication framework, and call the interface of the second microservice based on a first client among the plurality of clients. Since during the process of the first microservice calling the second microservice, a client is directly selected from the set of client instances corresponding to the second microservice, and the interface of the second microservice is called based on the function of the selected client. It does not need to rely on the Hypertext Transfer Protocol HTTP or the like to implement a remote call mechanism, thereby being able to reduce call latency and improve call efficiency.
[0013] Additional aspects and advantages of the present disclosure will be given in part in the following description, become apparent in part from the following description, or be learned by practice of the present disclosure. Description of the Drawings
[0014] The above-mentioned and / or additional aspects and advantages of the present disclosure will become apparent and be readily understood from the following description of embodiments in conjunction with the drawings, where:
[0015] Figure 1 is a schematic flowchart of a microservice call method proposed in an embodiment of the present disclosure;
[0016] Figure 2 is a schematic flowchart of a microservice call method proposed in another embodiment of the present disclosure;
[0017] Figure 3 is a schematic flowchart of a microservice call method proposed in another embodiment of the present disclosure;
[0018] Figure 4 is a schematic diagram of the architecture of a distributed system in an embodiment of the present disclosure;
[0019] Figure 5 is a schematic diagram of data flow transfer in microservice call in an embodiment of the present disclosure;
[0020] Figure 6 is a schematic diagram of the structure of a microservice call device proposed in an embodiment of the present disclosure;
[0021] Figure 7 shows a block diagram of an exemplary electronic device suitable for implementing the embodiments of the present disclosure. Detailed Embodiments
[0022] Embodiments of the present disclosure will be described in detail below. Examples of the embodiments are shown in the drawings, where the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the drawings are exemplary only for explaining the present disclosure and should not be construed as limiting the present disclosure. On the contrary, the embodiments of the present disclosure include all variations, modifications, and equivalents falling within the spirit and scope of the appended claims.
[0023] Figure 1 is a schematic flowchart of a microservice call method proposed in an embodiment of the present disclosure.
[0024] In this embodiment, the microservice call method is configured in a microservice call device as an example. In this embodiment, the microservice call method can be configured in the microservice call device, and the microservice call device can be set in a server or can also be set in an electronic device, which is not limited herein.
[0025] This embodiment takes the microservice call method being configured in an electronic device as an example. Among them, the electronic device can be a hardware device with various operating systems such as a smart phone, a tablet computer, a personal digital assistant, an e-book, etc.
[0026] It should be noted that the execution subject of the embodiments of the present disclosure can be, for example, a server or a central processing unit (CPU) in an electronic device in terms of hardware, and can be, for example, a relevant background service in a server or an electronic device in terms of software, and this is not limited.
[0027] The microservice call method provided in this embodiment can be executed by a first microservice. The first microservice is implemented based on a first computer programming language. The first microservice can be deployed on an electronic device (such as a computer). This electronic device can be deployed in a distributed system, and the distributed system can also include other electronic devices, and this is not limited.
[0028] Among them, a microservice for calling other microservices can be called the first microservice, and the called microservice can be called the second microservice. A microservice is a software architecture pattern that splits an application into a set of small, independently deployable services, and each service is built around a specific business function. These microservices can be independently deployed, scaled, and maintained, and they cooperate with each other through lightweight communication mechanisms to form a complete application system.
[0029] As Figure 1 shown, the microservice call method includes:
[0030] S101: Receive a microservice call request, where the microservice call request is used to trigger the call of the second microservice. The second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different.
[0031] Among them, the microservice call request refers to a request used to trigger the first microservice to call the second microservice. By way of example, the microservice call request can be triggered by a business or also by a developer.
[0032] In some embodiments, the first microservice may be implemented based on a first computer programming language. The first computer programming language, for example, is the Java programming language, which is a portable, simple, secure, and object-oriented language. The second microservice may be implemented in a second computer programming language, and the first computer programming language and the second computer programming language are different. The second programming language may be, for example, the C++ programming language. That is to say, the first microservice and the second microservice may be heterogeneous microservices, and both are implemented based on different technology stacks. The first microservice may be implemented based on the Java technology stack, for example, and the second microservice may be implemented based on the C++ technology stack, for example.
[0033] In some embodiments, the microservice call request may include the identifier of the second microservice. After the first microservice determines that it has received the microservice call request, it may determine the second microservice to be called with reference to the identifier of the second microservice carried in the microservice call request.
[0034] S102: Obtain a set of client instances corresponding to the second microservice, where the set of client instances includes the clients of each instance among multiple instances corresponding to the interface of the second microservice, and the clients are implemented based on a target communication framework.
[0035] After receiving the microservice call request as described above, a set of client instances corresponding to the second microservice may be obtained. The set of client instances includes multiple clients, and each client is used to implement the call of the microservice.
[0036] In some embodiments, a client refers to software or a device that communicates with a server over a network. The client is responsible for sending requests to the server and processing the responses returned from the server. The client in the embodiments of the present disclosure has the function of calling the interface of the second microservice. The client may be implemented based on a target communication framework, for example. The target communication framework may be, for example, a communication framework suitable for calling the interface of the second microservice. That is to say, a client developed based on the target communication framework can support quickly, conveniently, and efficiently calling the interface of the second microservice. The target communication framework may be, for example, the Starlight framework. The Starlight framework is a microservice communication framework for cloud native, compatible with the Spring ecosystem (the Spring ecosystem refers to a series of related technologies and tools based on the Spring framework system, which can help developers develop enterprise-level applications faster and more simply. Various technologies and tools in the Spring ecosystem are closely connected to form a complete ecosystem). Based on this, an efficient, stable, controllable, and observable microservice application can be quickly built, and comfortable experiences such as improved R & D efficiency and enhanced business stability can be obtained.
[0037] In some embodiments, the interface of the second microservice refers to an interface that defines the behavioral specifications such as methods, properties, and events that classes or objects in the second microservice can provide. The interface of the second microservice is used to describe the methods by which a class or object in the second microservice interacts with the external world. An interface is usually regarded as a kind of contract or agreement, which stipulates the methods and properties that a class or object can implement to support other code to interact with them correctly.
[0038] Among them, multiple instances corresponding to the interface of the second microservice can be, for example, the specific implementation contents that implement one or more methods provided by the interface of the second microservice. Different instances are used to correspondingly implement different functions that the interface can provide, and different functions can all be functions provided by the second microservice.
[0039] In the embodiments of the present disclosure, clients of each instance corresponding to the interface of the second microservice can be pre-implemented based on a target communication framework, and the clients are given the ability to call the interface of the second microservice, and then a set of client instances corresponding to the second microservice is formed. During the process of the first microservice calling the second microservice, a client is directly selected from the set of client instances corresponding to the second microservice, and the interface of the second microservice is called based on the function of the selected client.
[0040] S103: Call the interface of the second microservice based on the first client among multiple clients.
[0041] Among them, a client selected from the set of client instances can be called the first client. By way of example, the first microservice can determine the method to be called this time, determine the instance used to implement this method from multiple instances of the interface of the second microservice, and use the client corresponding to this instance as the first client. Or, the first client can also be randomly selected from multiple first clients. Or the selection of the first client can also be implemented based on any other possible method, and this is not limited.
[0042] In the embodiments of the present disclosure, the first client can be determined from multiple clients based on load balancing. A free or a client with a lower load can be selected as the first client based on load balancing technology to effectively improve the microservice call performance during the process of calling the second microservice. By way of example, the call load situation of each client can be calculated based on a load balancing algorithm, and a suitable first client can be selected according to the calculation result.
[0043] In this embodiment, by receiving a microservice call request, where the microservice call request is used to trigger the call of a second microservice, the second microservice is implemented based on a second computer programming language, the first computer programming language and the second computer programming language are different, and a set of client instances corresponding to the second microservice is obtained, where the set of client instances includes clients of each instance corresponding to the interface of the second microservice, where the client is implemented based on a target communication framework, and based on a first client among the multiple clients, the interface of the second microservice is called. Since in the process of the first microservice calling the second microservice, a client is directly selected from the set of client instances corresponding to the second microservice, and based on the function of the selected client, the interface of the second microservice is called. And there is no need to rely on the Hypertext Transfer Protocol HTTP or the like to implement the remote call mechanism, so that the call latency can be reduced and the call efficiency can be improved.
[0044] Figure 2 It is a schematic flowchart of a microservice call method proposed in another embodiment of the present disclosure.
[0045] The microservice call method provided in this embodiment can be executed by a first microservice. The first microservice is implemented based on a first computer programming language. The first microservice can be deployed on an electronic device (such as a computer), and the electronic device can be deployed in a distributed system. The distributed system can also include other electronic devices, which is not limited herein.
[0046] As Figure 2 shown, the microservice call method includes:
[0047] S201: Obtain the access address of each instance corresponding to the interface of the second microservice, where the second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different.
[0048] Among them, each instance corresponds to an access address, and the access address is used to support the access to the corresponding instance. The access address can be, for example, an Internet Protocol (IP) address. Exemplarily, each instance can be registered in a registration center, and a corresponding IP address can be configured for each instance in the registration center to support the access to the instances registered in the registration center.
[0049] S202: Establish a client corresponding to the corresponding instance according to the access address.
[0050] In this embodiment, it is supported to pre-build the clients of each instance, and a set of client instances corresponding to the second microservice is formed by multiple clients. After determining the access address of each instance, the client corresponding to each instance can be implemented based on the target communication framework.
[0051] S203: Form a set of client instances based on multiple clients.
[0052] After establishing multiple clients as described above, a set of client instances can be formed based on the multiple clients. The corresponding relationship between the second microservice and the set of client instances can also be configured to support quickly and accurately retrieving the set of client instances corresponding to the second microservice based on this corresponding relationship.
[0053] S204: Receive a microservice call request, where the microservice call request is used to trigger the call to the second microservice.
[0054] S205: Obtain the set of client instances corresponding to the second microservice, where the set of client instances includes the client of each instance corresponding to the interface of the second microservice, and the client is implemented based on the target communication framework.
[0055] S206: Based on the first client among the multiple clients, call the interface of the second microservice.
[0056] In this embodiment, by receiving a microservice call request, where the microservice call request is used to trigger the call to the second microservice, the second microservice is implemented based on the second computer programming language, and the first computer programming language and the second computer programming language are different, and obtaining the set of client instances corresponding to the second microservice, where the set of client instances includes the client of each instance corresponding to the interface of the second microservice, where the client is implemented based on the target communication framework, and based on the first client among the multiple clients, calling the interface of the second microservice. Since in the process of the first microservice calling the second microservice, a client is directly selected from the set of client instances corresponding to the second microservice, and based on the function of the selected client, the interface of the second microservice is called. Without relying on the Hypertext Transfer Protocol HTTP or the like to implement the remote call mechanism, the call latency can be reduced and the call efficiency can be improved. The clients of each instance corresponding to the interface of the second microservice can be implemented in advance based on the target communication framework, and the clients are given the ability to call the interface of the second microservice, and then the set of client instances corresponding to the second microservice is formed, so as to effectively improve the acquisition efficiency of the set of client instances corresponding to the second microservice, and further improve the overall microservice call efficiency.
[0057] Figure 3 It is a schematic flowchart of a microservice call method proposed in another embodiment of the present disclosure.
[0058] The microservice call method provided in this embodiment can be executed by a first microservice. The first microservice is implemented based on a first computer programming language. The first microservice can be deployed on an electronic device (such as a computer), and this electronic device can be deployed in a distributed system. The distributed system can also include other electronic devices, and there is no limitation in this regard.
[0059] As Figure 3 shown, the microservice call method includes:
[0060] S301: Obtain the access address corresponding to each instance in the instance list corresponding to the interface of the second microservice from the registry as the access address corresponding to each instance corresponding to the interface of the second microservice, where the second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different.
[0061] Among them, the registry can be implemented based on some service frameworks.
[0062] That is to say, the registry can include an instance list corresponding to the interface of the second microservice. The instance list can include multiple instances of the interface and the access address corresponding to each instance. That is, the access addresses of multiple instances corresponding to the interface of the second microservice are managed in the registry in the form of an instance list. Thus, the acquisition efficiency and accuracy of the access address can be effectively improved.
[0063] S302: Establish a client corresponding to the corresponding instance according to the access address.
[0064] S303: Form a client instance set according to multiple clients.
[0065] S304: Subscribe to the interface of the first microservice from the registry, where the registry includes: the interface of the first microservice and / or interface alias, and the second microservice associated with the interface and / or interface alias.
[0066] In the embodiment of the present disclosure, the interface of the first microservice can also be subscribed in advance in the registry, and the interface of the first microservice and / or interface alias, and the second microservice associated with the interface and / or interface alias can also be registered in advance in the registry. Thus, with the assistance of the registry, the first microservice can quickly and accurately identify the second microservice that the present microservice needs to call.
[0067] S305: Receive a microservice call request, where the microservice call request is used to trigger the call of the second microservice.
[0068] S306: Obtain the second microservice associated with the interface and / or interface alias of the first microservice from the registry as the second microservice to be called.
[0069] In some embodiments, after receiving a microservice call request, the first microservice may obtain, from a registry, a second microservice associated with the interface and / or interface alias of the first microservice as the second microservice to be called.
[0070] In some embodiments, a second microservice associated with the interface of the first microservice may be obtained from a registry as the second microservice to be called.
[0071] In some embodiments, a second microservice associated with the interface alias of the first microservice may be obtained from a registry as the second microservice to be called.
[0072] In some embodiments, a second microservice associated with the interface and interface alias of the first microservice may be obtained from a registry as the second microservice to be called.
[0073] Thereby, the accuracy and flexibility of the determination of the second microservice can be effectively improved, and it can be effectively applied to personalized call scenarios.
[0074] S307: Obtain a set of client instances corresponding to the second microservice, where the set of client instances includes the client of each instance among multiple instances corresponding to the interface of the second microservice, and the client is implemented based on a target communication framework.
[0075] S308: Invoke the interface of the second microservice based on the first client among the multiple clients.
[0076] In this embodiment, by receiving a microservice call request, where the microservice call request is used to trigger the call of a second microservice, the second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different, and obtaining a set of client instances corresponding to the second microservice, where the set of client instances includes clients of each instance corresponding to the interface of the second microservice, where the clients are implemented based on a target communication framework, and based on a first client among the multiple clients, calling the interface of the second microservice. Since in the process of the first microservice calling the second microservice, a client is directly selected from the set of client instances corresponding to the second microservice, and based on the function of the selected client, the interface of the second microservice is called. And it does not need to rely on the Hypertext Transfer Protocol HTTP, etc. to implement the remote call mechanism, so that the call latency can be reduced and the call efficiency can be improved. It is also possible to pre-subscribe to the interface of the first microservice in the registration center, and in the registration center, it is also possible to pre-register the interface and / or interface alias of the first microservice, and the second microservice associated with the interface and / or interface alias. Thus, with the assistance of the registration center, the first microservice can quickly and accurately identify the second microservice that the microservice needs to call. The second microservice associated with the interface of the first microservice can be obtained from the registration center as the second microservice to be called. Or, the second microservice associated with the interface alias of the first microservice can be obtained from the registration center as the second microservice to be called. Or, the second microservice associated with the interface and the interface alias of the first microservice can be obtained from the registration center as the second microservice to be called. Thus, the accuracy and flexibility of the determination of the second microservice can be effectively improved, and it is effectively applicable to personalized call scenarios.
[0077] In the embodiments of the present disclosure, the status of each client in the set of client instances can also be managed to ensure that accurate clients are provided and support the correct call of the second microservice. It can be determined that a first instance among the multiple instances corresponding to the interface of the second microservice is in a first state, where the first state indicates that the first instance is offline, and the client corresponding to the first instance is deleted from the set of client instances.
[0078] In the embodiments of the present disclosure, a new client can also be added to the set of client instances. It can be determined that a first instance is added to the interface of the second microservice, and the access address of the first instance is obtained. According to the access address, a client corresponding to the first instance is established, the client corresponding to the first instance is added to the set of client instances, and the first instance is set to a second state, where the second state indicates that the first instance is online.
[0079] In the disclosed embodiment, the client status can also be managed in a linked manner, and the status of the client corresponding to the first instance in the client instance set can be updated according to the status of the first instance among the multiple instances corresponding to the interface of the second microservice. In other words, the status of the client of each instance can be consistent with the status of the instance. If the first instance is offline, the client corresponding to the first instance is also offline. If the first instance is online, the client corresponding to the first instance is also online, thereby improving the global status management effect.
[0080] The description of the above embodiments can be illustrated as follows:
[0081] The first computer programming language is Java programming language, the second programming language is C++ programming language, the target communication framework is Starlight framework, and the registration center is implemented based on some service frameworks. Figure 4 As shown, Figure 4 : is a schematic diagram of the architecture of the distributed system in the embodiment of the present disclosure, which includes a registration center, clusters ClusterA, ClusterB, ClusterC, and ClusterD, wherein each cluster can be used to provide a microservice (an optional example of a first microservice), and also includes ClusterE, ClusterF, ClusterG, ..., ClusterN, where N is a positive integer greater than 1, and ClusterE, ClusterF, ClusterG, ..., ClusterN can provide another microservice (an optional example of a second microservice).
[0082] As mentioned above Figure 4, a Consumer and a Provider can be deployed in ClusterA that implements the first microservice, achieving fast calls between services with low latency, high efficiency, high performance, and high scalability in a heterogeneous technology system. Calls are implemented based on the bRPC protocol in the Java technology stack (bRPC is a high-performance, open-source Remote Procedure Call (RPC) framework. Protobuf (an interface description language and binary data exchange format for serializing structured data) is used as the message serialization and network transmission format, and communication between the server and client is achieved by defining interfaces and message types). The bRPC interface calls reuse the software development kit (SDK) of the Starlight framework and the target communication framework, as well as the registry of the target communication framework, enabling low-cost access to Java and / or C++ distributed microservices. inf-brpc-sdk is an optional example of the microservice call device in this disclosure embodiment. inf-brpc-sdk can call the bRPC protocol interface and can be encapsulated as an SDK. It internally encapsulates functions such as interface subscription, Starlight client, bRPC service instance listening, and bRPC service instance call load balancing. inf-brpc-sdk can call both the protocol interface of the Java technology stack and the bRPC protocol interface.
[0083] In the above Figure 4 , interface subscription is used to obtain the IP address (an optional example of the access address) of the instance of the microservice implemented in the C++ programming language from the registry. By creating a SingleStarlightClient (an optional example of establishing a client), a direct connection between the client and / or the provider is achieved, and the IP address of the created Starlight client (an optional example of the client) is obtained from the registry.
[0084] Among them, there are operations such as online, offline, publish, and delete for the instance of the provider (service provider) that provides services. How to promptly perceive the instance status can be achieved by the ProviderListener interface. The ProviderListener interface can provide three methods: addProvider (add service provider), removeProvider (delete service provider), and updateProvider (update service provider), which respectively monitor the addition, deletion, and update status of the provider container.
[0085] Such asFigure 5 As shown Figure 5 is a schematic diagram of data flow in microservice calls in an embodiment of the present disclosure. The data flow is mainly divided into three parts: initialization, asynchronous listening, and requests. Among them,
[0086] 1. Initialization:
[0087] Configure and connect to the registration center according to the registration center address, subscribe to the corresponding C++ service interface, and obtain the IP addresses of all C++ service instances under the service interface from the registration center according to the C++ service interface and alias; create a Starlight instance for each IP respectively to implement the connection between the current Java service instance and each C++ service instance, and maintain a long connection; all Starlight instances are cached in the computer memory through the inf-brpc-sdk device.
[0088] 2. Asynchronous listening:
[0089] The inf-brpc-sdk implements the monitoring of the status of all instances of the interface of the currently subscribed C++ microservice. The monitored status mainly includes new, changed, and offline status. When a new instance is monitored, a new Starlight client is created according to the IP address of the new instance, and the connections of all current Starlight clients are cached in the total cache set (an optional example of the client instance set). When an instance goes offline is monitored, the corresponding Starlight instance is deleted from the local cache of the computer according to the IP address of the offline instance. When a change status is monitored, the status of the Starlight client instance is modified.
[0090] 3. Requests:
[0091] When requesting a C++ microservice, a proxy factory for the bRPC interface can be obtained. The proxy factory obtains all C++ client instance sets (an optional example of the client instance set) cached by the current Java instance, and obtains a Starlight client with an available status through the load balancer of the inf-brpc-sdk, and then realizes remote procedure calls through the long connection between the Starlight client and the C++ microservice.
[0092] Figure 6 is a schematic structural diagram of a microservice call device proposed in an embodiment of the present disclosure.
[0093] As Figure 6 shown, the microservice call device 60 includes:
[0094] A receiving module 601, configured to receive a microservice call request, where the microservice call request is used to trigger a first microservice to call a second microservice, the first microservice is implemented based on a first computer programming language, the second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different.
[0095] An obtaining module 602, configured to obtain a set of client instances corresponding to the second microservice, where the set of client instances includes clients of each instance among multiple instances corresponding to the interface of the second microservice, and the clients are implemented based on a target communication framework.
[0096] A calling module 603, configured to call the interface of the second microservice based on a first client among the multiple clients.
[0097] It should be noted that the foregoing explanation of the microservice call method also applies to the microservice call device in this embodiment, and will not be elaborated here.
[0098] In this embodiment, by receiving a microservice call request, where the microservice call request is used to trigger a call to a second microservice, the second microservice is implemented based on a second computer programming language, the first computer programming language and the second computer programming language are different, and obtaining a set of client instances corresponding to the second microservice, where the set of client instances includes clients of each instance among multiple instances corresponding to the interface of the second microservice, and the clients are implemented based on a target communication framework, and calling the interface of the second microservice based on a first client among the multiple clients. Since during the process of the first microservice calling the second microservice, a client is directly selected from the set of client instances corresponding to the second microservice, and the interface of the second microservice is called based on the function of the selected client. And there is no need to rely on the Hypertext Transfer Protocol HTTP or the like to implement a remote call mechanism, thereby being able to reduce call latency and improve call efficiency.
[0099] Figure 7 The block diagram of an exemplary electronic device suitable for implementing the embodiments of the present disclosure is shown. Figure 7 The shown electronic device 12 is merely an example and should not impose any limitation on the functions and usage scope of the embodiments of the present disclosure.
[0100] As Figure 7 shown, the electronic device 12 is presented in the form of a general-purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, a memory 28, and a bus 18 connecting different system components (including the memory 28 and the processing unit 16).
[0101] Bus 18 represents one or more of several types of bus architectures, including a memory bus or memory controller, a peripheral bus, an Accelerated Graphics Port, a processor bus, or a local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnection (PCI) bus.
[0102] Electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including both volatile and nonvolatile media, removable and non-removable media.
[0103] Memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache 32. Electronic device 12 may further include other removable / non-removable, volatile / nonvolatile computer system storage media. By way of example only, storage system 34 can be used for reading and writing on non-removable, nonvolatile magnetic media ( Figure 7 not shown, typically called a "hard disk drive").
[0104] Although Figure 7 not shown in the figures, a disk drive for reading and writing on removable nonvolatile disks (such as a "floppy disk") and an optical disk drive for reading and writing on removable nonvolatile optical disks (such as Compact Disc Read Only Memory (CD-ROM), Digital Video Disc Read Only Memory (DVD-ROM), or other optical media) can be provided. In these cases, each drive can be connected to bus 18 by one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of the various embodiments of the present disclosure.
[0105] A program / utilities 40 having a set (at least one) of program modules 42 can be stored, for example, in a memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. The program modules 42 generally execute the functions and / or methods in the embodiments described in the present disclosure.
[0106] The electronic device 12 can also communicate with one or more external devices 14 (such as a keyboard, a pointing device, a display 24, etc.), can also communicate with one or more devices that enable a human body to interact with the electronic device 12, and / or can communicate with any device that enables the electronic device 12 to communicate with one or more other computing devices (such as a network card, a modem, etc.). Such communication can be carried out through an input / output (I / O) interface 22. Moreover, the electronic device 12 can also communicate with one or more networks (such as a Local Area Network (LAN), a Wide Area Network (WAN), and / or a public network, such as the Internet) through a network adapter 20. As shown in the figure, the network adapter 20 communicates with other modules of the electronic device 12 through a bus 18. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in combination with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0107] The processing unit 16 executes various functional applications and data processing by running programs stored in the memory 28, such as implementing the microservice call method mentioned in the foregoing embodiments.
[0108] To implement the above embodiments, the present disclosure also proposes a non-transitory computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it implements the microservice call method proposed in the foregoing embodiments of the present disclosure.
[0109] To implement the above embodiments, the present disclosure also proposes a computer program product. When the instructions in the computer program product are executed by a processor, they execute the microservice call method proposed in the foregoing embodiments of the present disclosure.
[0110] It should be noted that, in the description of the present disclosure, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present disclosure, unless otherwise specified, the meaning of "a plurality" is two or more.
[0111] Any process or method description depicted in a flowchart or otherwise described herein can be understood to represent a module, segment, or portion of code that includes one or more executable instructions for implementing a specific logical function or process. The scope of the preferred embodiments of the present disclosure includes additional implementations where functions may be executed not in the order shown or discussed, including in a substantially simultaneous manner according to the involved functions or in a reverse order, which should be understood by those skilled in the art to which the embodiments of the present disclosure pertain.
[0112] It should be understood that various parts of the present disclosure can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one or a combination of the following techniques well known in the art can be used: discrete logic circuits having logic gate circuits for implementing logical functions on data signals, application specific integrated circuits having appropriate combinational logic gate circuits, programmable gate arrays (PGAs), field programmable gate arrays (FPGAs), etc.
[0113] Those of ordinary skill in the art of this technology can understand that all or part of the steps carried out in implementing the above-described embodiment methods can be completed by instructing relevant hardware through a program. The said program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.
[0114] In addition, in each of the various embodiments of the present disclosure, the functional units can be integrated into one processing module, or each unit can exist physically alone, or two or more units can be integrated into one module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of a software functional module. When the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0115] The above-mentioned storage medium can be a read-only memory, a magnetic disk, an optical disk, or the like.
[0116] In the description of this specification, the description with reference to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples.
[0117] Although the embodiments of the present disclosure have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting the present disclosure. Those of ordinary skill in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present disclosure.
Claims
1. A microservice call method, characterized in that, Executed by a first microservice, which is implemented based on a first computer programming language; wherein, the method includes: Receiving a microservice call request, wherein the microservice call request is used to trigger the call of a second microservice, the second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different; Obtaining a set of client instances corresponding to the second microservice, wherein the set of client instances includes clients of each instance among a plurality of instances corresponding to the interface of the second microservice, and the clients are implemented based on a target communication framework; Based on a first client among the plurality of clients, calling the interface of the second microservice.
2. The method according to claim 1, wherein The set of client instances is constructed based on the following method: Obtaining the access address of each instance among the plurality of instances corresponding to the interface of the second microservice; Establishing a client corresponding to the corresponding instance according to the access address; Forming the set of client instances according to the plurality of clients.
3. The method according to claim 2, wherein The method further includes: Subscribing to the interface of the first microservice from a registration center, wherein the registration center includes: the interface of the first microservice and / or interface alias, and the second microservice associated with the interface and / or interface alias.
4. The method according to claim 3, wherein The method further includes: Obtaining, from the registration center, the second microservice associated with the interface and / or interface alias of the first microservice as the second microservice to be called.
5. The method according to claim 3, characterized in that, The registration center further includes: a list of instances corresponding to the interface of the second microservice, the list of instances includes a plurality of instances, and each instance has a corresponding access address; Wherein, the obtaining the access address of each instance among the plurality of instances corresponding to the interface of the second microservice includes: Obtaining, from the registration center, the access address corresponding to each instance in the list of instances as the access address of each instance corresponding to the interface of the second microservice.
6. The method according to claim 1, wherein The method further includes: Determining that a first instance among the plurality of instances corresponding to the interface of the second microservice is in a first state, wherein the first state indicates that the first instance is offline; Deleting the client corresponding to the first instance from the set of client instances.
7. The method according to claim 1, characterized in that The method further includes: Determining to add a first instance to the interface of the second microservice; Obtaining the access address of the first instance; Establishing a client corresponding to the first instance according to the access address; Adding the client corresponding to the first instance to the set of client instances; Setting the first instance to a second state, wherein the second state indicates that the first instance is online.
8. The method according to claim 1, wherein The method further includes: Updating the state of the client corresponding to the first instance in the set of client instances according to the state of the first instance among the plurality of instances corresponding to the interface of the second microservice.
9. The method according to any one of claims 1-8, characterized in that, The method further includes: Determining a first client from among the plurality of clients based on load balancing.
10. A microservice call device, characterized in that, The device includes: A receiving module, configured to receive a microservice call request, where the microservice call request is used to trigger a first microservice to call a second microservice, the first microservice is implemented based on a first computer programming language, the second microservice is implemented based on a second computer programming language, and the first computer programming language and the second computer programming language are different; An obtaining module, configured to obtain a set of client instances corresponding to the second microservice, where the set of client instances includes clients of each of a plurality of instances corresponding to an interface of the second microservice, and the clients are implemented based on a target communication framework; A calling module, configured to call an interface of the second microservice based on a first client among the plurality of clients.
11. An electronic device, characterized in that, Comprising: At least one processor; And A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to any one of claims 1-9.
12. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, Wherein, The computer instructions are used to cause the computer to execute the method according to any one of claims 1-9.
13. A computer program product, characterized in that, Comprising a computer program, which implements the steps of the method according to any one of claims 1-9 when executed by a processor.