RPC request message processing method, processing filter, electronic device and medium
By using Java annotations and Java reflection driver in the RPC framework, the RPC request packets are automatically processed, which solves the problems of low filter development efficiency and poor reusability under the RPC framework, and achieves more efficient development and lower coupling filters design.
Patent Information
- Application Number
- CN202410629538.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-05-21
AI Technical Summary
Under the RPC framework, as business demand increases, the number of customized filters increases, resulting in low development efficiency, high filter coupling and poor reusability.
By using Java annotations and Java reflection drivers in RPC request messages, the method paths are automatically determined and replaced, so that the processing of RPC request messages is completed without the need to develop a separate filter for each target service.
It shortens the time-consuming development of filters, improves development efficiency, reduces the number of filters, reduces the coupling between filters, and improves the reusability and convenience of filters.
Smart Images

Figure CN118524129B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer communication technology, and in particular to an RPC request message processing method, a processing filter, an electronic device and a medium. Background Art
[0002] RPC (Remote Procedure Call) is a computer communication protocol that allows a computer program to call a program on another computer. The RPC framework includes two types of filters with request message processing and filtering functions: one is the filter that comes with the RPC framework, and the other is the filter that the developer develops through the filter development interface provided by the RPC framework to meet business needs.
[0003] However, with the increase in business needs, more and more filters are custom-developed under the RPC framework, which leads to a long time-consuming filter development and low development efficiency. After the filters corresponding to various business needs are integrated into the filter responsibility chain under the RPC framework, most of the business needs are to process the request messages, resulting in a high degree of coupling between the filters. In addition, since each custom-developed filter needs to implement the interface method when applied, the filter reusability is poor and inconvenient. Summary of the invention
[0004] In view of this, the purpose of the present application is to provide an RPC request message processing method, a processing filter, an electronic device and a medium, which can utilize the Java annotations corresponding to various target services in the RPC request message, and the Java reflection driver to process the RPC request message, without the need to develop a filter for each target service, thereby shortening the time spent on filter development and improving development efficiency; and each target service can complete message processing through one filter, reducing the number of filters, reducing the coupling between filters, and improving the reusability and convenience of filters.
[0005] In a first aspect, an embodiment of the present application provides an RPC request message processing method, which is applied to a processing filter, and the method includes:
[0006] Receive the remote procedure call (RPC) request message sent by the service consumer;
[0007] If the RPC request message has an annotation, determine the method path corresponding to the method identifier in the annotation according to the processor of the RPC request message and the annotation type of the annotation;
[0008] Annotations refer to Java annotations added by the service consumer to the request class or the attributes under the request class corresponding to the RPC request message, which are used to represent the method identifier corresponding to the target business;
[0009] Replace the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path;
[0010] Driven by Java reflection, the method stored in the corresponding position of the method path in the RPC request message is run to complete the processing of the RPC request message.
[0011] In a possible implementation, after receiving the remote procedure call RPC request message sent by the service consumer, the method further includes:
[0012] Determine whether there is a class annotation on the request class corresponding to the RPC request message, and whether there is an attribute annotation under the request class;
[0013] If the request class corresponding to the RPC request message has a class annotation, and / or the request class has a property annotation, then the RPC request message has an annotation.
[0014] In a possible implementation, determining whether a class annotation exists on a request class corresponding to an RPC request message and whether an attribute annotation exists under the request class includes:
[0015] Get the request class name in the RPC request message. The request class name carries the class path.
[0016] Get the request class and the attribute array of the request class corresponding to the request class name stored at the location of the class path through Java reflection;
[0017] Determine whether there are class annotations and attribute annotations on the request class.
[0018] In a possible implementation, before receiving the remote procedure call RPC request message method sent by the service consumer, the method further includes:
[0019] When the RPC architecture is started, the contents of the locally stored driver method mapping file are synchronously cached into the method path mapping table stored in the cache;
[0020] The driver method mapping file stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
[0021] In a possible implementation, determining a method path corresponding to a method identifier in an annotation according to a processor of the RPC request message and an annotation type of the annotation includes:
[0022] According to the processor of the RPC request message and the annotation type of the annotation, determine the method path corresponding to the method identifier in the annotation from the method path mapping table stored in the cache;
[0023] The method path mapping table stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
[0024] In a possible implementation, the method further includes:
[0025] The content stored in the method path mapping table is refreshed according to the content stored in the locally stored driving method mapping file according to the preset time.
[0026] In one possible implementation, the method includes:
[0027] According to the preset time, hashing the content in the locally stored driving method mapping file to obtain the current content hash value corresponding to the driving method mapping file;
[0028] If the current content hash value is different from the corresponding content hash value obtained last time, the content stored in the method path mapping table is refreshed according to the content stored in the driver method mapping file.
[0029] In a second aspect, an embodiment of the present application further provides a processing filter, the processing filter comprising:
[0030] The receiving module is used to receive the remote procedure call (RPC) request message sent by the service consumer;
[0031] A determination module, for determining, if an annotation exists in the RPC request message, a method path corresponding to the method identifier in the annotation according to the processor of the RPC request message and the annotation type of the annotation;
[0032] Annotations refer to Java annotations added by the service consumer to the request class or the attributes under the request class corresponding to the RPC request message, which are used to represent the method identifier corresponding to the target business;
[0033] The replacement module is used to replace the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path;
[0034] The running module is used to run the method stored in the corresponding position of the method path in the RPC request message through Java reflection drive to complete the processing of the RPC request message.
[0035] In a possible implementation manner, the processing filter further includes a judgment module;
[0036] A judgment module is used to judge whether there is a class annotation on the request class corresponding to the RPC request message and whether there is an attribute annotation under the request class after receiving the remote procedure call RPC request message sent by the service consumer; if there is a class annotation on the request class corresponding to the RPC request message and / or there is an attribute annotation under the request class, then the RPC request message has an annotation.
[0037] In one possible implementation, the judgment module is specifically used to obtain the request class name in the RPC request message, where the request class name carries a class path; obtain the request class corresponding to the request class name and the attribute array of the request class stored at the location of the class path through Java reflection; and judge whether there are class annotations on the request class and whether there are annotations on the attributes.
[0038] In a possible implementation, the processing filter further includes a cache module;
[0039] A cache module is used to synchronously cache the contents of the locally stored driver method mapping file into the method path mapping table stored in the cache before receiving the remote procedure call RPC request message method sent by the service consumer, when the RPC architecture is started;
[0040] The driver method mapping file stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
[0041] In one possible implementation, a determination module is specifically used to determine, based on the processor of the RPC request message and the annotation type of the annotation, a method path corresponding to the method identifier in the annotation from a method path mapping table stored in a cache; wherein the method path mapping table stores correspondingly the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
[0042] In a possible implementation, the processing filter further includes: a refreshing module;
[0043] The refresh module is used to refresh the content stored in the method path mapping table according to the content stored in the locally stored driving method mapping file according to the preset time.
[0044] In a possible implementation manner, the refresh module is further configured to:
[0045] According to the preset time, hashing the content in the locally stored driving method mapping file to obtain the current content hash value corresponding to the driving method mapping file;
[0046] If the current content hash value is different from the corresponding content hash value obtained last time, the content stored in the method path mapping table is refreshed according to the content stored in the driver method mapping file.
[0047] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the storage medium communicate through the bus, and the processor executes the machine-readable instructions to perform the steps of any RPC request message processing method in the first aspect.
[0048] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the RPC request message processing method of any one of the first aspects are executed.
[0049] An embodiment of the present application provides an RPC request message processing method, a processing filter, an electronic device and a medium, the method comprising: receiving a remote procedure call RPC request message sent by a service consumer; if the RPC request message has an annotation, determining a method path corresponding to a method identifier in the annotation according to the processor of the RPC request message and the annotation type of the annotation; wherein the annotation refers to a Java annotation added by the service consumer on a request class corresponding to the RPC request message or on an attribute under the request class, for characterizing a method identifier corresponding to a target business; replacing the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path; and running the method stored at a position corresponding to the method path in the RPC request message through Java reflection drive to complete the processing of the RPC request message. This application uses Java annotations corresponding to various target services in the RPC request message, as well as Java reflection driver to process the RPC request message. There is no need to develop a filter for each target service, which shortens the time spent on filter development and improves development efficiency. Each target service can complete message processing through one filter, which reduces the number of filters, reduces the coupling between filters, and improves the reusability and convenience of filters. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0051] Figure 1 A schematic diagram of a process of processing an RPC request message provided in an embodiment of the present application is shown;
[0052] Figure 2A schematic diagram of the structure of an RPC architecture provided with a processing filter provided in an embodiment of the present application is shown;
[0053] Figure 3 A schematic diagram of the structure of an RPC request message provided in an embodiment of the present application is shown;
[0054] Figure 4 A schematic diagram of a driving method mapping file provided in an embodiment of the present application is shown;
[0055] Figure 5 A schematic diagram of the workflow of an RPC architecture provided with a processing filter provided in an embodiment of the present application is shown;
[0056] Figure 6 A schematic diagram of a process of another RPC request message processing method provided in an embodiment of the present application is shown;
[0057] Figure 7 A schematic structural diagram of a processing filter provided in an embodiment of the present application is shown;
[0058] Figure 8 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0059] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of explanation and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn in real proportion. The flowchart used in this application shows the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowchart can be implemented out of sequence, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart under the guidance of the content of the present application, or remove one or more operations from the flowchart.
[0060] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0061] In order to enable those skilled in the art to use the contents of this application, the following implementation is provided in conjunction with a specific application scenario, "the field of computer communication technology". For those skilled in the art, the general principles defined herein may be applied to other embodiments and application scenarios without departing from the spirit and scope of this application. Although this application is mainly described around the "field of computer communication technology", it should be understood that this is only an exemplary embodiment.
[0062] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.
[0063] The following is a detailed description of an RPC request message processing method provided in an embodiment of the present application.
[0064] Reference Figure 1 As shown, it is a flow chart of an RPC request message processing method provided in an embodiment of the present application. The exemplary steps of the embodiment of the present application are described below:
[0065] S101. Receive a remote procedure call (RPC) request message sent by a service consumer.
[0066] In an implementation manner of the present application, when the RPC request message passes through the processing filter, the processing filter will receive the RPC request message; the RPC request message is a message sent by the service consumer requiring the service provider to provide a service (that is, a message for which the service provider has not yet provided a service).
[0067] Here, both the service consumer and the service provider in the RPC architecture can set a processing filter. The processing filter of the service consumer should be the last filter among all filters (referring to all filters in the service consumer) that the RPC request message sent by the service consumer passes through; the processing filter of the service provider should be the last filter among all filters (referring to all filters in the service provider). Figure 2 As shown, it is a structural diagram of the RPC architecture provided with a processing filter provided in an embodiment of the present application, where built-in filter 01, built-in filter 02, and built-in filter 03 are filters on the service consumption side, and built-in filter 04, built-in filter 05, and built-in filter 06 are filters on the service provision side.
[0068] Among them, RPC (Remote Procedure Call), that is, two servers A and B, an application deployed on server A wants to call the function / method provided by the application on server B. Since it is not in the same memory space, it cannot be called directly. It is necessary to express the semantics of the call and convey the call data through the network.
[0069] Further, determine whether there is a class annotation on the request class corresponding to the RPC request message, and whether there is an attribute annotation under the request class; if there is a class annotation on the request class corresponding to the RPC request message, and / or there is an attribute annotation under the request class, then the RPC request message has an annotation.
[0070] In the implementation manner of the present application, annotations include annotations on classes and annotations on attributes. Annotations refer to Java annotations added by the service consumer on the request class of the RPC request message or on the attributes under the request class, which are used to characterize the method identifier corresponding to the target business; the method corresponding to the method identifier corresponding to each target business is used to implement the business logic of each target business; in an RPC request message, there can be multiple annotations, that is, there can be multiple method identifiers corresponding to multiple target businesses, that is, the processing filter in the present application can implement the business logic of multiple target businesses without the need to develop multiple filters, thus shortening the time required to develop filters and improving development efficiency; and each target business can complete message processing through one filter, thus reducing the number of filters, reducing the coupling between filters, and improving the reusability and convenience of filters.
[0071] Among them, Java annotations, also known as Java annotations, are a new feature introduced in JDK5. It provides a safe, comment-like mechanism for associating any information or metadata with program elements (classes, methods, member variables, etc.); Java annotations are some meta-information attached to the code, which are used by some tools to parse and use during compilation and runtime, and play the role of description and configuration.
[0072] Specifically, after receiving the remote procedure call RPC request message sent by the service consumer, the method also includes: determining whether there is a class annotation on the request class corresponding to the RPC request message, and whether there is an attribute annotation under the request class; if there is a class annotation on the request class corresponding to the RPC request message, and / or there is an attribute annotation under the request class, then the RPC request message has an annotation.
[0073] In an implementation manner of the present application, a request class name in an RPC request message is obtained, where the request class name carries a class path; a request class and an attribute array of the request class corresponding to the request class name stored at the location of the class path are obtained through Java reflection; and it is determined whether there are class annotations on the request class and whether there are annotations on the attributes.
[0074] Reference Figure 3As shown, it is a schematic diagram of the structure of an RPC request message provided by an embodiment of the present application; the structure of the RPC request message includes a message header and a message body; the length of the message header is fixed, and records the message body length and the message body structure (class); the specific data of the RPC request message is stored in the message body structure of the RPC request message. The request class name is stored in the message body structure of the RPC request message, and the request class name carries the class path; the request class corresponding to the request class name and the attribute array of the request class stored at the location of the class path are obtained through java reflection. If there is a class annotation on the request class in the RPC request message, then there is an annotation in the RPC request message; it is determined in turn whether each attribute in the attribute array of the request class has an attribute annotation; if there is an attribute annotation, then there is an annotation in the RPC request message.
[0075] S102: If the RPC request message has an annotation, determine the method path corresponding to the method identifier in the annotation according to the processor of the RPC request message and the annotation type of the annotation.
[0076] In the implementation of the present application, the annotation type includes the annotation type on the class and the annotation type on the attribute; the annotation corresponding to the annotation type on the class is the annotation on the class; the annotation corresponding to the annotation type on the attribute is the annotation on the attribute. When there is an annotation in the RPC request message, the method path corresponding to the method identifier in the annotation is determined from the method path mapping table stored in the cache according to the processor of the RPC request message and the annotation type of the annotation.
[0077] Here, the processor of the RPC request message refers to the side where the processing filter currently processing the RPC request message is located, including service consumers and consumer providers. As shown in Table 1, a method path mapping table provided in an embodiment of the present application is provided, wherein the method path mapping table stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
[0078] Table 1
[0079]
[0080] Among them, for the same method identifier, the corresponding annotation type is different, and the method path will also be different. For example, the specified function of the method identifier is the signing and verification operation. When the processor is a service consumer, the target business to be implemented is signing; when the processor is a service provider, the target business to be implemented is verification. Different processors have different target businesses to be implemented, and the method paths are also different.
[0081] Here, the content in the method path mapping table is obtained from the locally stored driver method mapping file; the driver method mapping file stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
[0082] Specifically, before the method of receiving the remote procedure call (RPC) request message sent by the service consumer, the method further includes: when the RPC architecture is started, synchronously caching the content in the locally stored driver method mapping file into the method path mapping table stored in the cache.
[0083] Specifically, the content in the method path mapping table is refreshed according to a preset time length.
[0084] Reference Figure 4 As shown, it is a schematic diagram of a driving method mapping file provided by an embodiment of the present application; when the content of the driving method mapping file is synchronously cached into the method path mapping table, or when the content of the method path mapping table is refreshed, the attached Figure 4 The "Annotations on Classes" and "Annotations on Properties" in the method path mapping table correspond to the "Annotation Type of Annotation" field in the method path mapping table; Figure 4 The "method identifier = A", "method identifier = B" and "method identifier = C" in the method path mapping table correspond to the "method identifier in annotation" field in the method path mapping table; Figure 4 The "service consumer" and "service provider" in the method path mapping table correspond to the "RPC request message processor" field in the method path mapping table; Figure 4 The "Method and Method Path" in corresponds to the "Method Path" field in the method path mapping table.
[0085] Here, the present application stores the method path mapping table in the cache, which can ensure that the method path corresponding to the method identifier is obtained in the cache, speeding up the acquisition of the method path, thereby shortening the time for message processing.
[0086] Furthermore, the present application provides two ways of refreshing the content in the method path mapping table according to a preset duration.
[0087] The first method of refreshing the content in the method path mapping table includes: refreshing the content stored in the method path mapping table according to the content stored in the locally stored driving method mapping file according to a preset time period.
[0088] The preset duration is the duration for configuring the content stored in the driving method mapping file into the method path mapping table, so that the content in the method path mapping table can be guaranteed to be accurate.
[0089] The second method of refreshing the content in the method path mapping table includes: hashing the content in the locally stored driving method mapping file according to a preset duration to obtain the current content hash value corresponding to the driving method mapping file; if the current content hash value is different from the corresponding content hash value obtained last time, refreshing the content stored in the method path mapping table according to the content stored in the driving method mapping file; if the current content hash value is the same as the corresponding content hash value obtained last time, there is no need to refresh the content in the method path mapping table.
[0090] In the implementation manner of the present application, by comparing the current content hash value with the corresponding content hash value obtained last time, it can be ensured that the content in the method path mapping table is refreshed only when the content in the driver method mapping file changes, thereby reducing the number of refresh times.
[0091] The preset duration is the duration for configuring the content stored in the driving method mapping file into the method path mapping table, so that the content in the method path mapping table can be guaranteed to be accurate.
[0092] When the method path mapping table is continuously iterated with the demand and forms a scale within a certain period of time, these annotated driver methods can be reused, and the locally stored driver method mapping file records the driver methods of all annotation types; therefore, the locally stored driver method mapping file naturally forms the role of a filter warehouse.
[0093] S103. Replace the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path.
[0094] S104. Driven by Java reflection, the method stored in the corresponding position of the method path in the RPC request message is run to complete the processing of the RPC request message.
[0095] Here. Java reflection mechanism is in the running state, for any class, you can know all the properties and methods of this class; for any object, you can call any of its methods and properties; this function of dynamically obtaining information and dynamically calling object methods is called the reflection mechanism of Java language.
[0096] like Figure 5As shown, it is a schematic diagram of the workflow of the RPC architecture provided with a processing filter provided in the embodiment of the present application; based on the RPC framework, the service consumer initiates an RPC request (invoke RPC remote call); after being processed by the RPC built-in filter (built-in filter 01 to built-in filter 03) responsibility chain (req-1 to req-4); when passing through the last node of the responsibility chain (the processing filter of the service consumer), it is detected that the request message is annotation-driven (req-4-1), and it officially enters the entrance for processing the RPC request message through the processing filter, and executes the RPC request message processing method provided in the embodiment of the present application; after the processing of the processing filter of the service consumer is completed, it is transferred to the built-in filter (built-in filter 04 to built-in filter 06) chain (req-5 to req-8) of the service provider. When passing through the last node of the responsibility chain (the processing filter of the service provider), it is detected that the request message has an annotation driver (req8-res-1), and it officially enters the entrance for RPC request message processing through the processing filter, and executes the RPC request message processing method provided in the embodiment of the present application; when the processing filter of the service provider completes the processing, it responds to the service consumer (Consumer, res-1~res-9) in sequence according to the call link; among them, the message is not processed when the links res-1~res-9 pass through the processing filter.
[0097] An embodiment of the present application provides an RPC request message processing method, which is applied to a filter, including: receiving a remote procedure call RPC request message sent by a service consumer; if the RPC request message has an annotation, determining a method path corresponding to a method identifier in the annotation according to a processor of the RPC request message and an annotation type of the annotation; wherein the annotation refers to a Java annotation added by a service consumer to a request class corresponding to the RPC request message or to an attribute under the request class, which is used to characterize a method identifier corresponding to a target business; replacing the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path; and running the method stored in a corresponding position of the method path in the RPC request message through Java reflection drive to complete the processing of the RPC request message. This application uses Java annotations corresponding to various target services in the RPC request message, as well as Java reflection driver to process the RPC request message. There is no need to develop a filter for each target service, which shortens the time spent on filter development and improves development efficiency. Each target service can complete message processing through one filter, which reduces the number of filters, reduces the coupling between filters, and improves the reusability and convenience of filters.
[0098] Reference Figure 6As shown, it is a flowchart of another RPC request message processing method provided in an embodiment of the present application. The exemplary steps of the embodiment of the present application are described below:
[0099] S601 . Hash the content in the locally stored driving method mapping file according to a preset time length to obtain a current content hash value corresponding to the driving method mapping file.
[0100] In the implementation manner of the present application, the process of hashing the content in the locally stored driving method mapping file may be any hashing algorithm in the prior art.
[0101] S602: If the current content hash value is different from the corresponding content hash value obtained last time, the content stored in the method path mapping table is refreshed according to the content stored in the driving method mapping file.
[0102] In the implementation manner of the present application, if the current content hash value is different from the corresponding content hash value obtained last time, it means that the content in the driving method mapping file has changed. Therefore, the content stored in the method path mapping table is refreshed according to the content stored in the driving method mapping file.
[0103] S603: If the current content hash value is the same as the corresponding content hash value obtained last time, there is no need to refresh the content in the method path mapping table.
[0104] The embodiment of the present application provides a flow chart of another RPC request message processing method, which includes: hashing the content in the locally stored driving method mapping file according to a preset time length to obtain the current content hash value corresponding to the driving method mapping file; if the current content hash value is different from the corresponding content hash value obtained last time, then refreshing the content stored in the method path mapping table according to the content stored in the driving method mapping file; if the current content hash value is the same as the corresponding content hash value obtained last time, there is no need to refresh the content in the method path mapping table. By comparing the current content hash value with the corresponding content hash value obtained last time, it can be ensured that the content in the method path mapping table is refreshed only when the content in the driving method mapping file changes, thereby reducing the number of refreshes.
[0105] Based on the same inventive concept, the embodiment of the present application also provides a processing filter corresponding to the RPC request message processing method. Since the principle of solving the problem by the processing filter in the embodiment of the present application is similar to the above-mentioned RPC request message processing method in the embodiment of the present application, the implementation of the processing filter can refer to the implementation of the method, and the repeated parts will not be repeated.
[0106] Reference Figure 7FIG. 1 is a schematic diagram of a structure of a processing filter provided in an embodiment of the present application, wherein the processing filter comprises:
[0107] The receiving module 701 is used to receive a remote procedure call (RPC) request message sent by a service consumer;
[0108] The determination module 702 is used to determine the method path corresponding to the method identifier in the annotation according to the processor of the RPC request message and the annotation type of the annotation if the RPC request message has an annotation;
[0109] Annotations refer to Java annotations added by the service consumer to the request class or the attributes under the request class corresponding to the RPC request message, which are used to represent the method identifier corresponding to the target business;
[0110] A replacement module 703 is used to replace the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path;
[0111] The running module 704 is used to run the method stored in the corresponding position of the method path in the RPC request message through Java reflection drive to complete the processing of the RPC request message.
[0112] In a possible implementation, the processing filter further includes a determination module 705;
[0113] The judgment module 705 is used to judge whether there is a class annotation on the request class corresponding to the RPC request message and whether there is an attribute annotation under the request class after receiving the remote procedure call RPC request message sent by the service consumer; if there is a class annotation on the request class corresponding to the RPC request message and / or there is an attribute annotation under the request class, then the RPC request message has an annotation.
[0114] In one possible implementation, the judgment module 705 is specifically used to obtain the request class name in the RPC request message, where the request class name carries a class path; obtain the request class corresponding to the request class name and the attribute array of the request class stored at the location of the class path through Java reflection; and determine whether there are class annotations on the request class and whether there are annotations on the attributes.
[0115] In a possible implementation, the processing filter further includes a cache module 706;
[0116] The cache module 706 is used to cache the contents of the locally stored driver method mapping file synchronously into the method path mapping table stored in the cache before receiving the remote procedure call RPC request message method sent by the service consumer, when the RPC architecture is started;
[0117] The driver method mapping file stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
[0118] In one possible implementation, the determination module 702 is specifically used to determine the method path corresponding to the method identifier in the annotation from the method path mapping table stored in the cache according to the processor of the RPC request message and the annotation type of the annotation; wherein the method path mapping table stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
[0119] In a possible implementation, the processing filter further includes: a refreshing module 707;
[0120] The refresh module 707 is used to refresh the content stored in the method path mapping table according to the content stored in the locally stored driving method mapping file according to a preset time period.
[0121] In a possible implementation manner, the refreshing module 707 is further configured to:
[0122] According to the preset time, hashing the content in the locally stored driving method mapping file to obtain the current content hash value corresponding to the driving method mapping file;
[0123] If the current content hash value is different from the corresponding content hash value obtained last time, the content stored in the method path mapping table is refreshed according to the content stored in the driver method mapping file.
[0124] The present application provides a structural schematic diagram of a processing filter, which includes: a receiving module 701, which is used to receive a remote procedure call RPC request message sent by a service consumer; a determining module 702, which is used to determine, if there is an annotation in the RPC request message, the method path corresponding to the method identifier in the annotation according to the processor of the RPC request message and the annotation type of the annotation; wherein the annotation refers to a Java annotation added by the service consumer on the request class corresponding to the RPC request message or on the attribute under the request class, which is used to characterize the method identifier corresponding to the target business; a replacing module 703, which is used to replace the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path; and a running module 704, which is used to run the method stored in the corresponding position of the method path in the RPC request message through Java reflection drive to complete the processing of the RPC request message. This application uses Java annotations corresponding to various target services in the RPC request message, as well as Java reflection driver to process the RPC request message. There is no need to develop a filter for each target service, which shortens the time spent on filter development and improves development efficiency. Each target service can complete message processing through one filter, which reduces the number of filters, reduces the coupling between filters, and improves the reusability and convenience of filters.
[0125] like Figure 8 As shown, an electronic device 800 provided in an embodiment of the present application includes: a processor 801, a memory 802 and a bus, the memory 802 stores machine-readable instructions executable by the processor 801, when the electronic device is running, the processor 801 and the memory 802 communicate through the bus, and the processor 801 executes the machine-readable instructions to perform the steps of the above-mentioned RPC request message processing method.
[0126] Specifically, the memory 802 and the processor 801 can be general-purpose memories and processors, which are not specifically limited here. When the processor 801 runs the computer program stored in the memory 802, the RPC request message processing method can be executed.
[0127] Corresponding to the above-mentioned RPC request message processing method, an embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned RPC request message processing method are executed.
[0128] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the method embodiment, and will not be repeated in this application. In the several embodiments provided in this application, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0129] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0130] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0131] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the information processing method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard drives, ROM, RAM, magnetic disks, or optical disks.
[0132] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for processing an RPC request message, characterized in that: The method is applied to processing filters, and the method comprises: Receive the remote procedure call (RPC) request message sent by the service consumer; If the RPC request message has an annotation, determining a method path corresponding to the method identifier in the annotation according to the processor of the RPC request message and the annotation type of the annotation; The annotation refers to a Java annotation added by the service consumer on the request class corresponding to the RPC request message or on the attribute under the request class, which is used to represent the method identifier corresponding to the target service; Replace the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path; By driving through Java reflection, the method stored in the corresponding position of the method path in the RPC request message is run to complete the processing of the RPC request message; Before the remote procedure call (RPC) request message method received from the service consumer, the method further includes: when the RPC architecture is started, synchronously caching the contents of the locally stored driver method mapping file into the method path mapping table stored in the cache; wherein the driver method mapping file stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
2. The RPC request message processing method according to claim 1, characterized in that: After receiving the remote procedure call (RPC) request message sent by the service consumer, the method further includes: Determine whether there is a class annotation on the request class corresponding to the RPC request message, and whether there is an attribute annotation under the request class; If there is a class annotation on the request class corresponding to the RPC request message, and / or there is an attribute annotation under the request class, then the RPC request message has an annotation.
3. The RPC request message processing method according to claim 2, characterized in that: Determining whether there is a class annotation on the request class corresponding to the RPC request message and whether there is an attribute annotation under the request class includes: Obtain a request class name in the RPC request message, where the request class name carries a class path; Obtaining, through Java reflection, a request class corresponding to the request class name and an attribute array of the request class stored at the location of the class path; Determine whether there is a class annotation on the request class and whether there is an annotation on the attribute.
4. The RPC request message processing method according to any one of claims 1 to 3, characterized in that: The determining, according to the processor of the RPC request message and the annotation type of the annotation, a method path corresponding to the method identifier in the annotation includes: Determine, according to the processor of the RPC request message and the annotation type of the annotation, a method path corresponding to the method identifier in the annotation from a method path mapping table stored in a cache; The method path mapping table stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path accordingly.
5. The RPC request message processing method according to claim 4, characterized in that: The method further comprises: The content stored in the method path mapping table is refreshed according to the content stored in the locally stored driving method mapping file according to the preset time period.
6. The RPC request message processing method according to claim 5, characterized in that: The method comprises: Hash the content in the locally stored driving method mapping file according to the preset time length to obtain a current content hash value corresponding to the driving method mapping file; If the current content hash value is different from the corresponding content hash value obtained last time, the content stored in the method path mapping table is refreshed according to the content stored in the driving method mapping file.
7. A processed filter, characterized in that: The processing filter comprises: The receiving module is used to receive the remote procedure call (RPC) request message sent by the service consumer; A determination module, configured to determine, if the RPC request message has an annotation, a method path corresponding to the method identifier in the annotation according to a processor of the RPC request message and an annotation type of the annotation; The annotation refers to a Java annotation added by the service consumer on the request class corresponding to the RPC request message or on the attribute under the request class, which is used to represent the method identifier corresponding to the target service; A replacement module, used to replace the code corresponding to the method identifier in the annotation corresponding to the RPC request message with the method path; A running module, used to run the method stored in the corresponding position of the method path in the RPC request message through Java reflection driving, so as to complete the processing of the RPC request message; A cache module is used to synchronously cache the contents of a locally stored driver method mapping file into a method path mapping table stored in the cache before the remote procedure call RPC request message method sent by the receiving service consumer is received, when the RPC architecture is started; wherein the driver method mapping file stores the processor of the RPC request message, the annotation type of the annotation, the method identifier in the annotation, and the method path.
8. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the RPC request message processing method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the RPC request message processing method according to any one of claims 1 to 6 are executed.
Citation Information
Patent Citations
Method for optimizing transaction remote procedure call, medium and electronic equipment
CN112256455A
Financial message processing method and device, electronic equipment and storage medium
CN116346961A