Remote service calling method and device

By querying the target service proxy object in a distributed system and dynamically selecting the RPC framework, and using the general service call interface for request conversion, the system transformation problem is solved when replacing the remote service call framework, and the system maintainability and scalability are improved.

CN120475062APending Publication Date: 2025-08-12SICHUAN RURAL COMMERCIAL UNITED BANK CO LTD +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510741855.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-04
Publication Date
2025-08-12

AI Technical Summary

Technical Problem

In the distributed system, the prior art is difficult to achieve transparent and efficient communication between different microservices, network segments, and computer rooms when remote service calls are called in a distributed system, and large-scale transformation of the application system is required when replacing the RPC calling framework.

Method used

By querying the target service proxy object, dynamically selecting the target remote service calling framework, and using the general service calling interface for request conversion, ensuring compatibility with multiple RPC frameworks and simplifying service docking complexity.

Benefits of technology

It realizes that when adding or replacing the RPC framework, only needs to update configuration files or a small amount of code, and does not require large-scale modification of the system architecture, improving the maintainability and scalability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120475062A_ABST
    Figure CN120475062A_ABST
Patent Text Reader

Abstract

The invention provides a remote service calling method and device, and the method comprises the steps: responding to a remote service calling request initiated by a service consumer, and querying a target service agent object; based on the general service calling interface, converting the remote service calling request, and docking a to-be-docked target remote service calling framework determined in a target configuration file, so as to determine a target service instance from a plurality of candidate service instances corresponding to a target service agent object through the target remote service calling framework, sending the converted remote service calling request to the target service instance; and receiving a remote service calling response generated by the target service instance in response to the converted remote service calling request, thereby ensuring the compatibility with various remote service calling frameworks, and realizing that when a new service calling framework is added or an existing service calling framework is changed, only a configuration file or a small number of codes need to be updated. And the whole system architecture does not need to be modified on a large scale, so that the maintainability and the expansibility of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a remote service invocation method and device. Background Art

[0002] Remote Procedure Call (RPC), also known as remote service call, plays an indispensable role in distributed systems, solving the problem of service call between different microservices, network segments, and data centers. RPC provides a transparent and efficient communication mechanism without having to worry about the details of underlying network communication. This transparent calling method not only speeds up communication between nodes, but also optimizes resource allocation and utilization efficiency, promoting overall system performance. Therefore, how to implement RPC is extremely important. Summary of the Invention

[0003] The present disclosure provides a remote service invocation method and apparatus to at least partially resolve one of the technical problems in the related art. The technical solution of the present disclosure is as follows:

[0004] According to a first aspect of an embodiment of the present disclosure, a remote service calling method is provided, comprising: in response to a service consumer initiating a remote service calling request, querying a target service proxy object that matches the remote service calling request; determining a target remote service calling framework to be docked from a target configuration file; based on a universal service calling interface adapted to multiple remote service calling frameworks, converting the remote service calling request, and docking the target remote service calling framework, so as to determine a target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service calling framework, and sending the converted remote service calling request to the target service instance; and receiving a remote service calling response generated by the target service instance in response to the converted remote service calling request.

[0005] According to the second aspect of an embodiment of the present disclosure, a remote service calling device is provided, comprising: a query module for querying a target service proxy object that matches a remote service calling request initiated by a service consumer; a determination module for determining a target remote service calling framework to be docked from a target configuration file; a docking module for converting the remote service calling request based on a universal service calling interface adapted to multiple remote service calling frameworks, and docking the target remote service calling framework, so as to determine a target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service calling framework, and send the converted remote service calling request to the target service instance; and a receiving module for receiving a remote service calling response generated by the target service instance in response to the converted remote service calling request.

[0006] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the remote service calling method as described in the embodiment of the first aspect of the present disclosure.

[0007] According to the fourth aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided. When the instructions in the computer-readable storage medium are executed by the processor of an electronic device, the electronic device can execute the remote service calling method as described in the embodiment of the first aspect of the present disclosure.

[0008] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising: a computer program, wherein when the computer program is executed by a processor, the remote service calling method as described in the embodiment of the first aspect of the present disclosure is implemented.

[0009] The technical solutions provided by the embodiments of the present disclosure bring at least the following beneficial effects:

[0010] In this technical solution, when a service consumer initiates a remote service call request, it queries the target service proxy object that matches the remote service call request and determines the target remote service call framework to be connected based on the target configuration file. It can dynamically adapt to different service requirements and environments, and use the universal service call interface to convert requests, ensuring compatibility with multiple remote service call frameworks and simplifying the complexity of service connection. In addition, the target remote service call framework to be connected is dynamically determined based on the target configuration file, so that when adding new services or changing existing service call frameworks, only the configuration file or a small amount of code needs to be updated, without the need for large-scale modifications to the entire system architecture, thereby improving the maintainability and scalability of the system.

[0011] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute an improper limitation of the present disclosure.

[0013] Figure 1 This is a flowchart of a remote service calling method according to the first embodiment of the present disclosure;

[0014] Figure 2 is a flowchart of a remote service calling method shown in the second embodiment of the present disclosure;

[0015] Figure 3 is a flowchart of a remote service calling method shown in the third embodiment of the present disclosure;

[0016] Figure 4 Schematic diagram of the RPC decoupling framework shown in the embodiment of the present disclosure;

[0017] Figure 5 This is a schematic diagram of the preparation process for remote service calling according to an embodiment of the present disclosure;

[0018] Figure 6 is a structural diagram of a remote service invoking device shown in the fourth embodiment of the present disclosure;

[0019] Figure 7 It is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0020] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.

[0021] It should be noted that the terms "first," "second," and the like in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the numbers used in this manner are interchangeable where appropriate so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure as detailed in the appended claims.

[0022] It should be noted that in the technical solutions disclosed herein, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, and are in compliance with relevant laws and regulations and do not violate public order and good morals.

[0023] The essence of remote calling is that the client encapsulates the interface and request parameters and transmits them to the server through the network. After the parameters are parsed, a series of local calls are made on the server. The server then encapsulates the returned results and transmits them back to the client through the network.

[0024] The above process involves service addressing, network transmission protocols, serialization and deserialization, and other aspects. With technological advancements, encapsulating these processes into application-transparent frameworks is becoming a trend. While mature application-level products are currently available, each product has its own protocol format, and service addressing must be performed through a registry. In a distributed microservices-based architecture, each application typically only uses one product as its technical foundation. If a business or technology stack change necessitates a change in product or RPC call framework, the application transformation required is substantial.

[0025] In response to the above problems, the present disclosure proposes a remote service invocation method and device.

[0026] The following describes the remote service calling method and apparatus according to the embodiments of the present disclosure with reference to the accompanying drawings.

[0027] Figure 1 1 is a flow chart of the remote service invocation method shown in the first embodiment of the present disclosure. It should be noted that the execution subject of the embodiment of the present disclosure may be a remote service invocation device, which may be set in the service consumer, or in the SDK integrated in the service consumer.

[0028] like Figure 1 As shown, the remote service calling method includes the following steps:

[0029] Step 101: In response to a remote service call request initiated by a service consumer, a target service proxy object matching the remote service call request is searched.

[0030] In order to achieve seamless calling and flexibility of remote services, in the embodiment of the present disclosure, when a service consumer initiates a remote service call request, a target service proxy object that matches the remote service call request is queried from the dependency injection container. The target service proxy object has information of multiple service instances (such as IP addresses and port numbers, etc.). The service consumer does not need to directly understand the specific service instance information (such as IP addresses and port numbers, etc.), nor does it need to understand the specific implementation details of the service, which reduces the direct dependency between the service consumer and the service provider and realizes the decoupling between the service consumer and the service provider.

[0031] Step 102: Determine the target remote service call framework to be connected from the target configuration file.

[0032] In order to improve the flexibility of remote service calls, in the embodiment of the present disclosure, relevant information of the service call framework (such as type, version, etc.) is specified in the configuration file. The remote service call device dynamically reads these configurations at runtime and selects the appropriate remote service call framework accordingly.

[0033] It should be noted that different remote service calls may use different remote service call frameworks (such as gRPC, RESTful HTTP, sofaRPC, etc.). By specifying the remote service call framework to be connected through the target configuration file, you can easily switch or expand the supported protocols and service frameworks without modifying the core logic of the service consumer.

[0034] Step 103, based on the universal service call interface adapted to multiple remote service call frameworks, convert the remote service call request and connect to the target remote service call framework to determine the target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service call framework, and send the converted remote service call request to the target service instance.

[0035] It is important to understand that the universal service call interface that is compatible with multiple remote service call frameworks can hide the differences between different remote service call frameworks (such as gRPC, RESTful HTTP, sofaRPC, etc.). When consumers initiate service calls, they do not need to care about the specific implementation details of the underlying layer.

[0036] In the disclosed embodiments, the generic service call interface converts the original remote service call request into a data format suitable for network transmission, based on the requirements of the target remote service call framework. For example, gRPC may require the Protobuf format, while RESTful services may require the JSON or XML format. In addition to data format conversion, the request structure may also be adjusted, such as adding necessary header information, setting the URL path and HTTP method (GET, POST, etc.) to ensure that the request meets the requirements of the target remote service call framework.

[0037] Furthermore, by calling the general service call interface and connecting to the target remote service call framework, the target remote service call framework can determine the target service instance from multiple candidate service instances corresponding to the target service proxy object based on the selection strategy, where the selection strategy includes: load balancing strategy, health check strategy, etc. After determining the target service instance, the target remote service call framework sends the converted remote service call request to the target service instance.

[0038] As an example, the target remote service call framework encapsulates the converted remote service call request to obtain a target message; determines the target service instance from multiple candidate service instances corresponding to the target service proxy object; sends the target message to the target service instance; wherein the target message is used for the target service instance to perform message parsing to obtain the converted remote service call request, and generates a remote service call response in response to the converted remote service call request.

[0039] That is to say, the target remote service call framework first encapsulates the converted remote service call request into a specific message format, namely the target message. The format of the target message is designed specifically for network transmission, ensuring the integrity and readability of the data; next, the framework will select the most suitable service instance as the target service instance from the multiple candidate service instances managed by the target service proxy object by selecting a strategy (such as load balancing, service health check, etc.). After determining the target service instance, the framework will send the encapsulated target message to the target service instance through the network. After receiving the message, the target service instance will perform a series of parsing operations to restore the original remote service call request; then, the target service instance will execute the corresponding business logic according to the content of the request and generate a remote service call response, which also needs to be encapsulated according to a predefined protocol format (such as JSON, XML or Protobuf) and then returned to the service consumer who initiated the request.

[0040] Step 104: Receive a remote service call response generated by the target service instance in response to the converted remote service call request.

[0041] In an embodiment of the present disclosure, when the target service instance receives the converted remote service call request, the converted remote service call request is processed. Based on the content of the request (method name, parameters, etc.), the target service instance executes the corresponding business logic and generates a remote service call response. The remote service call response may include processing results or status information. When the target service instance returns the remote service call response, the universal service call interface needs to deserialize the remote service call response from its transmission format (such as JSON, XML or Protobuf) into a native object or structure, so that service consumers can easily access and process data.

[0042] The remote service calling method of the embodiment of the present disclosure queries the target service proxy object that matches the remote service calling request by responding to the service consumer; determines the target remote service calling framework to be connected from the target configuration file; converts the remote service calling request based on the universal service calling interface adapted to multiple remote service calling frameworks, and connects to the target remote service calling framework, so as to determine the target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service calling framework, and sends the converted remote service calling request to the target service instance; receives the remote service calling response generated by the target service instance in response to the converted remote service calling request Therefore, when a service consumer initiates a remote service call request, it queries the target service proxy object that matches the remote service call request and determines the target remote service call framework to be connected based on the target configuration file. It can dynamically adapt to different service requirements and environments, and use the universal service call interface to convert requests, ensuring compatibility with multiple remote service call frameworks and simplifying the complexity of service connection. In addition, the target remote service call framework to be connected is dynamically determined based on the target configuration file, so that when adding new services or changing existing service call frameworks, only the configuration file or a small amount of code needs to be updated, without the need for large-scale modifications to the entire system architecture, thereby improving the maintainability and scalability of the system.

[0043] In order to clearly illustrate how to respond to a remote service call request initiated by a service consumer and query a service proxy object that matches the remote service call request in the above embodiment, the present disclosure proposes another remote service call method.

[0044] Figure 2 It is a flowchart of the remote service calling method shown in the second embodiment of the present disclosure.

[0045] like Figure 2 As shown, the remote service calling method includes the following steps:

[0046] Step 201: In response to a remote service call request initiated by a service consumer, target service identification information in the remote service call request is obtained.

[0047] In the embodiments of the present disclosure, a remote service call request usually includes some key identification information, which is used to uniquely identify the service proxy object. This may include but is not limited to the service name, version number, etc. Therefore, the target service identification information, such as the service name, version number, etc., can be extracted from the remote service call request.

[0048] Step 202: According to the target service identification information, a target service proxy object matching the target service identification information is searched from a plurality of candidate service proxy objects in the dependency injection container.

[0049] It is important to understand that a dependency injection container is a design pattern used to manage the creation of objects and their dependencies. The dependency injection container stores multiple service proxy objects, each of which corresponds to one or more remote service instances.

[0050] In the disclosed embodiment, based on the target service identification information extracted from the remote service call request, a target service proxy object that matches the target service identification information is searched in the dependency injection container. For example, the target service proxy object is searched by comparing identifiers such as the service name and version.

[0051] Step 203: Determine the target remote service call framework to be connected from the target configuration file.

[0052] Step 204, based on the universal service call interface adapted to multiple remote service call frameworks, convert the remote service call request and connect to the target remote service call framework to determine the target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service call framework, and send the converted remote service call request to the target service instance.

[0053] Step 205: Receive a remote service call response generated by the target service instance in response to the converted remote service call request.

[0054] It should be noted that the execution process of steps 203 to 205 can be implemented in any of the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.

[0055] In summary, by responding to the service consumer initiating a remote service call request, the target service identification information in the remote service call request is obtained; based on the target service identification information, the target service proxy object that matches the target service identification information is queried from multiple candidate service proxy objects in the dependency injection container. Thus, by dynamically finding and using appropriate service proxy objects, the decoupling between the service consumer and the specific service implementation is achieved, the service management and integration process is simplified, and new service instances can be easily added to the dependency injection container without adjusting the existing system architecture, thereby improving the stability and reliability of the system.

[0056] Based on any of the above embodiments, before a service consumer initiates a remote service request, the service consumer needs to subscribe to the target service from the registration center. If the target service has been successfully registered in the registration center, the service instance of the target service is sent to the service consumer so that the service consumer can dynamically obtain the address information of the service provider at runtime. Figure 3 The embodiments are described in detail.

[0057] Figure 3 It is a flowchart of the remote service calling method shown in the third embodiment of the present disclosure.

[0058] like Figure 3 As shown, the remote service calling method includes the following steps:

[0059] Step 301: In response to a service consumer being started, an initial service subscription request is generated.

[0060] In an embodiment of the present disclosure, in response to a service consumer being started, a first service configuration file associated with the service consumer is obtained and parsed to obtain information about services to be subscribed associated with the service consumer; and an initial subscription request is generated based on the information about the services to be subscribed.

[0061] That is to say, during the process of starting the service consumer, a configuration file associated with the service consumer, namely the first configuration file, is loaded, wherein the first configuration file contains the service information to be subscribed associated with the service consumer. Then, the first configuration file is parsed to extract the service information to be subscribed associated with the service consumer from the first configuration file. For example, the service information to be subscribed includes: service name, service version, etc.; and then, based on the service information to be subscribed, an initial subscription request is generated.

[0062] Step 302: Acquire multiple candidate service instances based on the initial service subscription request and the target configuration file.

[0063] In order to improve the flexibility, maintainability and scalability of remote service calls, in the embodiment of the present disclosure, based on the target configuration file, the service consumer subscribes to the target service to the target service registration center through the service subscription interface, receives and associates multiple candidate service instances of the target service to the service proxy object.

[0064] As an example, based on the target configuration file, the service subscription interface is called to convert the initial service subscription request into a target service subscription request adapted to the target remote service call framework through the service subscription interface, and the target service subscription request is sent to the target service registration center adapted to the target remote service call framework through the target remote service call framework; wherein, the target service subscription request is used to subscribe to the target service to the target service registration center; multiple candidate service instances of the target service sent by the target service registration center are received, and the multiple candidate service instances are associated with the target service proxy object; wherein, the multiple candidate service instances are sent when the target service provided by the service provider is successfully registered by the target service registration center.

[0065] That is to say, based on the target configuration file, the service consumer first calls the service subscription interface, and by calling the service subscription interface, converts the initial service subscription request into a target service subscription request that is compatible with the target remote service call framework specified in the target configuration file; then, the target remote service call framework is connected, and the converted target service subscription request is sent to the target service registration center corresponding to the target remote service call framework through the target remote service call framework, wherein the target service subscription request is used to subscribe to the specified target service to the target service registration center. If the target service has been registered in the target service registration center, multiple candidate service instances of the target service are sent according to the service provider information of the registered target service, wherein the candidate service instance includes the IP address and port for locating the target service; then, the service consumer associates these received candidate service instances with the locally maintained target service proxy object.

[0066] Among them, it should be noted that, in the process of the service consumer calling the service subscription interface, the target service proxy object associated with the target service is synchronously generated through the target remote service call framework; the target service proxy object is injected into the initialized dependency injection container; wherein, the initialization timing of the dependency injection container includes the startup of the service consumer.

[0067] That is, when a service consumer starts up and calls the service subscription interface, the target remote service call framework synchronously creates a target service proxy object associated with the target service; this target service proxy object is then injected into the already initialized dependency injection container. To ensure that the service proxy object is injected promptly for subsequent service calls, the dependency injection container is initialized when the service consumer starts up.

[0068] In addition, it should be noted that when the target service is successfully registered, the target service registration center generates multiple candidate service instances. The steps for generating multiple candidate service instances are as follows:

[0069] 1. In response to a service provider initiation, generate an initial service registration request;

[0070] In an embodiment of the present disclosure, when the service provider is started, the service provider can obtain a second configuration file associated with itself and parse the second service configuration file to obtain the service information to be registered associated with the service provider (such as service name, service version, service port, service protocol, etc.); then, based on the service information to be registered, an initial service registration request is generated.

[0071] 2. Based on the target configuration file, call the service registration interface to convert the initial service registration request into a target service registration request that is adapted to the target remote service call framework through the service registration interface, and send the target service registration request to the target service registration center that is adapted to the target remote service call framework through the target remote service call framework; wherein, the target service registration request is used by the target service registration center to register the target service according to the target service registration request, and generates multiple candidate service instances when the target service registration is successful.

[0072] That is to say, when the service provider starts, the service registration interface is called, and based on the target remote service call framework recorded in the target configuration file, the initial service registration request sent by the service provider is converted into a target service registration request that is adapted to the target remote service call framework, ensuring that the converted target service registration request can be understood and transmitted by the target remote service call framework; then, the target remote service call framework is connected, and the target service registration request is sent to the target service registration center that is adapted to the target remote service call framework through the target remote service call framework. After the target service registration center receives the request, it will perform the service registration operation based on the information in the request. When the registration is successful, the service registration center will generate multiple candidate service instances for the service provider (such as the IP address and port of the target service).

[0073] Step 303: In response to the remote service call request initiated by the service consumer, query the target service proxy object that matches the remote service call request.

[0074] Step 304: Determine the target remote service call framework to be connected from the target configuration file.

[0075] Step 305: Based on a universal service call interface that is compatible with multiple remote service call frameworks, the remote service call request is converted and connected to the target remote service call framework to determine the target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service call framework, and send the converted remote service call request to the target service instance.

[0076] Step 306: Receive a remote service call response generated by the target service instance in response to the converted remote service call request.

[0077] It should be noted that the execution process of steps 303 to 306 can be implemented in any of the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.

[0078] In summary, by responding to the service consumer opening, an initial service subscription request is generated; based on the initial service subscription request and the target configuration file, multiple candidate service instances are obtained. Therefore, the service consumer does not need to know the specific location or number of service providers in advance, but can obtain the list of available service instances from the service registration center according to the rules defined in the target configuration file and the requirements in the service subscription request. When the service provider changes (such as addition, reduction or update), the target service proxy object adaptively adjusts its associated service instance list to ensure the continuity and reliability of the service.

[0079] On the basis of any embodiment of the present disclosure, by analyzing the mainstream RPC framework, a common interface (common service call interface, service subscription interface and service registration interface) is abstracted to achieve adaptation to different RPC frameworks. Different frameworks require different adaptation implementations. A decoupling layer is used to shield the differences in application response to different RPC frameworks. The RPC decoupling framework is integrated into the business application (service consumer) in the form of an SDK, such as Figure 4 As shown, it is logically divided into a decoupling layer and an adaptation layer. The RPC decoupling framework includes a standard RPC core component layer (decoupling layer) and an RPC and registration center adapter layer (adaptation layer).

[0080] Among them, the standard RPC core component layer is used to rely on the adaptation layer to initiate service subscription and call when the business application starts, and to establish a local proxy object for the remote service (that is, to synchronously generate a target service proxy object associated with the target service through the target remote service call framework);

[0081] For example, the Standard RPC Core component reads the configuration files consume.xml (the configuration file associated with the service consumer) and provide.xml (the configuration file associated with the service provider) to complete service registration and subscription. Specifying protocol="sofa" in the configuration file associated with the adaptation layer connects to the SOFA RPC framework through the SOFA RPC adaptation layer.

[0082] The RPC and registry center adapter (adaptation layer) is used to connect to different RPC protocols and frameworks, and encapsulate RPC API calls for use in the decoupling layer;

[0083] The adaptation layer uses the SPI extension mechanism to define common interface classes specifically for adapting to third-party RPC frameworks. Specific implementation classes implement related methods and RPC API encapsulation. For example, in the case of SOFA RPC, the adaptation layer defines the RpcProtocolAdapter interface class. The corresponding SOFA RPC implementation is SofaAdapter, which provides several key interfaces: service registration (registService), service subscription (registReference), and service invocation (invoke).

[0084] After the RPC decoupling layer completes the RPC data model conversion, service registration and subscription, process encapsulation and other operation processes, the application layer is unaware of the specific RPC call process, achieving a loosely coupled design and reducing the difficulty of maintaining the business module. Figure 5 The specific steps are as follows:

[0085] 1. Application startup, dependency injection container initialization

[0086] When the application starts, the dependency injection container is initialized first to ensure that all necessary components and services are initialized and configured correctly.

[0087] After the dependency injection container is initialized, it reads the configuration file associated with the business application and parses the required service information from it. This information may include the service name, version number, protocol type, etc.

[0088] 2. Initialize resources

[0089] RpcCore (standard RPC core component) initializes the required resources. These resources may include network connections, thread pools, etc., in preparation for subsequent service registration and service subscription.

[0090] 3. SOFARPC API and Adaptation Layer

[0091] SofaAdapter, as the adaptation layer, is responsible for interacting with a specific RPC framework (such as SOFA) and implementing service registration and subscription functions by calling the API provided by the RPC framework.

[0092] 4. Initiate service registration (also known as service exposure) and service subscription (also known as service reference)

[0093] RpcCore initiates the exposure of services (i.e., service providers register services with the registry) and references (i.e., service consumers subscribe to services).

[0094] 5. Return the reference object proxy

[0095] Interact with the RPC framework through SofaAdapter to create a service proxy object so that the application can call the remote service through the proxy object;

[0096] 6. Maintain reference object table

[0097] RpcContext (an important component in the SOFA RPC framework for managing context information) maintains a reference object table that records all referenced service instances.

[0098] 7. Service Proxy Injection into Dependency Injection Container

[0099] Finally, the generated service proxy objects are injected into the dependency injection container. In this way, other components or modules can easily access these service proxy objects through dependency injection and make remote service calls.

[0100] Taking SOFA RPC calls as an example, when an application initiates an RPC call, it obtains the remote service proxy class object ProxyInvoker returned by SOFA RPC from the dependency injection container, and then initiates a direct call to the interface; this call action is intercepted by the underlying routing rules of SOFA RPC. The final service call process is actually a network communication through the client responsible for communication in SOFA RPC, which sends the request to the service provider.

[0101] Corresponding to the remote service calling method provided in the above embodiment, the present disclosure also provides a remote service calling device. Since the remote service calling device provided in the embodiment of the present disclosure corresponds to the remote service calling method provided in the above embodiment, the implementation method of the remote service calling method is also applicable to the remote service calling device provided in the embodiment of the present disclosure, and will not be described in detail in the embodiment of the present disclosure.

[0102] Figure 6 4 is a schematic diagram of the structure of the remote service calling device shown in the fourth embodiment of the present disclosure.

[0103] like Figure 6 As shown, the remote service calling device 600 includes: a query module 610 , a determination module 620 , a docking module 630 and a receiving module 640 .

[0104] Among them, the query module 610 is used to respond to the service consumer initiating a remote service call request and query the target service proxy object that matches the remote service call request; the determination module 620 is used to determine the target remote service call framework to be docked from the target configuration file; the docking module 630 is used to convert the remote service call request based on a universal service call interface adapted to multiple remote service call frameworks, and dock with the target remote service call framework, so as to determine the target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service call framework, and send the converted remote service call request to the target service instance; the receiving module 640 is used to receive the remote service call response generated by the target service instance in response to the converted remote service call request.

[0105] As a possible implementation of the embodiment of the present disclosure, the converted remote service call request is used for the target remote service call framework to use the following modules to perform the following steps: first, generate a module.

[0106] The first generation module is used to encapsulate the converted remote service call request into a message to obtain a target message; determine the target service instance from multiple candidate service instances corresponding to the target service proxy object; and send the target message to the target service instance; wherein the target message is used for the target service instance to perform message parsing to obtain the converted remote service call request, and generate a remote service call response in response to the converted remote service call request.

[0107] As a possible implementation method of the embodiment of the present disclosure, the query module 610 is used to obtain the target service identification information in the remote service call request in response to the service consumer initiating the remote service call request; based on the target service identification information, query the target service proxy object that matches the target service identification information from multiple candidate service proxy objects in the dependency injection container.

[0108] As a possible implementation of the embodiment of the present disclosure, the remote service invoking apparatus 600 further includes: an acquisition module.

[0109] The acquisition module is used to generate an initial service subscription request in response to the service consumer being started; and acquire multiple candidate service instances based on the initial service subscription request and the target configuration file.

[0110] As a possible implementation method of an embodiment of the present disclosure, an acquisition module is used to call a service subscription interface based on the target configuration file, so as to convert the initial service subscription request into a target service subscription request adapted to the target remote service call framework through the service subscription interface, and send the target service subscription request to a target service registration center adapted to the target remote service call framework through the target remote service call framework; wherein, the target service subscription request is used to subscribe to the target service to the target service registration center; receive multiple candidate service instances of the target service sent by the target service registration center, and associate the multiple candidate service instances with the target service proxy object; wherein, the multiple candidate service instances are sent when the target service provided by the service provider is successfully registered by the target service registration center.

[0111] As a possible implementation of an embodiment of the present disclosure, an acquisition module is configured to, in response to a service consumer being enabled, acquire a first service configuration file associated with the service consumer; parse the first service configuration file to obtain information about services to be subscribed associated with the service consumer; and generate an initial subscription request based on the information about the services to be subscribed.

[0112] As a possible implementation of the embodiment of the present disclosure, multiple candidate service instances are generated using the following modules: a second generation module.

[0113] The second generation module is used to generate an initial service registration request in response to the startup of the service provider; based on the target configuration file, the service registration interface is called to convert the initial service registration request into a target service registration request that is adapted to the target remote service call framework through the service registration interface, and the target service registration request is sent to the target service registration center that is adapted to the target remote service call framework through the target remote service call framework; wherein, the target service registration request is used by the target service registration center to register the target service according to the target service registration request, and multiple candidate service instances are generated when the target service registration is successful.

[0114] As a possible implementation method of the embodiment of the present disclosure, the second generation module is used to obtain a second service configuration file associated with the service provider; parse the second service configuration file to obtain the service information to be registered associated with the service provider; and generate an initial service registration request based on the service information to be registered.

[0115] As a possible implementation of the embodiment of the present disclosure, the remote service calling apparatus 600 further includes: an injection module.

[0116] Among them, the injection module is used to synchronously generate a target service proxy object associated with the target service through the target remote service call framework during the process of the service consumer calling the service subscription interface; inject the target service proxy object into the initialized dependency injection container; wherein the initialization timing of the dependency injection container includes the startup of the service consumer.

[0117] The remote service calling device of the embodiment of the present disclosure queries the target service proxy object that matches the remote service calling request by responding to the service consumer; determines the target remote service calling framework to be connected from the target configuration file; converts the remote service calling request based on the universal service calling interface adapted to multiple remote service calling frameworks, and connects to the target remote service calling framework, so as to determine the target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service calling framework, and sends the converted remote service calling request to the target service instance; receives the remote service calling response generated by the target service instance in response to the converted remote service calling request Therefore, when a service consumer initiates a remote service call request, it queries the target service proxy object that matches the remote service call request and determines the target remote service call framework to be connected based on the target configuration file. It can dynamically adapt to different service requirements and environments, and use the universal service call interface to convert requests, ensuring compatibility with multiple remote service call frameworks and simplifying the complexity of service connection. In addition, the target remote service call framework to be connected is dynamically determined based on the target configuration file, so that when adding new services or changing existing service call frameworks, only the configuration file or a small amount of code needs to be updated, without the need for large-scale modifications to the entire system architecture, thereby improving the maintainability and scalability of the system.

[0118] In an exemplary embodiment, an electronic device is also provided.

[0119] Among them, electronic equipment includes:

[0120] processor;

[0121] a memory for storing processor-executable instructions;

[0122] The processor is configured to execute instructions to implement the remote service calling method proposed in any of the aforementioned embodiments.

[0123] As an example, Figure 7 is a structural diagram of an electronic device 700 shown in an exemplary embodiment of the present disclosure, such as Figure 7 As shown, the electronic device 700 may further include:

[0124] The memory 710 and the processor 720, and the bus 730 connecting different components (including the memory 710 and the processor 720), the memory 710 stores a computer program, and when the processor 720 executes the program, the remote service calling method described in the embodiment of the present disclosure is implemented.

[0125] Bus 730 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. Examples of these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.

[0126] The electronic device 700 typically includes a variety of electronic device-readable media, which can be any available media that can be accessed by the electronic device 700, including volatile and non-volatile media, removable and non-removable media.

[0127] The memory 710 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 740 and / or cache memory 750. The server 700 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 760 may be used to read and write non-removable, non-volatile magnetic media ( Figure 7 Not shown, often called a "hard drive"). Although Figure 7 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 730 via one or more data medium interfaces. Memory 710 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of various embodiments of the present disclosure.

[0128] A program / utility 780 having a set (at least one) of program modules 770 may be stored, for example, in memory 710. Such program modules 770 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may include an implementation of a network environment. Program modules 770 generally implement the functions and / or methods of the embodiments described herein.

[0129] The electronic device 700 can also communicate with one or more external devices 790 (e.g., a keyboard, a pointing device, a display 791, etc.), one or more devices that enable a user to interact with the electronic device 700, and / or any device that enables the electronic device 700 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication can occur via an input / output (I / O) interface 792. Furthermore, the electronic device 700 can communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network such as the Internet) via a network adapter 793. As shown, the network adapter 793 communicates with other modules of the electronic device 700 via a bus 730. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the electronic device 700, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0130] The processor 720 executes various functional applications and data processing by running programs stored in the memory 710 .

[0131] It should be noted that the implementation process and technical principles of the electronic device of this embodiment can be found in the aforementioned explanation of the remote service calling method of the embodiment of the present disclosure, and will not be repeated here.

[0132] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions. The instructions can be executed by a processor of an electronic device to implement the remote service invocation method proposed in any of the above embodiments. Alternatively, the computer-readable storage medium can be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, optical data storage device, etc.

[0133] In an exemplary embodiment, a computer program product is further provided, including a computer program / instruction, wherein the computer program / instruction, when executed by a processor, implements the remote service calling method proposed in any of the above embodiments.

[0134] Other embodiments of the present disclosure will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the present disclosure being indicated by the following claims.

[0135] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A remote service calling method, characterized in that: include: In response to a remote service call request initiated by a service consumer, querying a target service proxy object that matches the remote service call request; Determine the target remote service call framework to be connected from the target configuration file; Based on a universal service call interface adapted to multiple remote service call frameworks, the remote service call request is converted and connected to the target remote service call framework, so as to determine a target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service call framework, and send the converted remote service call request to the target service instance; Receive a remote service call response generated by the target service instance in response to the converted remote service call request.

2. The method according to claim 1, characterized in that The converted remote service call request is used by the target remote service call framework to execute the following steps: Encapsulating the converted remote service call request into a message to obtain the target message; Determine a target service instance from a plurality of candidate service instances corresponding to the target service proxy object; The target message is sent to the target service instance; wherein the target message is used by the target service instance to perform message parsing, obtain the converted remote service call request, and generate the remote service call response in response to the converted remote service call request.

3. The method according to claim 1, characterized in that The step of querying a service proxy object that matches a remote service call request initiated by the service consumer includes: In response to the service consumer initiating a remote service call request, obtaining target service identification information in the remote service call request; According to the target service identification information, a target service proxy object that matches the target service identification information is searched from a plurality of candidate service proxy objects in a dependency injection container.

4. The method according to claim 1, wherein Before the service consumer initiates a remote service call request and searches for a target service proxy object that matches the remote service call request, the method further includes: In response to the service consumer being started, generating an initial service subscription request; The plurality of candidate service instances are obtained based on the initial service subscription request and the target configuration file.

5. The method according to claim 4, characterized in that The acquiring the plurality of candidate service instances based on the initial service subscription request and the target configuration file includes: Based on the target configuration file, calling a service subscription interface to convert the initial service subscription request into a target service subscription request adapted to the target remote service call framework through the service subscription interface, and sending the target service subscription request to a target service registration center adapted to the target remote service call framework through the target remote service call framework; wherein the target service subscription request is used to subscribe to a target service from the target service registration center; Receive multiple candidate service instances of the target service sent by the target service registration center, and associate the multiple candidate service instances with the target service proxy object; wherein the multiple candidate service instances are sent when the target service provided by the service provider is successfully registered by the target service registration center.

6. The method according to claim 4, characterized in that The generating of an initial service subscription request in response to the service consumer being started includes: In response to the service consumer being started, obtaining a first service configuration file associated with the service consumer; Parsing the first service configuration file to obtain information about the service to be subscribed associated with the service consumer; The initial subscription request is generated according to the information of the service to be subscribed.

7. The method according to claim 5, characterized in that The multiple candidate service instances are generated by the following steps: In response to a service provider initiation, generating an initial service registration request; Based on the target configuration file, a service registration interface is called to convert the initial service registration request into a target service registration request adapted to the target remote service call framework through the service registration interface, and the target service registration request is sent to a target service registration center adapted to the target remote service call framework through the target remote service call framework; wherein, the target service registration request is used by the target service registration center to register the target service according to the target service registration request, and to generate the multiple candidate service instances when the target service registration is successful.

8. The method according to claim 7, characterized in that The generating of an initial service registration request in response to the service provider starting up includes: obtaining a second service profile associated with the service provider; Parsing the second service configuration file to obtain information of the service to be registered associated with the service provider; Generate the initial service registration request according to the service information to be registered.

9. The method according to claim 7, characterized in that The method further comprises: In the process of the service consumer calling the service subscription interface, a target service proxy object associated with the target service is synchronously generated through the target remote service calling framework; Injecting the target service proxy object into the initialized dependency injection container; The initialization timing of the dependency injection container includes the startup of the service consumer.

10. A remote service calling device, characterized in that: include: A query module, configured to query a target service proxy object that matches a remote service call request initiated by a service consumer; A determination module is used to determine the target remote service call framework to be connected from the target configuration file; a docking module for converting the remote service call request based on a universal service call interface adapted to multiple remote service call frameworks, and docking with the target remote service call framework to determine a target service instance from multiple candidate service instances corresponding to the target service proxy object through the target remote service call framework, and sending the converted remote service call request to the target service instance; The receiving module is configured to receive a remote service call response generated by the target service instance in response to the converted remote service call request.

Citation Information

Cited By

  • Multi-process parallel communication method and device, equipment and storage medium

    CN121078103A