A method and apparatus for invoking a remote service
By using framework calling codes to generate remote service calls through TCP protocols, the method addresses the limitations of existing frameworks in cross-language, cross-platform remote calling, enhancing speed and user experience.
Patent Information
- Application Number
- CN202110144183.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-02
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2041-02-02
AI Technical Summary
The existing service framework system only supports remote calls between the backgrounds of fixed development languages, and cannot meet the needs of cross-platform and cross-language, resulting in the speed of remote service calls through the HTTP request gateway.
Configure framework calling code for the client, use the TCP protocol to generate cross-language call requests, realize cross-language cross-platform communication decoupling between the server and the client, and interact with the service framework system through a proxy server to obtain the results of remote service call.
It improves the speed of remote service calls, improves user experience, and achieves the freedom of language development and overall performance improvement.
Smart Images

Figure CN113821352B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular, to a method and device for remotely invoking services. Background Art
[0002] With the development and expansion of the Internet scale, service functions are continuously refined, and users often call services in a service framework system (such as Jingdong Service Framework system of JD.com) to meet functional requirements. In remote service invocation, when the service framework system does not support direct invocation, an HTTP request gateway is required to achieve remote invocation.
[0003] In the process of implementing the present invention, at least the following problems exist in the prior art:
[0004] Some service framework systems only support remote invocations between backends of fixed development languages and cannot meet the needs of cross-platform and cross-language remote invocations. Therefore, when the backend of a PC, mobile device, or other development language calls a service, an HTTP request gateway is required to perform remote service invocations. Since the HTTP protocol has a larger message volume compared to the custom TCP protocol for remote invocations, it will affect the data transmission performance per unit time. Furthermore, when the data volume is large, the speed of providing remote services by existing service framework systems is often affected. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a method and device for remotely invoking services, which can configure corresponding framework invocation codes for a client, and then use the framework invocation codes to generate a call request for a remote service across languages through the TCP protocol during the invocation process, realizing cross-language and cross-platform communication decoupling between the server and the client, enabling the invoker to achieve freedom in language development; and can generate requests only through the TCP protocol during the invocation process, improving the overall invocation speed and enhancing the user experience.
[0006] To achieve the above object, according to one aspect of the embodiments of the present invention, a method for remotely invoking services is provided, including:
[0007] Receiving a first call request for a remote service, and obtaining corresponding framework invocation codes in response to the first call request;
[0008] Based on the first call request, using the framework invocation codes to generate a second call request for a proxy server, so that the proxy server requests and obtains a remote service call result from the service framework system through the TCP protocol according to the second call request;
[0009] Receiving the remote service call result returned by the proxy server to achieve the invocation of the remote service.
[0010] Optionally, obtaining corresponding framework call code in response to the first call request includes:
[0011] Parsing the first call request to determine the service identifier indicated by the first call request;
[0012] Obtaining corresponding framework call code from a preset file storage system according to the service identifier; or, obtaining a service contract file from the preset file storage system according to the service identifier, and generating framework call code corresponding to the service identifier based on the service contract file.
[0013] Optionally, the method for calling a remote service further includes:
[0014] The language type of the framework call code is consistent with the language type of the first call request.
[0015] Optionally, after obtaining the corresponding framework call code, it further includes:
[0016] Injecting the framework call code into the client code.
[0017] Optionally, the parsing of the first call request further includes: parsing the first call request to determine the input parameter information indicated by the first call request;
[0018] And, generating a second call request for the proxy server based on the first call request and using the framework call code includes:
[0019] Serializing and expressing the input parameter information using the framework call code; generating a second call request for the proxy server through the TCP protocol based on the serialization and expression result.
[0020] Optionally, enabling the proxy server to request and obtain a remote service call result from the service framework system according to the second call request through the TCP protocol includes:
[0021] Deserializing and expressing the serialization and expression result in the second call request using the proxy server;
[0022] Generating a third call request for the remote service in the service framework system through the TCP protocol using the proxy server based on the deserialization and expression result;
[0023] Receiving the remote service call result returned by the service framework system in response to the third call request using the proxy server.
[0024] Optionally, before the proxy server requests and obtains the remote service call result from the service framework system according to the second call request through the TCP protocol, the following steps are further included:
[0025] Pre-configure the framework service code for the proxy server based on the service contract file in advance;
[0026] Utilize the framework service code to generate the SPI interface class data for the service consumer in the service framework system to call the service producer through Javaassist, and input the SPI interface class data into the development toolkit of the service framework system; and,
[0027] Utilize the proxy server to generate a third call request for the remote service in the service framework system based on the result of the deserialized expression through the TCP protocol, including:
[0028] Utilize the proxy server to adapt the result of the deserialized expression to the SPI interface class data to determine the service interface data of the remote service, and then generate the third call request through the TCP protocol based on the service interface data.
[0029] According to another aspect of the embodiments of the present invention, a device for calling a remote service is provided, including:
[0030] A receiving module, configured to receive a first call request for a remote service, and obtain a corresponding framework call code in response to the first call request;
[0031] A calling module, configured to generate a second call request for a proxy server based on the first call request by using the framework call code, so that the proxy server requests and obtains the remote service call result from the service framework system according to the second call request through the TCP protocol;
[0032] An execution module, configured to receive the remote service call result returned by the proxy server to implement the call of the remote service.
[0033] Optionally, the receiving module obtaining the corresponding framework call code in response to the first call request includes:
[0034] Parse the first call request to determine the service identifier indicated by the first call request;
[0035] Obtain the corresponding framework call code from a preset file storage system according to the service identifier; or obtain a service contract file from a preset file storage system according to the service identifier to generate a framework call code corresponding to the service identifier based on the service contract file.
[0036] Optionally, the language type of the framework call code is the same as the language type of the first call request.
[0037] Optionally, after the receiving module obtains the corresponding framework call code, it further includes:
[0038] Inject the framework call code into the client code.
[0039] Optionally, when the receiving module parses the first call request, it further includes: parsing the first call request to determine the input parameter information indicated by the first call request;
[0040] And, based on the first call request, the calling module generates a second call request to the proxy server using the framework call code, including:
[0041] Serialize and express the input parameter information using the framework call code; generate a second call request to the proxy server through the TCP protocol based on the serialization expression result.
[0042] Optionally, the calling module causes the proxy server to request and obtain a remote service call result from the service framework system through the TCP protocol according to the second call request, including:
[0043] Deserialize and express the serialization expression result in the second call request using the proxy server;
[0044] Generate a third call request to the remote service in the service framework system through the TCP protocol using the proxy server based on the result of the deserialization expression;
[0045] Receive the remote service call result returned by the service framework system in response to the third call request using the proxy server.
[0046] Optionally, before the calling module causes the proxy server to request and obtain a remote service call result from the service framework system through the TCP protocol according to the second call request, it further includes:
[0047] Pre-configure framework service code for the proxy server based on the service contract file;
[0048] Using the framework service code, generate SPI interface class data for a service consumer in the service framework system to call a service producer through Javaassist, and pass the SPI interface class data into the development toolkit of the service framework system; and,
[0049] Based on the result of deserialization expression, the proxy server generates a third call request for the remote service in the service framework system through the TCP protocol, including:
[0050] The proxy server adapts the result of the deserialization expression to the SPI interface class data to determine the service interface data of the remote service, and then generates the third call request through the TCP protocol based on the service interface data.
[0051] According to another aspect of the embodiments of the present invention, a remote service call electronic device is provided, including:
[0052] One or more processors;
[0053] A storage device for storing one or more programs,
[0054] When the one or more programs are executed by the one or more processors, the one or more processors implement the remote service call method provided by the present invention.
[0055] According to still another aspect of the embodiments of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the remote service call method provided by the present invention is implemented.
[0056] One of the embodiments of the above invention has the following advantages or beneficial effects: Because corresponding function codes are configured for the client and the server, and then the function codes are used to generate call requests cross-linguistically through the TCP protocol during the call process, the technical problem of slow speed caused by the need to perform remote service calls through an HTTP request gateway in the prior art due to the inability to meet the cross-platform and cross-language remote call requirements is overcome. Furthermore, cross-language and cross-platform communication decoupling between the server and the client is achieved, enabling the caller to develop freely in different languages, and only generating requests through the TCP protocol during the call process, achieving the technical effects of improving the overall call speed and enhancing the user experience.
[0057] The further effects of the above non-conventional optional manner will be described in conjunction with specific embodiments hereinafter. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] The drawings are used to better understand the present invention and do not constitute an improper limitation to the present invention. Among them:
[0059] Figure 1 is a schematic diagram of the main process of a remote service call method according to the first embodiment of the present invention;
[0060] Figure 2It is a schematic flowchart of a method for invoking a remote service according to the second embodiment of the present invention;
[0061] Figure 3 It is a schematic diagram of the configuration of a proxy server cluster in a method for invoking a remote service according to the third embodiment of the present invention;
[0062] Figure 4 It is a schematic diagram of communication between a client and a proxy server in a method for invoking a remote service according to the fourth embodiment of the present invention;
[0063] Figure 5 It is a schematic framework diagram of a method for invoking a remote service according to the fifth embodiment of the present invention;
[0064] Figure 6 It is a schematic framework diagram of a method for invoking a remote service according to the sixth embodiment of the present invention;
[0065] Figure 7 It is a schematic diagram of a visualization window for configuring a proxy server in a method for invoking a remote service according to the seventh embodiment of the present invention;
[0066] Figure 8 It is a schematic diagram of a visualization window for monitoring through a proxy server interface in a method for invoking a remote service according to the eighth embodiment of the present invention;
[0067] Figure 9 It is a schematic diagram of a visualization window for generating functional code according to a service contract file in a method for invoking a remote service according to the ninth embodiment of the present invention;
[0068] Figure 10 It is a schematic diagram of the main modules of an apparatus for invoking a remote service according to the tenth embodiment of the present invention;
[0069] Figure 11 It is an exemplary system architecture diagram to which the embodiments of the present invention can be applied;
[0070] Figure 12 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing the embodiments of the present invention. Detailed implementation manners
[0071] The following describes exemplary embodiments of the present invention with reference to the accompanying drawings. Various details of the embodiments of the present invention are included to facilitate understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following.
[0072] Figure 1 It is a schematic diagram of the main process of a method for invoking a remote service according to the first embodiment of the present invention, as Figure 1 shown, including:
[0073] Step S101, receive a first call request for a remote service, and obtain corresponding framework call code in response to the first call request;
[0074] Step S102, based on the first call request, generate a second call request for a proxy server by using the framework call code, so that the proxy server requests and obtains a remote service call result from a service framework system according to the second call request through the TCP protocol;
[0075] Step S103, receive the remote service call result returned by the proxy server to implement the invocation of the remote service.
[0076] The first call request is initiated by a calling user, which may include service information, such as the service name to be called, input parameter information, etc.; the calling user may be a front-end developer or a back-end developer; in some practical applications, before the client receives the first call request, an interceptor for preliminary interception may be set in the proxy tool control class to avoid the client receiving interference requests or incorrect requests; the client may be a scenario where the front-end initiates a call or a scenario where the back-end initiates a call, and the client may include: a background client, a mobile client, a PC client, etc.; the service framework system may be an open-source microservice framework, an in-enterprise service framework (such as Jingdong Service Framework, JSF), etc.
[0077] Through the method in this application, corresponding framework call code can be configured for the client, and then the framework call code is used to generate a call request for the remote service across languages through the TCP protocol during the call process, realizing cross-language and cross-platform communication decoupling between the server and the client, enabling the caller to achieve freedom in language development; and it can generate requests only through the TCP protocol during the call process, improving the overall call speed and enhancing the user experience.
[0078] Figure 2 It is a schematic diagram of the process of a method for invoking a remote service according to the second embodiment of the present invention, as Figure 2 shown, including:
[0079] Step S201, a developer inputs service information (the service information may be in the form of the above first call request, specifically including: the service name to be called, input parameter information, etc.), which is received by the proxy tool control class;
[0080] Step S202: After the proxy tool control class receives the service information, it sends it to the client;
[0081] Step S203: The client generates a second call request based on the received service information (the first call request) for requesting the proxy server;
[0082] Step S204: After the proxy server receives the second call request, it requests a remote service call from the service framework system;
[0083] Step S205: The service framework system returns the remote service call result to the proxy server;
[0084] Step S206: The proxy server returns the received remote service call result to the client;
[0085] Step S207: The client executes the called remote service based on the remote service call result and returns the execution result to the proxy tool control class;
[0086] Step S208: The proxy tool control class returns / display the execution result of the remote call success or failure to the developer.
[0087] In some embodiments, obtaining the corresponding framework call code in response to the first call request includes:
[0088] Parsing the first call request to determine the service identifier indicated by the first call request;
[0089] Obtaining the corresponding framework call code from a preset file storage system according to the service identifier; or, obtaining a service contract file from a preset file storage system according to the service identifier to generate a framework call code corresponding to the service identifier based on the service contract file.
[0090] Further, in some embodiments, the method for calling a remote service further includes: the language type of the framework call code is consistent with the language type of the first call request.
[0091] In some embodiments, after obtaining the corresponding framework call code, it further includes:
[0092] Implanting the framework call code into the client code.
[0093] The service identifier can be used to uniquely identify the remote service to be called; the corresponding relationship between the service name and the service identifier can be stored in advance, and then the service identifier can be determined according to the service name in the first call request. The preset file storage system can be a preset database for storing framework call codes or service contract files.
[0094] The framework call code in the file storage system can be code that is pre-generated according to the service contract file and applicable to various remote services and various languages. Furthermore, the corresponding framework call code can be determined based on the language type and service identifier of the first call request. Alternatively, when the first call request is received, the corresponding framework call code can be generated according to the service contract file in the file storage system. It can be flexibly set according to the actual situation;
[0095] After obtaining the corresponding framework call code, the code can be implanted into the original client code so that the corresponding functions of the framework call code are applied. For example, when using the web front-end to call the applet in the service framework system, the framework call code in JavaScript language can be generated using the service contract file and placed into the front-end JS code. In this way, when performing front-end page operations, the method corresponding to the newly implanted framework call code can be directly executed in the JS file to call the proxy server, instead of executing the method of remotely calling the service through the HTTP request gateway, thus meeting the cross-language service call requirements.
[0096] In some practical applications, the languages of the framework call code generated for the Android and IOS clients can be JAVA and Objective C respectively.
[0097] In some embodiments, parsing the first call request further includes: parsing the first call request to determine the input parameter information indicated by the first call request;
[0098] Moreover, generating a second call request for the proxy server based on the first call request using the framework call code includes: serially expressing the input parameter information using the framework call code; generating a second call request for the proxy server through the TCP protocol based on the result of the serial expression.
[0099] In some embodiments, enabling the proxy server to request and obtain the remote service call result from the service framework system through the TCP protocol based on the second call request includes: deserializing the result of the serial expression in the second call request using the proxy server; generating a third call request for the remote service in the service framework system through the TCP protocol using the proxy server based on the result of the deserialization expression; using the proxy server to receive the remote service call result returned by the service framework system in response to the third call request.
[0100] In some embodiments, before the proxy server requests and obtains the remote service call result from the service framework system according to the second call request through the TCP protocol, the following steps are further included: pre-configuring framework service code for the proxy server based on the service contract file; using the framework service code, generating SPI interface class data for the service consumer in the service framework system to call the service producer through Javaassist, and passing the SPI interface class data into the development toolkit of the service framework system; and,
[0101] Using the proxy server to generate a third call request for the remote service in the service framework system through the TCP protocol based on the result of the deserialized expression, including:
[0102] Using the proxy server to adapt the result of the deserialized expression to the SPI interface class data, determining the service interface data of the remote service, and then generating the third call request through the TCP protocol based on the service interface data.
[0103] Among them, the framework service code can be pre-configured, or can be obtained from a preset file storage system after the proxy server receives the second call request and then generated;
[0104] The third call request is a call request from the service consumer to the service producer in the service framework system (such as the JSF JD.com service framework).
[0105] Figure 3 It is a schematic diagram of the configuration of the proxy server cluster in a method for calling a remote service according to the third embodiment of the present invention, as Figure 3 shown:
[0106] Three host clusters can be configured. One cluster deploys the registry service, and developers can manually register interfaces; in the other two clusters, proxy server nodes can be deployed respectively and associated with the SDK (development toolkit) of the service framework system (such as the JSF JD.com service framework). When the proxy server node receives the first call request sent by the client, it can deserialize the interface information (input parameter information) and then request to obtain the service contract file, and at the same time generate the corresponding SPI interface class of the service through Javaassist, and then adapt the result of the deserialized interface information to the input parameters of the SPI interface class to call the SDK in the service framework system to generate the above-mentioned third call request.
[0107] Figure 4 It is a schematic diagram of the communication between the client and the proxy server in a method for calling a remote service according to the fourth embodiment of the present invention, as Figure 4 shown:
[0108] In this application, cross - language client communication is mainly based on the service interfaces of the service framework system and the languages of the clients. Framework call codes in corresponding languages are generated for the clients, and framework service codes in corresponding languages are configured for the proxy servers.
[0109] The framework call codes of the clients can provide two functions: communication and encoding / decoding. Among them, the communication function can be implemented using Netty, and the encoding / decoding function can be used for data serialization between different languages. The remaining part can be the business logic codes of the clients.
[0110] On the proxy server side, framework service codes are generated according to the interface contract file. Then, using the framework service codes, SPI interface class data for service consumers in the service framework system to call service producers is generated through Javaassist. The SPI interface class data is passed into the development toolkit of the service framework system, and the client requests are deserialized through encoding / decoding and passed into the development toolkit of the service framework system. The service producers in the service framework system are requested through the development toolkit to obtain the corresponding remote service call results.
[0111] Figure 5 It is a framework schematic diagram of a method for calling a remote service according to the fifth embodiment of the present invention. As Figure 5 shown, it includes:
[0112] The proxy server can be registered in the registration center first.
[0113] When the background client / mobile client / PC client receives a call request, a second call request for the proxy server is generated using the framework call codes.
[0114] After receiving the second call request, the proxy server obtains the service contract file from JFS (Jingdong File System, a distributed storage system) to generate framework service codes, and deserializes the information in the second call request using the framework service codes. Then, a third call request for calling the remote service in the service framework system (JSF) is generated to achieve remote call.
[0115] Figure 6 It is a framework schematic diagram of a method for calling a remote service according to the sixth embodiment of the present invention. As Figure 6 shown, it includes:
[0116] When the client receives the first call request, it can parse and obtain that the service name to be called is "Service 2", and some input parameter information "IP + port".
[0117] Registry addressing can be performed through the input parameter information "IP + port" to find the corresponding proxy server, and then the proxy server is used to request and obtain the call result of the remote service "Service 2" from the service framework system (JSF).
[0118] Figure 7 FIG. is a schematic diagram of a visual window for configuring a proxy server in a method for calling a remote service according to the seventh embodiment of the present invention, as Figure 7 shown:
[0119] The operation and maintenance personnel of the proxy server can create a configuration file in the project. They can select the "Generate" function by right-clicking, select the TCP protocol, enter the IP address and port number, generate the configuration file code, and then select "Deploy" by right-clicking to complete the deployment of the registry and the proxy server node.
[0120] Figure 8 FIG. is a schematic diagram of a visual window for monitoring the proxy server in a method for calling a remote service according to the eighth embodiment of the present invention, as Figure 8 shown:
[0121] Through the proxy server monitoring interface, the deployment status of the deployed registry, server node, and consumer service in the service framework system (such as JSF) can be viewed, and the server node can also be right-clicked to start or pause the service.
[0122] Figure 9 FIG. is a schematic diagram of a visual window for generating function code according to a service contract file in a method for calling a remote service according to the ninth embodiment of the present invention, as Figure 9 shown:
[0123] The service contract file can be defined according to the service framework system interface information. Then, according to the service contract file, the language, the IP address and port number of the proxy server are selected to generate the framework call code of the client in different languages locally. After generation, the service contract file can be sent to JFS for storage. Finally, the framework call code can be placed inside the front-end and back-end projects in the corresponding language environment to be called.
[0124] Figure 10 FIG. is a schematic diagram of the main modules of a device for calling a remote service according to the tenth embodiment of the present invention, as Figure 10 shown. The device 1000 for calling a remote service includes:
[0125] A receiving module 1001, configured to receive a first call request for a remote service and obtain a corresponding framework call code in response to the first call request;
[0126] A calling module 1002, configured to generate a second calling request for a proxy server based on the first calling request by using the framework calling code, so that the proxy server requests and obtains a remote service call result from the service framework system according to the second calling request through the TCP protocol;
[0127] An execution module 1003, configured to receive the remote service call result returned by the proxy server to implement the call of the remote service.
[0128] The first calling request is initiated by a caller, which may include service information such as the name of the service to be called, input parameter information, etc.; the caller may be a front-end developer or a back-end developer; in some practical applications, before the client receives the first calling request, an interceptor for preliminary interception may be set in the proxy tool control class to prevent the client from receiving interfering requests or incorrect requests; the client may be a scenario where the front-end initiates a call or a scenario where the back-end initiates a call, and the client may include: a background client, a mobile client, a PC client, etc.
[0129] Through the method in this application, corresponding framework calling code can be configured for the client, and then the framework calling code can be used to generate a calling request for a remote service across languages through the TCP protocol during the calling process, realizing cross-language and cross-platform communication decoupling between the server and the client, enabling the caller to achieve language development freedom; and it can generate requests only through the TCP protocol during the calling process, improving the overall calling speed and enhancing the user experience.
[0130] In some embodiments, the receiving module obtains the corresponding framework calling code in response to the first calling request, including:
[0131] Analyze the first calling request to determine the service identifier indicated by the first calling request;
[0132] Obtain the corresponding framework calling code from a preset file storage system according to the service identifier; or obtain a service contract file from the preset file storage system according to the service identifier, and generate the framework calling code corresponding to the service identifier based on the service contract file.
[0133] Further, in some embodiments, the language type of the framework calling code is the same as the language type of the first calling request.
[0134] In some embodiments, after the receiving module obtains the corresponding framework calling code, it further includes:
[0135] Embed the framework calling code into the client code.
[0136] The service identifier can be used to uniquely identify the remote service to be invoked; the corresponding relationship between the service name and the service identifier can be pre-stored, and then the service identifier can be determined according to the service name in the first invocation request. The preset file storage system can be a preset database for storing framework invocation code or service contract files.
[0137] The framework invocation code in the file storage system can be code that is pre-generated according to the service contract file and applicable to various remote services and various languages. Then, the corresponding framework invocation code can be determined according to the language type of the first invocation request and the service identifier; alternatively, the corresponding framework invocation code can also be generated according to the service contract file in the file storage system after receiving the first invocation request; it can be flexibly set according to the actual situation;
[0138] After obtaining the corresponding framework invocation code, the code can be implanted into the original client code so that the corresponding functions of the framework invocation code are applied; for example: when using a web front-end to invoke a mini-program in the service framework system, the framework invocation code in JavaScript language can be generated using the service contract file and placed into the front-end JS code. In this way, when performing front-end page operations, the methods corresponding to the newly implanted framework invocation code can be directly executed in the JS file to call the proxy server, instead of executing the method of remotely invoking the service through the HTTP request gateway, thus meeting the cross-language service invocation requirements.
[0139] In some practical applications, the languages of the framework invocation code generated for the clients of Android and IOS can be JAVA and Objective C respectively.
[0140] In some embodiments, the receiving module parsing the first invocation request further includes: parsing the first invocation request to determine the input parameter information indicated by the first invocation request;
[0141] And, the invocation module generating a second invocation request for the proxy server based on the first invocation request using the framework invocation code includes:
[0142] Serializing and expressing the input parameter information using the framework invocation code; generating a second invocation request for the proxy server through the TCP protocol based on the serialization expression result.
[0143] In some embodiments, the invocation module causes the proxy server to request and obtain the remote service invocation result from the service framework system through the TCP protocol according to the second invocation request, including:
[0144] Deserializing and expressing the serialization expression result in the second invocation request using the proxy server;
[0145] The proxy server generates a third call request for the remote service in the service framework system through the TCP protocol based on the result of deserialized expression;
[0146] The proxy server receives the remote service call result returned by the service framework system in response to the third call request.
[0147] In some embodiments, before the calling module enables the proxy server to request and obtain the remote service call result from the service framework system through the TCP protocol according to the second call request, it further includes:
[0148] Pre-configuring framework service code for the proxy server based on the service contract file in advance;
[0149] Using the framework service code, generating SPI interface class data for a service consumer in the service framework system to call a service producer through Javaassist, and passing the SPI interface class data into the development toolkit of the service framework system; and,
[0150] The proxy server generates a third call request for the remote service in the service framework system through the TCP protocol based on the result of deserialized expression, including:
[0151] The proxy server adapts the result of deserialized expression to the SPI interface class data, determines the service interface data of the remote service, and then generates the third call request through the TCP protocol based on the service interface data.
[0152] Among them, the framework service code can be pre-configured or can be obtained from a preset file storage system to generate a service contract file after the proxy server receives the second call request;
[0153] The third call request is a call request from a service consumer to a service producer in a service framework system (such as the JSF JD.com service framework).
[0154] Figure 11 Exemplary system architecture 1100 is shown for a method of calling a remote service or an apparatus for calling a remote service to which embodiments of the present invention can be applied.
[0155] Such as Figure 11As shown, the system architecture 1100 may include terminal devices 1101, 1102, 1103, a network 1104, and a server 1105. The network 1104 is used to provide a medium for communication links between the terminal devices 1101, 1102, 1103 and the server 1105. The network 1104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.
[0156] Users can use the terminal devices 1101, 1102, 1103 to interact with the server 1105 via the network 1104 to receive or send messages, etc. Various applications with remote call requirements may be installed on the terminal devices 1101, 1102, 1103.
[0157] The terminal devices 1101, 1102, 1103 may be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers, etc.
[0158] The server 1105 may be a server providing various services, such as a management server that supports the remote call requirements of users using the terminal devices 1101, 1102, 1103. The management server can process the received call requests and feedback the processing results (such as the call results of the services) to the terminal devices.
[0159] It should be noted that the method for calling remote services provided by the embodiments of the present invention is generally executed by the server 1105. Correspondingly, the device for calling remote services is generally set in the server 1105.
[0160] It should be understood that Figure 11 the numbers of terminal devices, networks, and servers in
[0161] are merely illustrative. According to the implementation requirements, there may be any number of terminal devices, networks, and servers. Figure 12 is a schematic structural diagram of a computer system 1200 of a terminal device suitable for implementing the embodiments of the present invention. Figure 12 The terminal device shown is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present invention.
[0162] As Figure 12As shown, the computer system 1200 includes a central processing unit (CPU) 1201, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1202 or a program loaded from a storage section 1208 into a random access memory (RAM) 1203. In the RAM 1203, various programs and data required for the operation of the system 1200 are also stored. The CPU 1201, the ROM 1202, and the RAM 1203 are connected to each other via a bus 1204. An input / output (I / O) interface 1205 is also connected to the bus 1204.
[0163] The following components are connected to the I / O interface 1205: an input section 1206 including a keyboard, a mouse, etc.; an output section 1207 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 1208 including a hard disk, etc.; and a communication section 1209 including a network interface card such as a LAN card, a modem, etc. The communication section 1209 performs communication processing via a network such as the Internet. A drive 1210 is also connected to the I / O interface 1205 as needed. A removable medium 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 1210 as needed so that a computer program read from it can be installed into the storage section 1208 as needed.
[0164] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1209, and / or installed from the removable medium 1211. When the computer program is executed by the central processing unit (CPU) 1201, the above functions defined in the system of the present invention are executed.
[0165] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, and the computer-readable program code is carried therein. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and this computer-readable medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0166] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the above module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, as well as the combination of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0167] The modules involved in the embodiments of the present invention can be implemented in software or in hardware. The described modules can also be provided in a processor. For example, it can be described as: a processor includes a receiving module, a calling module, and an executing module. Among them, the names of these modules do not constitute a limitation to the module itself in some cases.
[0168] As another aspect, the present invention also provides a computer-readable medium. The computer-readable medium can be included in the device described in the above embodiments; or it can exist alone without being assembled into the device. The above computer-readable medium carries one or more programs. When the one or more programs are executed by the device, the device includes: step S101, receiving a first call request for a remote service, and obtaining a corresponding framework call code in response to the first call request; step S102, generating a second call request for a proxy server based on the first call request by using the framework call code, so that the proxy server requests and obtains a remote service call result from a service framework system according to the second call request through the TCP protocol; step S103, receiving the remote service call result returned by the proxy server to implement the call of the remote service.
[0169] According to the technical solution of the embodiments of the present invention, by configuring corresponding function codes for the client and the server, and then using the function codes to generate call requests across languages through the TCP protocol during the call process, the technical problem of slow speed caused by the need to perform remote service calls through an HTTP request gateway in the prior art due to the inability to meet the cross-platform and cross-language remote call requirements is overcome. Furthermore, cross-language and cross-platform communication decoupling between the server and the client is achieved, enabling the caller to develop freely in different languages, and being able to generate requests only through the TCP protocol during the call process, achieving the technical effects of improving the overall call speed and enhancing the user experience.
[0170] The above specific embodiments do not limit the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for invoking a remote service, characterized in that, Including: Receiving a first call request for a remote service, and obtaining corresponding framework call code in response to the first call request; wherein, the framework call code is set on the client side, the framework call code provides encoding and decoding functions, and the encoding and decoding functions are used to implement serialization of data between different languages; the framework call code is code that is pre-generated according to a service contract file and is applicable to various remote services and various languages, and then the corresponding framework call code is determined according to the language type and service identifier of the first call request; Based on the first call request, generating a second call request for a proxy server by using the framework call code, so that the proxy server requests and obtains a remote service call result from a service framework system according to the second call request through the TCP protocol; Wherein, the second call request is generated through the TCP protocol based on a serialized expression result; the serialized expression result is generated by using the framework call code to perform serialization expression on the input parameter information indicated by the first call request; the proxy server is provided with framework service code, and the framework service code is used to generate SPI interface class data for a service consumer to call a service producer in the service framework system through Javaassist, and pass the SPI interface class data into a development toolkit of the service framework system; the proxy server is used to adapt the deserialized expression result to the SPI interface class data, determine service interface data of the remote service, and then generate a third call request through the TCP protocol based on the service interface data; the deserialized expression result is generated by using the proxy server to perform deserialization expression on the serialized expression result in the second call request; Receiving the remote service call result returned by the proxy server to implement the call of the remote service; wherein, the remote service call result is returned by the service framework system in response to the third call request.
2. The method according to claim 1, wherein Receiving the corresponding framework call code in response to the first call request includes: Parsing the first call request to determine the service identifier indicated by the first call request; Obtaining the corresponding framework call code from a preset file storage system according to the service identifier; or obtaining a service contract file from a preset file storage system according to the service identifier to generate the framework call code corresponding to the service identifier based on the service contract file.
3. The method according to claim 1, wherein Also including: The language type of the framework call code is the same as the language type of the first call request.
4. The method according to claim 1, characterized in that, After obtaining the corresponding framework call code, it also includes: Implanting the framework call code into the client code.
5. The method according to claim 2, wherein The parsing of the first call request further includes: parsing the first call request to determine the input parameter information indicated by the first call request; And, the generating of the second call request for the proxy server by using the framework call code based on the first call request includes: Use the framework call code to serialize the input parameter information; generate a second call request to the proxy server based on the serialization result through the TCP protocol.
6. The method according to claim 5, wherein Cause the proxy server to request and obtain a remote service call result from the service framework system according to the second call request through the TCP protocol, including: Use the proxy server to deserialize the serialization result in the second call request; Use the proxy server to generate a third call request to the remote service in the service framework system based on the deserialization result through the TCP protocol; Use the proxy server to receive the remote service call result returned by the service framework system in response to the third call request.
7. The method according to claim 6, wherein Before causing the proxy server to request and obtain a remote service call result from the service framework system according to the second call request through the TCP protocol, it further includes: Pre-configure the framework service code for the proxy server based on the service contract file.
8. An apparatus for invoking a remote service, characterized in that, Include: A receiving module, configured to receive a first call request for a remote service, and obtain a corresponding framework call code in response to the first call request; wherein, the framework call code is set on the client, the framework call code provides encoding and decoding functions, and the encoding and decoding functions are used to implement serialization of data between different languages; the framework call code is code pre-generated according to the service contract file and applicable to each remote service and various languages, and then the corresponding framework call code is determined according to the language type and service identifier of the first call request; A calling module, configured to generate a second call request to the proxy server based on the first call request by using the framework call code, so that the proxy server requests and obtains a remote service call result from the service framework system according to the second call request through the TCP protocol; Wherein, the second call request is generated through the TCP protocol based on the serialization result; the serialization result is generated by using the framework call code to serialize the input parameter information indicated by the first call request; the proxy server is provided with a framework service code, and the framework service code is used to generate SPI interface class data for a service consumer to call a service producer in the service framework system through Javaassist, and transmit the SPI interface class data into the development toolkit of the service framework system; the proxy server is used to adapt the deserialization result to the SPI interface class data to determine the service interface data of the remote service, and then generate a third call request based on the service interface data through the TCP protocol; the deserialization result is generated by using the proxy server to deserialize the serialization result in the second call request; An execution module, configured to receive the remote service call result returned by the proxy server to implement the call of the remote service; wherein, the remote service call result is returned by the service framework system in response to the third call request.
9. An electronic device for invoking a remote service, characterized in that, Include: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1-7.
10. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, the method according to any one of claims 1-7 is implemented.
Citation Information
Patent Citations
Distributed objects oriented communication system andmethod for common service various protocolby usedcorba proxy module therefor
KR1020010093465A