Remote calling method and system based on RMI component

By using remote call methods based on RMI components in the microservice architecture, defining declarative interfaces and RMI annotations, dynamically generating proxy classes for interface calls, solving the problem of low communication efficiency between microservices and improving development efficiency and system maintainability.

CN120050327APending Publication Date: 2025-05-27金现代信息产业股份有限公司
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510234437.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-28
Publication Date
2025-05-27

AI Technical Summary

Technical Problem

In microservice architecture, communication and call efficiency between services is low, resulting in large development workload and low efficiency, affecting the promotion and development of the architecture.

Method used

Using the remote calling method based on RMI components, by defining declarative interfaces and RMI annotations, the RMI component automatically processes details and dynamically generates proxy classes for interface calls.

Benefits of technology

This greatly reduces the development workload, improves development efficiency, realizes transparency of service calls, and enhances the maintainability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120050327A_ABST
    Figure CN120050327A_ABST
Patent Text Reader

Abstract

The invention provides a remote calling method and system based on an RM I component, and relates to the technical field of micro-services, and the specific scheme comprises the following steps: obtaining service information to be remotely called; carrying out request sending and response processing on the service through the RMI component based on the service information; wherein the RMI component defines a declarative interface for each remote service, configures service information in the declarative interface by using RMI annotation, dynamically generates an agent class of an actual execution request and response for the declarative interface by means of a dynamic agent, and performs unified interface calling by using an agent object generated for the agent class; by means of the RMI component, only the declarative interface and the RMI annotation need to be defined, and the RMI component can automatically process the details, so that the development workload is greatly reduced, and the development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of microservices, and particularly relates to a remote call method and system based on RMI components. Background Art

[0002] The statements in this part only provide background technical information related to the present invention and do not necessarily constitute prior art.

[0003] In today's software development field, the microservice architecture has become a common architecture pattern; in the microservice architecture, communication and calls between services become crucial. In traditional service - to - service communication and calls, a series of cumbersome tasks such as manually writing HTTP requests, parameter serialization, and response parsing are required, resulting in low efficiency of service - to - service communication and calls, which affects the popularization and development of the microservice architecture. Summary of the Invention

[0004] To overcome the deficiencies of the above - mentioned prior art, the present invention provides a remote call method and system based on RMI components. With the help of RMI components, only declarative interfaces and RMI annotations need to be defined, and the RMI components will automatically handle these details, greatly reducing the development workload and improving the development efficiency.

[0005] To achieve the above object, one or more embodiments of the present invention provide the following technical solutions:

[0006] The first aspect of the present invention provides a remote call method based on RMI components.

[0007] A remote call method based on RMI components includes:

[0008] Obtain service information to be remotely called;

[0009] Based on the service information, send requests and process responses for the service through RMI components;

[0010] Among them, the RMI components define declarative interfaces for each remote service, configure service information in the declarative interfaces using RMI annotations, and with the help of dynamic proxies, dynamically generate proxy classes that actually execute requests and responses for the declarative interfaces. Use the proxy objects generated for the proxy classes for unified interface calls.

[0011] Further, the service information includes a request address, a request method, request headers, and request parameters;

[0012] The format of the request address is: hostname / domain name / IP address + port number;

[0013] The request methods include @Post, @Get, @Put, @Delete.

[0014] Furthermore, the declarative interface is a standard interface that defines sending and receiving HTTP requests, including request methods, request addresses, request modes, request headers, request parameters, and specifies specifications for communicating with the server.

[0015] Furthermore, the RMI annotation is used to define information of HTTP sending request, which is defined on the interface and its method.

[0016] Furthermore, the dynamic proxy creates a new class without knowing the specific type in advance and dispatches method calls to the underlying program.

[0017] Further, it also includes: controlling the communication security mechanism through interceptors and filters;

[0018] The interceptor intercepts and processes requests before they are sent or responses before they are returned to the client; the filter performs real-time filtering and detection of network data through http remote calls.

[0019] Furthermore, it also includes: providing a programming interface, defining an RMIAPI object, and creating an RMIRuqest object through the RMIAPI object to perform remote calling of services.

[0020] A second aspect of the present invention provides a remote calling system based on RMI components.

[0021] A remote calling system based on RMI components, including an information acquisition module and a service calling module:

[0022] The information acquisition module is configured to: acquire service information to be remotely called;

[0023] The service calling module is configured to: send a request and process a response to the service through the RMI component based on the service information;

[0024] Among them, the RMI component defines a declarative interface for each remote service, uses RMI annotations to configure service information in the declarative interface, uses dynamic proxies to dynamically generate proxy classes for the declarative interface that actually execute requests and responses, and uses the proxy objects generated for the proxy classes to perform unified interface calls.

[0025] The third aspect of the present invention provides a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements the steps of a remote calling method based on an RMI component as described in the first aspect of the present invention.

[0026] A fourth aspect of the present invention provides an electronic device, including a memory, a processor, and a program stored on the memory and executable on the processor. When the processor executes the program, the steps in a remote call method based on an RMI component as described in the first aspect of the present invention are implemented.

[0027] The above one or more technical solutions have the following beneficial effects:

[0028] In the context where service calls between services in a microservices architecture become more frequent and complex, in order to achieve the transparency of service calls, improve development efficiency and system maintainability, the present invention provides a remote call RMI component based on spring. As a declarative and templated HTTP client, it provides a simple and powerful service call solution for enterprises. This component greatly simplifies the code for calling services through means such as RMI unified configuration, RMI annotation, declaring http interfaces, dynamic proxy, template expressions, data conversion, etc., improving the readability and maintainability of the code; through data conversion, interceptors, and filters, it supports customizing requests and responses and implementing specific requirements. The customization ability provides more flexibility and scalability for the customized business scenarios of enterprises, helps enterprises achieve the transparency of service calls, improves development efficiency and system maintainability, and is an indispensable important part in a microservices architecture or a distributed architecture.

[0029] The advantages of the additional aspects of the present invention will be partially given in the following description, partially become obvious from the following description, or be understood through the practice of the present invention. Description of the Drawings

[0030] The specification drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention.

[0031] Figure 1 It is a diagram of the implementation manner of the RMI component for the first embodiment.

[0032] Figure 2 It is a structural diagram of the RMI component for the second embodiment. Detailed Embodiments

[0033] It should be noted that the following detailed descriptions are all illustrative and are intended to provide further explanations for the present application. Unless otherwise specified, all technical and scientific terms used in the present invention have the same meanings as those commonly understood by those of ordinary skill in the technical field to which the present application belongs.

[0034] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0035] Terminology explanation:

[0036] RMI Annotation:

[0037] It is used to define all relevant information of HTTP request, which is generally defined on the interface and its method. To implement third-party interface call, RMI only needs to declare the interface and configure the information of the third-party interface through RMI specific annotations.

[0038] HTTP request interface:

[0039] A standard interface that defines sending and receiving HTTP requests. It includes information such as the request method, request header, request body, and specifies the specifications for communicating with the server. By implementing the HTTP request interface, you can send various types of HTTP requests such as GET and POST, and obtain data returned by the server. The actual process of sending the request is usually completed by a dynamic proxy class.

[0040] Dynamic Proxy:

[0041] A mechanism for creating proxy objects at runtime. It can create new classes without knowing the specific type in advance, and can dispatch method calls to the underlying program. In HTTP requests, dynamic proxies can be used to dynamically generate proxy classes that actually execute requests, thereby implementing the process of sending requests.

[0042] Template expressions:

[0043] Template expressions can be used to construct request parameters, request header information, and request body content, as well as to process returned data. Template expressions can dynamically bind data passed in by users through parameters or global variables to HTTP request information.

[0044] Data conversion:

[0045] A universal means of data exchange that provides a flexible way for data conversion. Through HTTP remote calls, data can be extracted from one system, and after specific conversion processing, it can be loaded into the target system to achieve cross-system data transmission and conversion.

[0046] Interceptor:

[0047] It can be intercepted and processed before the request is sent to the server or before the response is returned to the client. Interceptors specify various links in the life cycle of one or a batch of requests, such as the start, successful return of data, failure, completion, etc., to insert custom logic for processing.

[0048] Filter:

[0049] A commonly used network security tool that can achieve real-time filtering and detection of network data through HTTP remote calls, improve the level of network security protection, and ensure the security and integrity of network data.

[0050] Spring extension points:

[0051] The Spring framework provides rich extension points. Through these extension points, customized operations can be carried out during the initialization of the Spring container and the management of Beans, to achieve more flexible and powerful functions.

[0052] FactoryBean:

[0053] FactoryBean is a factory Bean interface in the Spring framework for defining custom Beans. By implementing this interface, developers can customize some complex Bean creation logics and achieve some special Bean creation and management methods. Through FactoryBean, we can encapsulate complex Bean creation logics into a factory Bean to achieve more flexible Bean management and creation.

[0054] Interceptor chain design pattern:

[0055] It is usually used to implement various interception, preprocessing, and postprocessing logics in an application. This design pattern allows you to insert and combine interceptors at different stages of processing requests to achieve various functions, such as authentication, authorization, logging, performance monitoring, etc.

[0056] Example 1

[0057] In an embodiment of the present disclosure, a remote call method based on RMI components is provided, including the following steps:

[0058] Step S1: Obtain service information to be remotely called;

[0059] Furthermore, the service information includes a request address, a request method, a request header, and request parameters;

[0060] The format of the request address is: hostname / domain name / IP address + port number;

[0061] The request methods include @Post, @Get, @Put, and @Delete.

[0062] Step S2: Based on the service information, the service request is sent and the response is processed through the RMI component;

[0063] Among them, the RMI component defines a declarative interface for each remote service, uses RMI annotations to configure service information in the declarative interface, uses dynamic proxies to dynamically generate proxy classes for the declarative interface that actually execute requests and responses, and uses the proxy objects generated for the proxy classes to perform unified interface calls.

[0064] Furthermore, the declarative interface is a standard interface that defines sending and receiving HTTP requests, including request methods, request addresses, request modes, request headers, request parameters, and specifies specifications for communicating with the server.

[0065] Furthermore, the RMI annotation is used to define information of HTTP sending request, which is defined on the interface and its method.

[0066] Furthermore, the dynamic proxy creates a new class without knowing the specific type in advance and dispatches method calls to the underlying program.

[0067] Further, it also includes: controlling the communication security mechanism through interceptors and filters;

[0068] The interceptor intercepts and processes requests before they are sent or responses before they are returned to the client; the filter performs real-time filtering and detection of network data through http remote calls.

[0069] Furthermore, it also includes: providing a programming interface, defining an RMIAPI object, and creating an RMIRuqest object through the RMIAPI object to perform remote calling of services.

[0070] The following is a detailed description of the implementation process of a remote calling method based on the RMI component in this embodiment.

[0071] This embodiment provides a spring-based remote call RMI component, which is a technology for remote communication and remote object calling. It is very important for building distributed systems and distributed computing environments. It can help developers develop and deploy distributed applications, improve the scalability and performance of the system, and help developers simplify the code for remote service calls and improve development efficiency. It also provides rich configuration options and support to meet various complex business needs.

[0072] The Spring-based remote call RMI component is a declarative and templated HTTP client. As a solution, it provides an efficient, reliable, and secure remote communication mechanism and needs to solve the following technical problems:

[0073] (1) Dynamically proxy and declare the HTTP interface

[0074] (2) Mask the complexity of remote calls

[0075] (3) Communication security mechanism

[0076] (4) Data conversion and transmission

[0077] (5) Scalability and flexibility

[0078] To this end, as Figure 1 shown, the Spring-based remote call RMI component of this embodiment mainly defines the creation logic of the http interface bean through the FactoryBean method of the Spring extension point, realizes the creation and management method of the HTTP interface bean. Through FactoryBean, the complex bean creation logic is encapsulated in a factory bean to realize flexible bean management and creation.

[0079] Solve the problem of injecting the dynamically implemented class of the interface into the Spring container through the interface dynamic proxy method. It mainly creates a proxy object through the JDK dynamic ProxyFactory. The java.lang.reflect.Proxy and java.lang.reflect.InvocationHandler interfaces in the Java standard library can help create dynamic proxies; ProxyFactory may refer to the factory class that uses the dynamic proxy mechanism provided by the Java standard library to create proxy objects; provide a programmatic way to define the interface call logic, make a programmatic interface call through the RMI API, create a RMIRuqest object through the generated final RMI API object to request a third-party interface; the declarative interface is actually a RMIRequest object generated through the FactoryBean method. Both the programmatic interface and the declarative interface finally generate this object for unified interface calls. There is a RMIConfiguration object in RMIRequest, and this object includes security mechanism processing, life cycle functions, interceptor chains, interception executors, log processing, HttpBackend (okhttp3 and httpClient), global filter interceptor chains, etc.

[0080] The method in the embodiment will be described in detail from the following four aspects: shielding the complexity of remote calls, communication security mechanism, scalability and flexibility, and easy extensibility.

[0081] I. Shielding the complexity of remote calls

[0082] It is mainly implemented through annotations, configuration files, configuration classes, data conversion methods, and unified invocation of the RMIRequest request method.

[0083] Annotations are mainly applied to define third-party interface information in the form of declarative interfaces. For example, annotations such as @Post, @Get, @Put, @Delete, @header, @adress, etc. respectively correspond to the configuration information of third-party interfaces.

[0084] The configuration file is mainly used for global configuration, such as the background request method, which currently supports okhttp3 and httpclient; global data converters, global request timeout, global connection timeout, global read timeout, setting the maximum number of asynchronous request threads globally, setting the maximum size of the asynchronous request thread pool queue globally, setting the maximum number of request connections globally, the character set of request data globally, the maximum number of request failure retries globally, the global default address (hostname / domain name / IP address + port number), whether to allow printing request / response logs, ssl configuration, etc.

[0085] The configuration class is mainly used to fill the configuration information of the configuration file into the configuration class, and perform personalized configuration for different interface calls. RMIRequest can correspond to different configuration classes to achieve customized use of configuration information for different requests.

[0086] The conversion of request parameters and request return data includes character set, serialization / deserialization, and data type conversion, and different data conversions are set through annotations or programmatic interfaces.

[0087] Regardless of declarative interfaces or programmatic interfaces, they are uniformly converted into RMIRequest objects for unified invocation of third-party interfaces. This class performs processing such as invocation, interceptors, filters, asynchronous / synchronous calls, interface call lifecycle processing, data conversion, ssl processing, exception retry, parameter variable acquisition, and background request method invocation (httpclient or okhttp3).

[0088] II. Communication security mechanism

[0089] The RMI component mainly controls the communication security mechanism through interceptors and filters. The filter processes the interceptor when releasing the remote call method. By providing custom filters and customizing different filters, finally, the default filter and the custom filter are generated into a filter chain, which is executed when the method is executed. Any filter will terminate the execution of the method.

[0090] The default filters are character encoding filter, json filter, and xml filter; the interceptors mainly define interface lifecycle interceptors, such as interfaces like BaseInterceptor, MethodInterceptorLifeCycle, ParamterInterceptorLifeCycle, ResultInterceptorLifeCycle, etc. Each lifecycle defines various callback methods, such as interface method execution callback, pre-request execution callback, post-request completion callback, callback before sending request data after request data serialization, callback after request success, callback after request failure, callback when triggering request retry, callback when listening to the transmission progress of default file upload or download, callback when sending a request to load cookies, callback when saving cookies after a successful request response, etc. Various lifecycle stage callbacks intercept interface calls during the execution of the interface.

[0091] The security mechanism can also be controlled through interception. For example, security controls such as parameter verification, ssl authentication, interface authentication, encryption and decryption processing of parameters and their return values, data desensitization, data adaptation, and request protocol adaptation are implemented through different lifecycle callbacks; data conversion and transmission mainly include data serialization and deserialization, data encryption and decryption, and data adaptation, etc., which are mainly implemented through the interceptor chain and are implemented through callbacks in ParamterInterceptorLifeCycle, supporting custom methods.

[0092] III. Extensibility and Flexibility

[0093] The flexibility of the RMI component is mainly reflected in aspects such as simple usage method, providing multiple implementation methods, and being easy to expand; the usage method is simple. By defining an interface, third-party interface calls can be implemented. The component shields the implementation details of backend request methods, authentication logic, security, etc. As long as simple configuration is performed, the configuration can be globally configured or customized for different interfaces. Providing multiple implementation methods, one is through the interface declaration paradigm, and the other is through the programmatic interface. Both methods generate a unified RMIRequest object to implement the implementation details of interface calls. rmiRuqest defines communication security, lifecycle extension, filters, backend request methods, etc.

[0094] IV. Easy to expand

[0095] It embodies aspects such as custom annotations, custom filters, custom lifecycle callbacks, custom data conversion, and configuration customization.

[0096] Custom annotations are applied to declarative interfaces to extend the scalability of the declarative interface method through custom annotations. For example, defining an annotation to extend the acquisition of the request address, which can be obtained from a database or other storage media. The custom annotation implements the logic of data conversion, so that different data conversion operations can be performed using different annotations in the interface declaration; custom filters. This method can customize different filters according to the customization requirements of different enterprises. For example, for equal protection requirements, encryption and decryption of data transmission, data desensitization, etc. can also be achieved through the way of lifecycle callbacks. The only difference between the two is the execution timing issue.

[0097] Based on the above description, a specific structure of an RMI component is provided, as Figure 2 shown:

[0098] Interface layer: The interfaces used by users, including declarative interfaces, which are created through the programmatic RMIRequest.

[0099] Dynamic proxy processor: The interface generates an interface proxy implementation class through dynamic proxy. The generated proxy class is the interface implementation class.

[0100] SpringContext container: Spring injects the bean (proxy bean) into the springcontext container through dependency injection. The class dynamically proxied by the interface is injected into the springcontext using the factorybean in spring.

[0101] Executor: The executor for remote calls, including the RMIRequest object, mainly creates the request. The configuration information of the request declared in the interface is parsed through the configuration parser. And it is intercepted through the filter chain in the executor to provide the lifecycle interface for the rmi interface call. Security mechanisms such as interface authentication, retry, and exception handling are implemented through the interceptor chain. Parameter processing: It mainly processes the input and output parameters of the RMI interface and can also handle functions such as file upload and download.

[0102] Background request executor: It mainly processes the completed RMI request and sends a request to the target server through the background request executor (okhttp, httpclient) and waits for the response.

[0103] Example 2

[0104] In one embodiment of the present disclosure, a remote call system based on RMI components is provided, including an information acquisition module and a service call module:

[0105] The information acquisition module is configured to: acquire service information to be remotely called;

[0106] The service call module is configured to: based on the service information, send requests for the service and process responses through RMI components;

[0107] Among them, the RMI component defines a declarative interface for each remote service, configures service information in the declarative interface using RMI annotations, dynamically generates a proxy class for actually executing requests and responses for the declarative interface with the help of dynamic proxies, and uses the proxy object generated for the proxy class to perform unified interface calls.

[0108] Embodiment Three

[0109] The purpose of this embodiment is to provide a computer-readable storage medium.

[0110] A computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the steps in a remote call method based on RMI components as described in Embodiment One of the present disclosure.

[0111] Embodiment Four

[0112] The purpose of this embodiment is to provide an electronic device.

[0113] An electronic device, including a memory, a processor, and a program stored on the memory and executable on the processor, and when the processor executes the program, it implements the steps in a remote call method based on RMI components as described in Embodiment One of the present disclosure.

[0114] The above are only the preferred embodiments of the present invention and are not used to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A remote calling method based on RMI component, characterized in that: include: Get the service information to be called remotely; Based on the service information, the RMI component is used to send service requests and process responses. Among them, the RMI component defines a declarative interface for each remote service, uses RMI annotations to configure service information in the declarative interface, uses dynamic proxies to dynamically generate proxy classes for the declarative interface that actually execute requests and responses, and uses the proxy objects generated for the proxy classes to perform unified interface calls.

2. A remote calling method based on RMI components as claimed in claim 1, characterized in that: The service information includes request address, request method, request header, and request parameters; The format of the request address is: host name / domain name / IP address+port number; The request methods include @Post, @Get, @Put, and @Delete.

3. A remote calling method based on RMI components as claimed in claim 1, characterized in that: The declarative interface is a standard interface that defines sending and receiving HTTP requests, including request methods, request addresses, request modes, request headers, request parameters, and specifies specifications for communicating with the server.

4. A remote calling method based on RMI component as claimed in claim 1, characterized in that: The RMI annotation is used to define the information of HTTP sending request and is defined on the interface and its method.

5. A remote calling method based on RMI component as claimed in claim 1, characterized in that: The dynamic proxy is a program that creates a new class without knowing the specific type in advance and dispatches method calls to the underlying program.

6. A remote calling method based on RMI component as claimed in claim 1, characterized in that: Also includes: Control of communication security mechanisms through interceptors and filters; Wherein, the interceptor intercepts and processes before the request is sent or before the response is returned to the client; The filter performs real-time filtering and detection on network data through http remote calling.

7. A remote calling method based on RMI components as claimed in claim 1, characterized in that: Also includes: Provides a programming interface, defines the RMIAPI object, and creates the RMIRuqest object through the RMIAPI object to perform remote calls on services.

8. A remote call system based on RMI components, characterized in that: Including information acquisition module and service call module: The information acquisition module is configured to: acquire service information to be remotely called; The service calling module is configured to: send a request and process a response to the service through the RMI component based on the service information; Among them, the RMI component defines a declarative interface for each remote service, uses RMI annotations to configure service information in the declarative interface, uses dynamic proxies to dynamically generate proxy classes for the declarative interface that actually execute requests and responses, and uses the proxy objects generated for the proxy classes to perform unified interface calls.

9. An electronic device, comprising: a memory for non-transitory storage of computer readable instructions; a processor for executing the computer-readable instructions; Wherein, when the computer-readable instructions are executed by the processor, the method according to any one of claims 1 to 7 is executed.

10. A storage medium, characterized in that: The computer-readable instructions are non-transitorily stored, wherein when the computer-readable instructions are executed by a computer, the method of any one of claims 1 to 7 is performed.

Citation Information

Cited By

  • Component security control method, system and equipment based on low-code platform and medium

    CN120671121A