Service registration and interception method, device, electronic device and readable storage medium

By generating service definition code and scanning the main program code for registration and binding, the fine-grained interception of the gRPC framework is realized, solving the problems of bloated code and incorrect interception, and improving the scalability and maintainability of the code.

CN112596932BActive Publication Date: 2025-01-14TIANMIAN INFORMATION TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110020904.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-01-04
Publication Date
2025-01-14
Estimated Expiration
2041-01-04

AI Technical Summary

Technical Problem

The existing gRPC framework is too bloated when registering service and interceptor registration, and cannot implement fine-grained interception and cannot intercept specified methods.

Method used

By parsing the user's service registration request, obtain the service name to be registered, the interceptor name and its binding relationship, generate service definition code, including annotation identifier, scan the main program code for registration and binding operations, and perform interception when calling the request Processing to achieve fine-grained interception.

Benefits of technology

It improves the scalability and maintainability of the code, realizes fine interception of specified methods, and solves the problem that the existing gRPC framework can only intercept all methods under the service.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112596932B_ABST
    Figure CN112596932B_ABST
Patent Text Reader

Abstract

The present invention relates to data processing, and discloses a service registration and interception method, including: obtaining annotation definition code, generating service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, wherein the service definition code includes annotation identifiers; filling the annotation definition code and the service definition code into the main program code corresponding to the target application, scanning the annotation identifiers in the main program code, performing registration operations and binding operations on the service to be registered and the interceptor to be registered; performing interception processing on the call request based on one or more service names to be called and the method names to be called carried by the call request. The present invention also provides a service registration and interception device, an electronic device, and a readable storage medium. The present invention improves the scalability and maintainability of the code, and realizes fine-grained interception.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing, and in particular to a service registration and interception method, device, electronic device and readable storage medium. Background Art

[0002] With the development of science and technology, communication is more and more widely used in people's lives. The gRPC (Google Remote Procedure Call) framework is a basic network communication component. The communication process involves service registration, interceptor registration, and binding of services and interceptors. The existing gRPC framework requires writing corresponding registration codes and binding codes one by one, which is difficult to expand. If there are many services that need to be registered, the code will be too bloated and difficult to maintain. In addition, the existing gRPC framework will intercept all methods under the service, but cannot intercept specified methods, and cannot achieve fine-grained interception. Therefore, there is an urgent need for a service registration and interception method to improve the scalability and maintainability of the code and achieve fine-grained interception. Summary of the invention

[0003] In view of the above, it is necessary to provide a service registration and interception method to improve the scalability and maintainability of the code and achieve fine-grained interception.

[0004] The service registration and interception method provided by the present invention includes:

[0005] Parse the service registration request for the target application issued by the user based on the client, and obtain the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered carried in the service registration request;

[0006] Obtain a predetermined annotation definition code from a database, and generate a service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, wherein the service definition code includes an annotation identifier;

[0007] Fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration and binding operations on the service to be registered and the interceptor to be registered;

[0008] Monitor the call request for the target application in real time, obtain one or more service names to be called and method names to be called carried in the call request, and perform interception processing on the call request based on the service names to be called and method names to be called.

[0009] Optionally, the service registration request also includes a transaction to be intercepted, and the generating of the service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered includes:

[0010] Generate a first definition code based on the name of the interceptor to be registered and the transaction to be intercepted;

[0011] Generate a second definition code based on the name of the service to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered;

[0012] The first definition code and the second definition code are combined to obtain a service definition code.

[0013] Optionally, scanning the annotation identifier in the main program code and performing registration and binding operations on the service to be registered and the interceptor to be registered includes:

[0014] Scanning program segments with annotation marks in the main program code and performing correctness verification on the program segments;

[0015] When the verification is passed, interception data is generated based on the program segment, and registration operations and binding operations are performed on the service to be registered and the interceptor to be registered based on the interception data.

[0016] Optionally, after performing a correctness check on the program segment, the method further includes:

[0017] If the verification fails, the program segment is marked and a warning message is sent to the client.

[0018] Optionally, the intercepting process of the calling request based on the name of the service to be called and the name of the method to be called includes:

[0019] Determine whether each service to be called is bound to an interceptor;

[0020] When it is determined that a certain designated service to be called is bound to an interceptor, it is determined whether the method to be called of the designated service to be called exists in the method name list to be intercepted of the designated service to be called;

[0021] When it is determined that the method exists in the list of method names to be intercepted of the specified service to be called, interception processing is performed on the call request.

[0022] Optionally, after determining whether each service to be called is bound to an interceptor, the method further includes:

[0023] If it is determined that each service to be called is not bound to an interceptor or the method to be called of the specified service to be called does not exist in the method name list to be intercepted of the specified service to be called, the calling operation corresponding to the calling request is executed.

[0024] In order to solve the above problems, the present invention also provides a service registration and interception device, the device comprising:

[0025] A parsing module is used to parse the service registration request for the target application issued by the user based on the client, and obtain the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered;

[0026] A generation module, used to obtain a predetermined annotation definition code from a database, and generate a service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, wherein the service definition code includes an annotation identifier;

[0027] A scanning module, used to fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration operations and binding operations on the service to be registered and the interceptor to be registered;

[0028] The interception module is used to monitor the call request for the target application in real time, obtain one or more names of the service to be called and the names of the method to be called carried in the call request, and perform interception processing on the call request based on the name of the service to be called and the name of the method to be called.

[0029] Optionally, scanning the annotation identifier in the main program code and performing registration and binding operations on the service to be registered and the interceptor to be registered includes:

[0030] Scanning program segments with annotation marks in the main program code and performing correctness verification on the program segments;

[0031] When the verification is passed, interception data is generated based on the program segment, and registration operations and binding operations are performed on the service to be registered and the interceptor to be registered based on the interception data.

[0032] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:

[0033] at least one processor; and,

[0034] a memory communicatively connected to the at least one processor; wherein,

[0035] The memory stores a service registration and interception program that can be executed by the at least one processor, and the service registration and interception program is executed by the at least one processor so that the at least one processor can execute the above-mentioned service registration and interception method.

[0036] In order to solve the above problems, the present invention also provides a computer-readable storage medium, on which a service registration and interception program is stored. The service registration and interception program can be executed by one or more processors to implement the above service registration and interception method.

[0037] Compared with the prior art, the present invention first obtains the annotation definition code, generates the service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, and the service definition code includes the annotation identifier; then, fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration and binding operations on the service to be registered and the interceptor to be registered; finally, perform interception processing on the call request based on the name of the service to be called and the name of the method to be called carried by the call request. This solution only needs to mark the annotation identifier in the service definition code corresponding to the service to be registered, so as to realize the registration of the service, the registration of the interceptor, and the binding of the service and the interceptor, thereby improving the scalability and maintainability of the code; by adding the list of method names to be intercepted of the service in the service definition code, the technical problem that the existing gRPC can only intercept all methods under the service but cannot intercept the specified method under the service is solved, and refined interception is realized. Therefore, the present invention improves the scalability and maintainability of the code, and realizes fine-grained interception. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 A flow chart of a service registration and interception method provided by an embodiment of the present invention;

[0039] Figure 2 A schematic diagram of a module of a service registration and interception device provided by an embodiment of the present invention;

[0040] Figure 3 A schematic diagram of the structure of an electronic device for implementing a service registration and interception method provided by an embodiment of the present invention;

[0041] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0042] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0043] It should be noted that the descriptions of "first", "second", etc. in the present invention are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0044] The present invention provides a service registration and interception method. Figure 1 FIG. 1 is a flow chart of a service registration and interception method provided by an embodiment of the present invention. The method can be executed by an electronic device, and the electronic device can be implemented by software and / or hardware.

[0045] In this embodiment, the service registration and interception method includes:

[0046] S1. Parse the service registration request for the target application issued by the user based on the client, and obtain the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered carried in the service registration request.

[0047] The target application can be a communication APP, which uses the gRPC framework for communication. gRPC is a general RPC framework designed for mobile and HTTP / 2, supporting C, Java and Go language versions. The framework uses protobuf (protobuf is a platform-independent, language-independent, scalable, lightweight and efficient serialized data structure protocol, which is saved in files with the .proto suffix) binary message serialization and deserialization structure.

[0048] The service (i.e., service class) is defined in the .proto file with the service keyword. The JAVA version generated by the .proto file is a class that inherits the io.grpc.BindableService interface. The service can be simply understood as the interface that the system provides to the outside world.

[0049] Interceptor (i.e. interceptor class), in the gRPC framework, interceptors include client interceptors and server interceptors. The interceptor in this embodiment is a server interceptor, and the class that implements the io.grpc.ServerInterceptor interface is a server interceptor. The interceptor can be understood as doing pre-check work before calling the service (the pre-check work that the interceptor needs to do after intercepting the call request can be set according to the specific business scenario). For example, 1. When the caller accesses a service that requires login before access, the interceptor can first intercept the caller's request and determine whether the caller has logged in. If not, access to the corresponding service is not allowed; for example, 2. The system requires the caller's IP address to be in the system's IP whitelist before access to the service is allowed. In this case, the interceptor can first intercept the caller's request, and then determine whether the caller's IP is in the system whitelist. If it is not in the whitelist, access to the service is denied, otherwise access is allowed.

[0050] A method is used to complete a task or implement a function (for example, controlling input or calculating a value), and usually has a return value as the processing result or calculation result.

[0051] S2. Obtain a predetermined annotation definition code from a database, and generate a service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, wherein the service definition code includes an annotation identifier.

[0052] The annotation definition code is a custom gRPC service annotation code. In this embodiment, the annotation is @GrpcServer. The attributes of the @GrpcServer annotation are value (service name, type is String), interceptor (interceptor class Class, which must implement the io.grpc.ServerInterceptor interface. If this attribute is not set, it means that the service has no interceptor binding, otherwise it means that the service is bound to the interceptor), interceptMethods (a list of method names to be intercepted. If this attribute is not set, all methods of the service class are intercepted, otherwise the methods in the method name list to be intercepted of the service class are intercepted; this attribute must be set to take effect).

[0053] In this embodiment, the service registration request also includes a transaction to be intercepted (for example, determining whether the caller IP is in the system whitelist), and the service definition code is generated based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, including:

[0054] A11, generating a first definition code based on the name of the interceptor to be registered and the transaction to be intercepted;

[0055] In this embodiment, the interceptor class name xxxServerInterceptor can be determined according to the name of the interceptor to be registered. The xxxServerInterceptor interceptor class needs to inherit the io.grpc.ServerInterceptor interface class. The corresponding interception business code can be generated according to the transaction to be intercepted, and the first definition code is obtained after aggregation.

[0056] A12. Generate a second definition code based on the name of the service to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered;

[0057] The service class name xxxServer can be determined according to the name of the service to be registered. The xxxServer service class needs to inherit the io.grpc.BindableService interface class. Add the annotation @GrpcServer to the xxxServer service class, and set relevant properties according to the binding relationship between the service to be registered and the interceptor to be registered and the list of method names to be intercepted of the service to be registered. After summarizing, the second definition code is obtained.

[0058] A13. Combine the first definition code and the second definition code to obtain a service definition code.

[0059] S3. Fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration and binding operations on the service to be registered and the interceptor to be registered.

[0060] In this embodiment, the scanning of the annotation identifier in the main program code and the performing of the registration operation and the binding operation on the service to be registered and the interceptor to be registered include:

[0061] B11, scanning the program segments carrying annotation marks in the main program code, and performing correctness verification on the program segments;

[0062] The correctness check includes checking whether the service class in the program segment inherits the io.grpc.BindableService interface class, checking whether the interceptor class inherits the io.grpc.ServerInterceptor interface class, and checking the syntax correctness.

[0063] B12. When the verification passes, interception data is generated based on the program segment, and registration and binding operations are performed on the service to be registered and the interceptor to be registered based on the interception data.

[0064] In this embodiment, the interception data sample is as follows:

[0065] / / Structure definition of interception data

[0066] struct GrpcServer {

[0067] serverClass, / / Service class

[0068] i nterceptorClass, / / Interceptor class

[0069] interceptMethods / / To intercept the method name list under the service class

[0070] }

[0071] In this embodiment, the service and interceptor in the interception data are registered and bound to the system in a loop by calling the serverBuilder.addService method provided by the gRPC framework.

[0072] The existing gRPC framework needs to gradually add registration code and binding code for each service and interceptor when adding registration services and binding interceptors. When more services are added, the amount of code is relatively large. In this embodiment, there is only one line of code corresponding to the registration and binding operations. When adding service registration and binding interceptors, you only need to add an annotation identifier in front of the corresponding service definition code and set related properties. When deleting a service or unbinding an interceptor, you only need to delete the annotation identifier or delete the properties in the annotation. This embodiment makes the code more maintainable and easier to expand.

[0073] In this embodiment, after performing a correctness check on the program segment, the method further includes:

[0074] If the verification fails, the program segment is marked and a warning message is sent to the client.

[0075] S4. Monitor the call request for the target application in real time, obtain one or more service names to be called and method names to be called carried in the call request, and perform interception processing on the call request based on the service names to be called and method names to be called.

[0076] The intercepting process of the calling request based on the name of the service to be called and the name of the method to be called includes:

[0077] C11. Determine whether each service to be called is bound to an interceptor;

[0078] This embodiment can determine whether the service to be called is bound to an interceptor based on the interception data generated by the program segment.

[0079] C12. When it is determined that a certain designated service to be called is bound to an interceptor, it is determined whether the method to be called of the designated service to be called exists in the list of method names to be intercepted of the designated service to be called;

[0080] C13. When it is determined that the method exists in the list of method names to be intercepted of the specified service to be called, interception processing is performed on the call request.

[0081] After intercepting the call request, the corresponding business processing can be performed according to the interception business code corresponding to the transaction to be intercepted. Unlike the existing gRPC framework that can only intercept to the service granularity (can only intercept all methods under the service), this step realizes refined interception and can intercept any specified method in the service's method name list to be intercepted.

[0082] In this embodiment, after determining whether each service to be called is bound to an interceptor, the method further includes:

[0083] If it is determined that each service to be called is not bound to an interceptor or the method to be called of the specified service to be called does not exist in the method name list to be intercepted of the specified service to be called, the calling operation corresponding to the calling request is executed.

[0084] It can be seen from the above embodiments that the service registration and interception method proposed in the present invention first obtains the annotation definition code, generates the service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, and the service definition code includes the annotation identifier; then, fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration and binding operations on the service to be registered and the interceptor to be registered; finally, perform interception processing on the call request based on the name of the service to be called and the name of the method to be called carried by the call request. This scheme only needs to mark the annotation identifier in the service definition code corresponding to the service to be registered, so as to realize the registration of the service, the registration of the interceptor, and the binding of the service and the interceptor, thereby improving the scalability and maintainability of the code; by adding the list of method names to be intercepted of the service in the service definition code, the technical problem that the existing gRPC can only intercept all methods under the service but cannot intercept the specified method under the service is solved, and refined interception is realized. Therefore, the present invention improves the scalability and maintainability of the code and realizes fine-grained interception.

[0085] like Figure 2 FIG. 1 is a schematic diagram of a module of a service registration and interception device provided in an embodiment of the present invention.

[0086] The service registration and interception device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the service registration and interception device 100 can include a parsing module 110, a generating module 120, a scanning module 130 and an interception module 140. The module of the present invention can also be referred to as a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.

[0087] In this embodiment, the functions of each module / unit are as follows:

[0088] The parsing module 110 is used to parse the service registration request issued by the user based on the client for the target application, and obtain the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered.

[0089] The target application can be a communication APP, which uses the gRPC framework for communication. gRPC is a general RPC framework designed for mobile and HTTP / 2, supporting C, Java and Go language versions. The framework uses protobuf (protobuf is a platform-independent, language-independent, scalable, lightweight and efficient serialized data structure protocol, which is saved in files with the .proto suffix) binary message serialization and deserialization structure.

[0090] The service (i.e., service class) is defined in the .proto file with the service keyword. The JAVA version generated by the .proto file is a class that inherits the io.grpc.BindableService interface. The service can be simply understood as the interface that the system provides to the outside world.

[0091] Interceptor (i.e. interceptor class), in the gRPC framework, interceptors include client interceptors and server interceptors. The interceptor in this embodiment is a server interceptor, and the class that implements the io.grpc.ServerInterceptor interface is a server interceptor. The interceptor can be understood as doing pre-check work before calling the service (the pre-check work that the interceptor needs to do after intercepting the call request can be set according to the specific business scenario). For example, 1. When the caller accesses a service that requires login before access, the interceptor can first intercept the caller's request and determine whether the caller has logged in. If not, access to the corresponding service is not allowed; for example, 2. The system requires the caller's IP address to be in the system's IP whitelist before access to the service is allowed. In this case, the interceptor can first intercept the caller's request, and then determine whether the caller's IP is in the system whitelist. If it is not in the whitelist, access to the service is denied, otherwise access is allowed.

[0092] A method is used to complete a task or implement a function (for example, controlling input or calculating a value), and usually has a return value as the processing result or calculation result.

[0093] The generation module 120 is used to obtain a predetermined annotation definition code from a database, and generate a service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, wherein the service definition code includes an annotation identifier.

[0094] The annotation definition code is a custom gRPC service annotation code. In this embodiment, the annotation is @GrpcServer. The attributes of the @GrpcServer annotation are value (service name, type is String), interceptor (interceptor class Class, which must implement the io.grpc.ServerInterceptor interface. If this attribute is not set, it means that the service has no interceptor binding, otherwise it means that the service is bound to the interceptor), interceptMethods (a list of method names to be intercepted. If this attribute is not set, all methods of the service class are intercepted, otherwise the methods in the method name list to be intercepted of the service class are intercepted; this attribute must be set to take effect).

[0095] In this embodiment, the service registration request also includes a transaction to be intercepted (for example, determining whether the caller IP is in the system whitelist), and the service definition code is generated based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, including:

[0096] A21. Generate a first definition code based on the name of the interceptor to be registered and the transaction to be intercepted;

[0097] In this embodiment, the interceptor class name xxxServerInterceptor can be determined according to the name of the interceptor to be registered. The xxxServerInterceptor interceptor class needs to inherit the io.grpc.ServerInterceptor interface class. The corresponding interception business code can be generated according to the transaction to be intercepted, and the first definition code is obtained after aggregation.

[0098] A22, generating a second definition code based on the name of the service to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered;

[0099] The service class name xxxServer can be determined according to the name of the service to be registered. The xxxServer service class needs to inherit the io.grpc.BindableService interface class. Add the annotation @GrpcServer to the xxxServer service class, and set relevant properties according to the binding relationship between the service to be registered and the interceptor to be registered and the list of method names to be intercepted of the service to be registered. After summarizing, the second definition code is obtained.

[0100] A23. Combine the first definition code and the second definition code to obtain a service definition code.

[0101] The scanning module 130 is used to fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration operations and binding operations on the service to be registered and the interceptor to be registered.

[0102] In this embodiment, the scanning of the annotation identifier in the main program code and the performing of the registration operation and the binding operation on the service to be registered and the interceptor to be registered include:

[0103] B21, scanning the program segments carrying annotation marks in the main program code, and performing correctness verification on the program segments;

[0104] The correctness check includes checking whether the service class in the program segment inherits the io.grpc.BindableService interface class, checking whether the interceptor class inherits the io.grpc.ServerInterceptor interface class, and checking the syntax correctness.

[0105] B22. When the verification passes, interception data is generated based on the program segment, and registration and binding operations are performed on the service to be registered and the interceptor to be registered based on the interception data.

[0106] In this embodiment, the interception data sample is as follows:

[0107] / / Structure definition of interception data

[0108] struct GrpcServer {

[0109] serverClass, / / Service class

[0110] i nterceptorClass, / / Interceptor class

[0111] interceptMethods / / To intercept the method name list under the service class

[0112] }

[0113] In this embodiment, the service and interceptor in the interception data are registered and bound to the system in a loop by calling the serverBuilder.addService method provided by the gRPC framework.

[0114] The existing gRPC framework needs to gradually add registration code and binding code for each service and interceptor when adding registration services and binding interceptors. When more services are added, the amount of code is relatively large. In this embodiment, there is only one line of code corresponding to the registration and binding operations. When adding service registration and binding interceptors, you only need to add an annotation identifier in front of the corresponding service definition code and set related properties. When deleting a service or unbinding an interceptor, you only need to delete the annotation identifier or delete the properties in the annotation. This embodiment makes the code more maintainable and easier to expand.

[0115] In this embodiment, after performing the correctness check on the program segment, the scanning module 130 is further used to:

[0116] If the verification fails, the program segment is marked and a warning message is sent to the client.

[0117] The interception module 140 is used to monitor the call request for the target application in real time, obtain one or more names of the service to be called and the names of the method to be called carried in the call request, and perform interception processing on the call request based on the name of the service to be called and the name of the method to be called.

[0118] The intercepting process of the calling request based on the name of the service to be called and the name of the method to be called includes:

[0119] C21. Determine whether each service to be called is bound to an interceptor;

[0120] This embodiment can determine whether the service to be called is bound to an interceptor based on the interception data generated by the program segment.

[0121] C22. When it is determined that a certain designated service to be called is bound to an interceptor, it is determined whether the method to be called of the designated service to be called exists in the method name list to be intercepted of the designated service to be called;

[0122] C23. When it is determined that the method exists in the list of method names to be intercepted of the specified service to be called, interception processing is performed on the call request.

[0123] After intercepting the call request, the corresponding business processing can be performed according to the interception business code corresponding to the transaction to be intercepted. Unlike the existing gRPC framework that can only intercept to the service granularity (can only intercept all methods under the service), this step realizes refined interception and can intercept any specified method in the service's method name list to be intercepted.

[0124] In this embodiment, after determining whether each service to be called is bound to an interceptor, the interception module 140 is further used to:

[0125] If it is determined that each service to be called is not bound to an interceptor or the method to be called of the specified service to be called does not exist in the method name list to be intercepted of the specified service to be called, the calling operation corresponding to the calling request is executed.

[0126] like Figure 3 , which is a schematic diagram of the structure of an electronic device for implementing a service registration and interception method provided by an embodiment of the present invention.

[0127] The electronic device 1 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The electronic device 1 can be a computer, a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of hosts or network servers, wherein cloud computing is a type of distributed computing, a super virtual computer composed of a group of loosely coupled computer sets.

[0128] In this embodiment, the electronic device 1 includes, but is not limited to, a memory 11, a processor 12, and a network interface 13, which can be interconnected and communicated via a system bus. The memory 11 stores a service registration and interception program 10, which can be executed by the processor 12. Figure 3 Only the electronic device 1 having components 11-13 and the service registration and interception program 10 is shown. It can be understood by those skilled in the art that Figure 3The structure shown does not constitute a limitation on the electronic device 1 , and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.

[0129] Among them, the memory 11 includes a memory and at least one type of readable storage medium. The memory provides a cache for the operation of the electronic device 1; the readable storage medium may be a non-volatile storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the readable storage medium may be an internal storage unit of the electronic device 1, such as a hard disk of the electronic device 1; in other embodiments, the non-volatile storage medium may also be an external storage device of the electronic device 1, such as a plug-in hard disk equipped on the electronic device 1, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. In this embodiment, the readable storage medium of the memory 11 is generally used to store an operating system and various application software installed on the electronic device 1, such as storing the code of the service registration and interception program 10 in an embodiment of the present invention. In addition, the memory 11 can also be used to temporarily store various types of data that have been output or are to be output.

[0130] In some embodiments, the processor 12 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 12 is generally used to control the overall operation of the electronic device 1, such as performing control and processing related to data interaction or communication with other devices. In this embodiment, the processor 12 is used to run the program code stored in the memory 11 or process data, such as running the service registration and interception program 10.

[0131] The network interface 13 may include a wireless network interface or a wired network interface, and the network interface 13 is used to establish a communication connection between the electronic device 1 and a client (not shown in the figure).

[0132] Optionally, the electronic device 1 may further include a user interface, which may include a display (Display), an input unit such as a keyboard (Keyboard), and the optional user interface may also include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.

[0133] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.

[0134] The service registration and interception program 10 stored in the memory 11 of the electronic device 1 is a combination of multiple instructions. When running in the processor 12, it can achieve:

[0135] Parse the service registration request for the target application issued by the user based on the client, and obtain the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered carried in the service registration request;

[0136] Obtain a predetermined annotation definition code from a database, and generate a service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, wherein the service definition code includes an annotation identifier;

[0137] Fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration and binding operations on the service to be registered and the interceptor to be registered;

[0138] Monitor the call request for the target application in real time, obtain one or more service names to be called and method names to be called carried in the call request, and perform interception processing on the call request based on the service names to be called and method names to be called.

[0139] Specifically, the specific implementation method of the processor 12 for the above service registration and interception program 10 can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.

[0140] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable medium can be non-volatile or non-volatile. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).

[0141] The computer-readable storage medium stores a service registration and interception program 10, which can be executed by one or more processors. The specific implementation method of the computer-readable storage medium of the present invention is basically the same as the above-mentioned service registration and interception method embodiments, and will not be repeated here.

[0142] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.

[0143] 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 modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0144] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.

[0145] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0146] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.

[0147] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system claim can also be implemented by one unit or device through software or hardware. The second and other words are used to indicate names, but not to indicate any particular order.

[0148] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.

Claims

1. A service registration and interception method, characterized in that: The method comprises: Parse the service registration request for the target application issued by the user based on the client, and obtain the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered carried in the service registration request; Obtain a predetermined annotation definition code from a database, and generate a service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, wherein the service definition code includes an annotation identifier, and the annotation definition code is a gRPC service annotation code. The service definition code adds an annotation identifier to the service name, the interceptor class Class, and the list of method names to be intercepted through the annotation definition code; Fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration and binding operations on the service to be registered and the interceptor to be registered; Monitor the call request for the target application in real time, obtain one or more service names to be called and method names to be called carried in the call request, and perform interception processing on the call request based on the service names to be called and method names to be called.

2. The service registration and interception method according to claim 1, characterized in that: The service registration request also includes a transaction to be intercepted, and the generating of the service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered includes: Generate a first definition code based on the name of the interceptor to be registered and the transaction to be intercepted; Generate a second definition code based on the name of the service to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered; The first definition code and the second definition code are combined to obtain a service definition code.

3. The service registration and interception method according to claim 1, characterized in that: The scanning of the annotation identifier in the main program code and performing registration and binding operations on the service to be registered and the interceptor to be registered include: Scanning program segments with annotation marks in the main program code and performing correctness verification on the program segments; When the verification is passed, interception data is generated based on the program segment, and registration operations and binding operations are performed on the service to be registered and the interceptor to be registered based on the interception data.

4. The service registration and interception method according to claim 3, characterized in that: After performing a correctness check on the program segment, the method further includes: If the verification fails, the program segment is marked and a warning message is sent to the client.

5. The service registration and interception method according to claim 1, characterized in that: The intercepting process of the calling request based on the name of the service to be called and the name of the method to be called includes: Determine whether each service to be called is bound to an interceptor; When it is determined that a certain designated service to be called is bound to an interceptor, it is determined whether the method to be called of the designated service to be called exists in the method name list to be intercepted of the designated service to be called; When it is determined that the method exists in the list of method names to be intercepted of the specified service to be called, interception processing is performed on the call request.

6. The service registration and interception method according to claim 5, characterized in that: After determining whether each service to be called is bound to an interceptor, the method further includes: If it is determined that each service to be called is not bound to an interceptor or the method to be called of the specified service to be called does not exist in the method name list to be intercepted of the specified service to be called, the calling operation corresponding to the calling request is executed.

7. A service registration and interception device, characterized in that: The device comprises: A parsing module is used to parse the service registration request for the target application issued by the user based on the client, and obtain the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered; A generation module, used to obtain a predetermined annotation definition code from a database, and generate a service definition code based on the name of the service to be registered, the name of the interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the list of method names to be intercepted of the service to be registered, wherein the service definition code includes an annotation identifier, the annotation definition code is a gRPC service annotation code, and the service definition code adds an annotation identifier to the service name, the interceptor class Class, and the list of method names to be intercepted through the annotation definition code; A scanning module, used to fill the annotation definition code and the service definition code into the main program code corresponding to the target application, scan the annotation identifier in the main program code, and perform registration operations and binding operations on the service to be registered and the interceptor to be registered; The interception module is used to monitor the call request for the target application in real time, obtain one or more names of the service to be called and the names of the method to be called carried in the call request, and perform interception processing on the call request based on the name of the service to be called and the name of the method to be called.

8. The service registration and interception device according to claim 7, characterized in that: The scanning of the annotation identifier in the main program code and performing registration and binding operations on the service to be registered and the interceptor to be registered include: Scanning program segments with annotation marks in the main program code and performing correctness verification on the program segments; When the verification is passed, interception data is generated based on the program segment, and registration operations and binding operations are performed on the service to be registered and the interceptor to be registered based on the interception data.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a service registration and interception program that can be executed by the at least one processor, and the service registration and interception program is executed by the at least one processor so that the at least one processor can execute the service registration and interception method as described in any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a service registration and interception program, which can be executed by one or more processors to implement the service registration and interception method as described in any one of claims 1 to 6.