CN112596932A - Service registration and interception method and device, electronic equipment and readable storage medium - Google Patents

Service registration and interception method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN112596932A
CN112596932A CN202110020904.0A CN202110020904A CN112596932A CN 112596932 A CN112596932 A CN 112596932A CN 202110020904 A CN202110020904 A CN 202110020904A CN 112596932 A CN112596932 A CN 112596932A
Authority
CN
China
Prior art keywords
service
registered
interceptor
name
called
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110020904.0A
Other languages
Chinese (zh)
Inventor
李永伦
许文彬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianmian Information Technology Shenzhen Co ltd
Original Assignee
Tianmian Information Technology Shenzhen Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tianmian Information Technology Shenzhen Co ltd filed Critical Tianmian Information Technology Shenzhen Co ltd
Priority to CN202110020904.0A priority Critical patent/CN112596932A/en
Publication of CN112596932A publication Critical patent/CN112596932A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to data processing, and discloses a service registration and interception method, which comprises the following steps: obtaining an annotation definition code, and generating 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 name list of the method to be intercepted of the service to be registered, wherein the service definition code comprises an annotation identifier; filling the annotation definition code and the service definition code into a main program code corresponding to a target application program, scanning an annotation identifier in the main program code, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered; and executing interception processing on the calling request based on one or more service names to be called carried by the calling request and the names of the methods to be called. The invention also provides a service registration and interception device, electronic equipment and a readable storage medium. The invention improves the expandability and maintainability of the code and realizes the fine-grained interception.

Description

Service registration and interception method and device, electronic equipment and readable storage medium
Technical Field
The present invention relates to the field of data processing, and in particular, to a method and an apparatus for registering and intercepting a service, an electronic device, and a readable storage medium.
Background
With the development of science and technology, communication is more and more widely applied in people's life. A gRPC (Google Remote Procedure Call) framework is a basic network communication component, and relates to registration of services, registration of an interceptor, and binding of the services and the interceptor in a communication process, whereas the existing gRPC framework needs to write corresponding registration codes and binding codes one by one, which is difficult to expand, and if more services need to be registered, the existing gRPC framework causes the codes to be too bulky and difficult to maintain, and intercepts all methods under the services, cannot intercept a specified method, and cannot realize fine-grained interception. Therefore, a method for registering and intercepting services is needed to improve the scalability and maintainability of codes and to achieve fine-grained interception.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a service registration and interception method, which aims to improve the scalability and maintainability of code and to achieve fine-grained interception.
The service registration and interception method provided by the invention comprises the following steps:
analyzing a service registration request aiming at a target application program sent by a user based on a client, and acquiring a service name to be registered, an interceptor name to be registered, a binding relationship between the service to be registered and the interceptor to be registered and a name list of a method to be intercepted of the service to be registered, wherein the service name to be registered, the interceptor name to be registered, the binding relationship between the service to be registered and the interceptor to be registered and the name list of the method;
acquiring a predetermined annotation definition code from a database, and generating a service definition code based on the name of the service to be registered, the name of an interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and a list of names of methods to be intercepted of the service to be registered, wherein the service definition code comprises an annotation identifier;
filling the annotation definition code and the service definition code into a main program code corresponding to the target application program, scanning an annotation identifier in the main program code, and performing registration operation and binding operation on the service to be registered and the interceptor to be registered;
monitoring a calling request aiming at the target application program in real time, acquiring one or more names of services to be called and names of methods to be called carried by the calling request, and executing interception processing on the calling request based on the names of the services to be called and the names of the methods to be called.
Optionally, the service registration request further includes a transaction to be intercepted, and generating 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 name list of the method to be intercepted of the service to be registered includes:
generating a first definition code based on the name of the interceptor to be registered and the transaction to be intercepted;
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 a list of names of methods to be intercepted of the service to be registered;
and merging the first definition code and the second definition code to obtain a service definition code.
Optionally, the scanning the annotation identifier in the main program code, and performing a registration operation and a binding operation on the service to be registered and the interceptor to be registered includes:
scanning a program segment carrying an annotation identifier in the main program code, and performing correctness check on the program segment;
and when the verification passes, generating interception data based on the program segment, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered based on the interception data.
Optionally, after performing correctness checking on the program segment, the method further includes:
and if the verification fails, identifying the program segment and sending early warning information to the client.
Optionally, the performing, based on the name of the service to be called and the name of the method to be called, interception processing on the call request includes:
judging whether each service to be called is bound with an interceptor;
when judging that a certain specified service to be called is bound with an interceptor, judging whether a method to be called of the specified service to be called exists in a list of names of methods to be intercepted of the specified service to be called;
and when judging that the method exists in the list of the names of the methods to be intercepted of the appointed service to be called, executing interception processing on the calling request.
Optionally, after determining whether each service to be called is bound to an interceptor, the method further includes:
and if judging that each service to be called is not bound with an interceptor or the method to be called of the appointed service to be called does not exist in the name list of the method to be intercepted of the appointed service to be called, executing the calling operation corresponding to the calling request.
In order to solve the above problem, the present invention further provides a service registration and interception apparatus, including:
the system comprises an analysis module, a service registration module and a service registration module, wherein the analysis module is used for analyzing a service registration request aiming at a target application program sent by a user based on a client, and acquiring a name of a service to be registered, a name of an interceptor to be registered, a binding relation between the service to be registered and the interceptor to be registered and a name list of a method to be intercepted of the service to be registered, which are carried by the service registration request;
the generation module is used for acquiring a predetermined annotation definition code from a database, and generating 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 a name list of a method to be intercepted of the service to be registered, wherein the service definition code comprises an annotation identifier;
the scanning module is used for filling the annotation definition codes and the service definition codes into main program codes corresponding to the target application program, scanning annotation identifications in the main program codes, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered;
and the intercepting module is used for monitoring the calling request aiming at the target application program in real time, acquiring one or more names of the service to be called and the name of the method to be called carried by the calling request, and executing intercepting processing on the calling request based on the name of the service to be called and the name of the method to be called.
Optionally, the scanning the annotation identifier in the main program code, and performing a registration operation and a binding operation on the service to be registered and the interceptor to be registered includes:
scanning a program segment carrying an annotation identifier in the main program code, and performing correctness check on the program segment;
and when the verification passes, generating interception data based on the program segment, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered based on the interception data.
In order to solve the above problem, the present invention also provides an electronic device, including:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores a service registration and interception program executable by the at least one processor, the service registration and interception program being executed by the at least one processor to enable the at least one processor to perform the above-mentioned service registration and interception method.
In order to solve the above problem, the present invention further provides a computer-readable storage medium, on which a service registration and interception program is stored, where the service registration and interception program is executable by one or more processors to implement the service registration and interception method.
Compared with the prior art, the method comprises the steps of firstly obtaining annotation definition codes, and generating the service definition codes based on the names of the services to be registered, the names of the interceptors to be registered, the binding relationship between the services to be registered and the interceptors to be registered and the name list of the methods to be intercepted of the services to be registered, wherein the service definition codes comprise annotation identifications; then, filling the annotation definition code and the service definition code into a main program code corresponding to the target application program, scanning an annotation identifier in the main program code, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered; and finally, performing interception processing on the calling request based on the name of the service to be called carried by the calling request and the name of the method to be called. According to the scheme, the registration of the service, the registration of the interceptor and the binding of the service and the interceptor can be realized only by marking the annotation identifier in the service definition code corresponding to the service to be registered, so that the expandability and maintainability of the code are improved; by adding the list of the names of the methods to be intercepted of the services in the service definition codes, the technical problem that the existing gRPC can only intercept all methods under the services but cannot intercept the specified method under the services is solved, and fine interception is realized. Therefore, the invention improves the expandability and maintainability of the code and realizes the fine-grained interception.
Drawings
Fig. 1 is a schematic flowchart of a service registration and interception method according to an embodiment of the present invention;
fig. 2 is a block diagram of a service registration and interception apparatus according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of an electronic device implementing a service registration and interception method according to an embodiment of the present invention;
the implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the description relating to "first", "second", etc. in the present invention is for descriptive purposes only and is not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In addition, technical solutions between various embodiments may be combined with each other, but must be realized by a person skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present invention.
The invention provides a service registration and interception method. Fig. 1 is a schematic flow chart illustrating a service registration and interception method according to an embodiment of the present invention. The method may be performed by an electronic device, which may be implemented by software and/or hardware.
In this embodiment, the service registration and interception method includes:
s1, analyzing a service registration request aiming at a target application program sent by a user based on a client, and acquiring a service name to be registered, an interceptor name to be registered, a binding relationship between the service to be registered and the interceptor to be registered and a name list of a method to be intercepted of the service to be registered, wherein the service name to be registered, the interceptor name to be registered, the binding relationship between the service to be registered and the interceptor to be registered and the name list of the method.
The target application program can be a communication APP, and the target application program adopts a gRPC framework for communication. gPC is a general RPC framework, designed for mobile and HTTP/2, supporting C, Java and Go language versions, and the framework adopts a protobuf (protobuf is a platform-independent, language-independent, extensible, lightweight and efficient protocol of a serialized data structure, and the protocol is a proto suffix file saving) binary message serialization and deserialization structure.
Services (namely service classes), which are defined by service keywords in the proto file, and the JAVA version generated by the proto file is a class inheriting an io, grpc and Bindablervice interface; a service may be simply understood as an interface through which the system provides access to the outside.
The interceptor (i.e., interceptor class) includes a client interceptor and a server interceptor in the gRPC framework, and the interceptor in this embodiment is a server interceptor, which implements an io.grpc.server interceptor interface class as a server interceptor. The interceptor can be understood as performing pre-check work before calling the service (the pre-check work to be performed by the interceptor after intercepting the call request can be specifically set according to a service scene), for example, 1, when a caller accesses a service which can be accessed only after logging in, the interceptor can intercept the request of the caller first, judge whether the caller logs in, and if not, disallow to access the corresponding service; for example, 2, the system requests the caller's IP address to be in the system's IP white list before allowing access to the service, the interceptor may be used to intercept the caller's request first, then determine whether the caller's IP is in the system white list, deny access to the service if not, and allow access otherwise.
Methods are used to accomplish something or perform a function (e.g., control input or calculate a value), and typically have a return value used as a result of a process or calculation.
S2, obtaining predetermined annotation definition codes from a database, and generating service definition codes based on the service name 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 name list of the method to be intercepted of the service to be registered, wherein the service definition codes comprise annotation identifiers.
The annotation definition code is a user-defined gRPC service annotation code, in this embodiment, the annotation is @ GrpServer, the attribute of the @ GrpServer annotation includes value (service name, type is String), interrupt (interceptor Class, i.e. i.grpc.Server interface is required to be realized, if the attribute is not set, the service is bound without an interceptor, otherwise, the service is bound with the interceptor), interrupt methods (list of method names to be intercepted, if the attribute is not set, all methods of the service Class are intercepted, otherwise, the methods in the list of method names to be intercepted of the service Class are intercepted, and the attribute is effective only when the attribute is set).
In this embodiment, the service registration request further includes a transaction to be intercepted (for example, it is determined whether a caller IP is in a system white list), and the generating a service definition code based on the name of the service to be registered, the name of an interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the name list of a method to be intercepted of the service to be registered includes:
a11, generating a first definition code based on the name of the interceptor to be registered and the transaction to be intercepted;
in this embodiment, the name of the interceptor class xxxserverInterreceptor may be determined according to the name of the interceptor to be registered, and the name of the interceptor class xxxserverInterreceptor needs to inherit the io.grpc.ServerInterreceptor interface class, and corresponding intercepted service codes may be generated according to the transaction to be intercepted, and the first definition code is obtained after the interception service codes are summarized.
A12, generating a second definition code based on the service name to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the name list of the method to be intercepted of the service to be registered;
determining a service class name xxxServer according to the name of the service to be registered, wherein the xxxServer service class needs to inherit an io.grpc.BindableService interface class, adding an annotation identifier @ GrpcServer on the xxxServer service class, setting relevant attributes according to the binding relationship between the service to be registered and the interceptor to be registered and a list of names of methods to be intercepted of the service to be registered, and obtaining a second definition code after summarizing.
And A13, merging the first definition code and the second definition code to obtain the service definition code.
S3, filling the annotation definition code and the service definition code into the main program code corresponding to the target application program, scanning the annotation mark in the main program code, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered.
In this embodiment, the scanning the annotation identifier in the main program code, and performing registration operation and binding operation on the service to be registered and the interceptor to be registered includes:
b11, scanning the program segment carrying the annotation mark in the main program code, and performing correctness check on the program segment;
the correctness checking comprises checking whether a service class in the program segment inherits an io.grpc.BindableService interface class, checking whether an interceptor class inherits an io.grpc.ServerInterreceptor interface class and checking the syntax correctness.
And B12, when the verification is passed, generating interception data based on the program segment, and performing registration operation and binding operation on the service to be registered and the interceptor to be registered based on the interception data.
In this embodiment, the example of intercepting data is as follows:
structural definition of intercepted data
struct GrpcServer{
serverlass,// service class
interceptorClass,// interceptor class
Intercept methods// list of names of methods under the class of service to be intercepted
}
In this embodiment, services and interceptors in the intercepted data are registered and bound to the system by calling a server builder.
When the existing gPC framework needs to add registration service and binding interceptors, registration codes and binding codes of each service and interceptor need to be added step by step, when the added services are more, the code amount is huge, in the embodiment, the codes corresponding to the registration and binding operations are only one line, when the service registration and binding interceptors need to be added, only annotation identification needs to be added before the corresponding service definition codes and relevant attributes are set, and only the attribute in the annotation needs to be deleted or deleted when the service or the binding interceptors are deleted, so that the code maintainability is stronger and the code maintainability is easier to expand.
In this embodiment, after performing correctness check on the program segment, the method further includes:
and if the verification fails, identifying the program segment and sending early warning information to the client.
S4, monitoring the call request aiming at the target application program in real time, acquiring one or more names of the service to be called and the name of the method to be called carried by the call request, and executing 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.
The executing interception processing on the calling request based on the name of the service to be called and the name of the method to be called comprises the following steps:
c11, judging whether each service to be called is bound with an interceptor;
the embodiment can judge whether the service to be called is bound with the interceptor according to the interception data generated by the program segment.
C12, when judging that an interceptor is bound to a certain specified service to be called, judging whether the method to be called of the specified service to be called exists in a name list of the method to be intercepted of the specified service to be called;
and C13, when judging that the method exists in the list of the names of the methods to be intercepted of the appointed service to be called, executing interception processing on the calling request.
After the call request is intercepted, corresponding business processing can be executed according to the intercepted business code corresponding to the transaction to be intercepted. Different from the existing gPC framework which can only intercept the service granularity (only intercept all methods under the service), the step realizes the refined interception and can intercept any specified method in the list of the names of the methods to be intercepted of the service.
In this embodiment, after determining whether each service to be called is bound to an interceptor, the method further includes:
and if judging that each service to be called is not bound with an interceptor or the method to be called of the appointed service to be called does not exist in the name list of the method to be intercepted of the appointed service to be called, executing the calling operation corresponding to the calling request.
As can be seen from the above embodiments, the service registration and interception method provided by the present invention includes first obtaining an annotation definition code, and generating a service definition code based on a name of a service to be registered, a name of an interceptor to be registered, a binding relationship between the service to be registered and the interceptor to be registered, and a list of names of methods to be intercepted of the service to be registered, where the service definition code includes an annotation identifier; then, filling the annotation definition code and the service definition code into a main program code corresponding to the target application program, scanning an annotation identifier in the main program code, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered; and finally, performing interception processing on the calling request based on the name of the service to be called carried by the calling request and the name of the method to be called. According to the scheme, the registration of the service, the registration of the interceptor and the binding of the service and the interceptor can be realized only by marking the annotation identifier in the service definition code corresponding to the service to be registered, so that the expandability and maintainability of the code are improved; by adding the list of the names of the methods to be intercepted of the services in the service definition codes, the technical problem that the existing gRPC can only intercept all methods under the services but cannot intercept the specified method under the services is solved, and fine interception is realized. Therefore, the invention improves the expandability and maintainability of the code and realizes the fine-grained interception.
Fig. 2 is a schematic block diagram of a service registration and interception apparatus according to an embodiment of the present invention.
The service registration and interception apparatus 100 of the present invention may be installed in an electronic device. According to the implemented functions, the service registration and interception apparatus 100 may include an analysis module 110, a generation module 120, a scanning module 130, and an interception module 140. The module of the present invention, which may also be referred to as a unit, refers to a series of computer program segments that can be executed by a processor of an electronic device and that can perform a fixed function, and that are stored in a memory of the electronic device.
In the present embodiment, the functions regarding the respective modules/units are as follows:
the analysis module 110 is configured to analyze a service registration request, which is sent by a user based on a client and is directed to a target application, and obtain a name of a service to be registered, a name of an interceptor to be registered, a binding relationship between the service to be registered and the interceptor to be registered, and a name list of a method to be intercepted of the service to be registered, which are carried in the service registration request.
The target application program can be a communication APP, and the target application program adopts a gRPC framework for communication. gPC is a general RPC framework, designed for mobile and HTTP/2, supporting C, Java and Go language versions, and the framework adopts a protobuf (protobuf is a platform-independent, language-independent, extensible, lightweight and efficient protocol of a serialized data structure, and the protocol is a proto suffix file saving) binary message serialization and deserialization structure.
Services (namely service classes), which are defined by service keywords in the proto file, and the JAVA version generated by the proto file is a class inheriting an io, grpc and Bindablervice interface; a service may be simply understood as an interface through which the system provides access to the outside.
The interceptor (i.e., interceptor class) includes a client interceptor and a server interceptor in the gRPC framework, and the interceptor in this embodiment is a server interceptor, which implements an io.grpc.server interceptor interface class as a server interceptor. The interceptor can be understood as performing pre-check work before calling the service (the pre-check work to be performed by the interceptor after intercepting the call request can be specifically set according to a service scene), for example, 1, when a caller accesses a service which can be accessed only after logging in, the interceptor can intercept the request of the caller first, judge whether the caller logs in, and if not, disallow to access the corresponding service; for example, 2, the system requests the caller's IP address to be in the system's IP white list before allowing access to the service, the interceptor may be used to intercept the caller's request first, then determine whether the caller's IP is in the system white list, deny access to the service if not, and allow access otherwise.
Methods are used to accomplish something or perform a function (e.g., control input or calculate a value), and typically have a return value used as a result of a process or calculation.
The generating module 120 is configured 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 names of methods to be intercepted of the service to be registered, where the service definition code includes an annotation identifier.
The annotation definition code is a user-defined gRPC service annotation code, in this embodiment, the annotation is @ GrpServer, the attribute of the @ GrpServer annotation includes value (service name, type is String), interrupt (interceptor Class, i.e. i.grpc.Server interface is required to be realized, if the attribute is not set, the service is bound without an interceptor, otherwise, the service is bound with the interceptor), interrupt methods (list of method names to be intercepted, if the attribute is not set, all methods of the service Class are intercepted, otherwise, the methods in the list of method names to be intercepted of the service Class are intercepted, and the attribute is effective only when the attribute is set).
In this embodiment, the service registration request further includes a transaction to be intercepted (for example, it is determined whether a caller IP is in a system white list), and the generating a service definition code based on the name of the service to be registered, the name of an interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the name list of a method to be intercepted of the service to be registered includes:
a21, generating a first definition code based on the name of the interceptor to be registered and the transaction to be intercepted;
in this embodiment, the name of the interceptor class xxxserverInterreceptor may be determined according to the name of the interceptor to be registered, and the name of the interceptor class xxxserverInterreceptor needs to inherit the io.grpc.ServerInterreceptor interface class, and corresponding intercepted service codes may be generated according to the transaction to be intercepted, and the first definition code is obtained after the interception service codes are summarized.
A22, generating a second definition code based on the service name to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and the name list of the method to be intercepted of the service to be registered;
determining a service class name xxxServer according to the name of the service to be registered, wherein the xxxServer service class needs to inherit an io.grpc.BindableService interface class, adding an annotation identifier @ GrpcServer on the xxxServer service class, setting relevant attributes according to the binding relationship between the service to be registered and the interceptor to be registered and a list of names of methods to be intercepted of the service to be registered, and obtaining a second definition code after summarizing.
And A23, merging the first definition code and the second definition code to obtain the service definition code.
The scanning module 130 is configured to fill the annotation definition code and the service definition code into a main program code corresponding to the target application program, scan an annotation identifier in the main program code, and perform a registration operation and a binding operation on the service to be registered and the interceptor to be registered.
In this embodiment, the scanning the annotation identifier in the main program code, and performing registration operation and binding operation on the service to be registered and the interceptor to be registered includes:
b21, scanning the program segment carrying the annotation mark in the main program code, and performing correctness check on the program segment;
the correctness checking comprises checking whether a service class in the program segment inherits an io.grpc.BindableService interface class, checking whether an interceptor class inherits an io.grpc.ServerInterreceptor interface class and checking the syntax correctness.
And B22, when the verification is passed, generating interception data based on the program segment, and performing registration operation and binding operation on the service to be registered and the interceptor to be registered based on the interception data.
In this embodiment, the example of intercepting data is as follows:
structural definition of intercepted data
struct GrpcServer{
serverlass,// service class
interceptorClass,// interceptor class
Intercept methods// list of names of methods under the class of service to be intercepted
}
In this embodiment, services and interceptors in the intercepted data are registered and bound to the system by calling a server builder.
When the existing gPC framework needs to add registration service and binding interceptors, registration codes and binding codes of each service and interceptor need to be added step by step, when the added services are more, the code amount is huge, in the embodiment, the codes corresponding to the registration and binding operations are only one line, when the service registration and binding interceptors need to be added, only annotation identification needs to be added before the corresponding service definition codes and relevant attributes are set, and only the attribute in the annotation needs to be deleted or deleted when the service or the binding interceptors are deleted, so that the code maintainability is stronger and the code maintainability is easier to expand.
In this embodiment, after performing correctness check on the program segment, the scanning module 130 is further configured to:
and if the verification fails, identifying the program segment and sending early warning information to the client.
The intercepting module 140 is configured to monitor, in real time, a call request for the target application program, obtain one or more names of services to be called and names of methods to be called carried by the call request, and perform intercepting processing on the call request based on the names of the services to be called and the names of the methods to be called.
The executing interception processing on the calling request based on the name of the service to be called and the name of the method to be called comprises the following steps:
c21, judging whether each service to be called is bound with an interceptor;
the embodiment can judge whether the service to be called is bound with the interceptor according to the interception data generated by the program segment.
C22, when judging that an interceptor is bound to a certain specified service to be called, judging whether the method to be called of the specified service to be called exists in a name list of the method to be intercepted of the specified service to be called;
and C23, when judging that the method exists in the list of the names of the methods to be intercepted of the appointed service to be called, executing interception processing on the calling request.
After the call request is intercepted, corresponding business processing can be executed according to the intercepted business code corresponding to the transaction to be intercepted. Different from the existing gPC framework which can only intercept the service granularity (only intercept all methods under the service), the step realizes the refined interception and can intercept any specified method in the list of the names of the methods to be intercepted of the service.
In this embodiment, after determining whether each service to be called is bound to an interceptor, the intercepting module 140 is further configured to:
and if judging that each service to be called is not bound with an interceptor or the method to be called of the appointed service to be called does not exist in the name list of the method to be intercepted of the appointed service to be called, executing the calling operation corresponding to the calling request.
Fig. 3 is a schematic structural diagram of an electronic device for implementing a service registration and interception method according to an embodiment of the present invention.
The electronic device 1 is a device capable of automatically performing numerical calculation and/or information processing in accordance with a command set or stored in advance. The electronic device 1 may be a computer, or may be a single network server, a server group composed of a plurality of network servers, or a cloud composed of a large number of hosts or network servers based on cloud computing, where cloud computing is one of distributed computing and is a super virtual computer composed of a group of loosely coupled computers.
In the embodiment, the electronic device 1 includes, but is not limited to, a memory 11, a processor 12, and a network interface 13 communicatively connected to each other through a system bus, the memory 11 stores a service registration and interception program 10, and the service registration and interception program 10 can be executed by the processor 12. Fig. 3 only shows the electronic device 1 with the components 11-13 and the service registration and interception program 10, and it will be understood by those skilled in the art that the structure shown in fig. 3 does not constitute a limitation of the electronic device 1, and may comprise fewer or more components than shown, or some components may be combined, or a different arrangement of components.
The storage 11 includes a memory and at least one type of readable storage medium. The memory provides cache for the operation of the electronic equipment 1; the readable storage medium may be a non-volatile storage medium such as 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 magnetic 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 provided on the electronic device 1, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. In this embodiment, the readable storage medium of the memory 11 is generally used for storing an operating system and various application software installed in the electronic device 1, for example, codes of the service registration and interception program 10 in an embodiment of the present invention. Further, the memory 11 may also be used to temporarily store various types of data that have been output or are to be output.
Processor 12 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 12 is generally configured 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 configured to run the program code stored in the memory 11 or process data, such as running the service registration and interception program 10.
The network interface 13 may comprise a wireless network interface or a wired network interface, and the network interface 13 is used for establishing a communication connection between the electronic device 1 and a client (not shown).
Optionally, the electronic device 1 may further include a user interface, the user interface may include a Display (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface may further include a standard wired interface and a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable for displaying information processed in the electronic device 1 and for displaying a visualized user interface, among other things.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
The service registration and interception program 10 stored in the memory 11 of the electronic device 1 is a combination of instructions that, when executed in the processor 12, can implement:
analyzing a service registration request aiming at a target application program sent by a user based on a client, and acquiring a service name to be registered, an interceptor name to be registered, a binding relationship between the service to be registered and the interceptor to be registered and a name list of a method to be intercepted of the service to be registered, wherein the service name to be registered, the interceptor name to be registered, the binding relationship between the service to be registered and the interceptor to be registered and the name list of the method;
acquiring a predetermined annotation definition code from a database, and generating a service definition code based on the name of the service to be registered, the name of an interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and a list of names of methods to be intercepted of the service to be registered, wherein the service definition code comprises an annotation identifier;
filling the annotation definition code and the service definition code into a main program code corresponding to the target application program, scanning an annotation identifier in the main program code, and performing registration operation and binding operation on the service to be registered and the interceptor to be registered;
monitoring a calling request aiming at the target application program in real time, acquiring one or more names of services to be called and names of methods to be called carried by the calling request, and executing interception processing on the calling request based on the names of the services to be called and the names of the methods to be called.
Specifically, the processor 12 may refer to the description of the relevant steps in the embodiment corresponding to fig. 1 for a specific implementation method of the service registration and interception program 10, which is not described herein again.
Further, the integrated modules/units of the electronic device 1, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. The computer readable medium may be non-volatile or non-volatile. The computer-readable medium may include: any entity or device capable of carrying said computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM).
The computer-readable storage medium stores a service registration and interception program 10, and the service registration and interception program 10 can be executed by one or more processors, and the specific implementation of the computer-readable storage medium of the present invention is substantially the same as that of each embodiment of the service registration and interception method, and is not described herein again.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the system claims may also be implemented by one unit or means in software or hardware. The terms second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims (10)

1. A service registration and interception method is characterized by comprising the following steps:
analyzing a service registration request aiming at a target application program sent by a user based on a client, and acquiring a service name to be registered, an interceptor name to be registered, a binding relationship between the service to be registered and the interceptor to be registered and a name list of a method to be intercepted of the service to be registered, wherein the service name to be registered, the interceptor name to be registered, the binding relationship between the service to be registered and the interceptor to be registered and the name list of the method;
acquiring a predetermined annotation definition code from a database, and generating a service definition code based on the name of the service to be registered, the name of an interceptor to be registered, the binding relationship between the service to be registered and the interceptor to be registered, and a list of names of methods to be intercepted of the service to be registered, wherein the service definition code comprises an annotation identifier;
filling the annotation definition code and the service definition code into a main program code corresponding to the target application program, scanning an annotation identifier in the main program code, and performing registration operation and binding operation on the service to be registered and the interceptor to be registered;
monitoring a calling request aiming at the target application program in real time, acquiring one or more names of services to be called and names of methods to be called carried by the calling request, and executing interception processing on the calling request based on the names of the services to be called and the names of the methods to be called.
2. The service registration and interception method according to claim 1, wherein the service registration request further includes a transaction to be intercepted, and the generating 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 names of methods to be intercepted of the service to be registered comprises:
generating a first definition code based on the name of the interceptor to be registered and the transaction to be intercepted;
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 a list of names of methods to be intercepted of the service to be registered;
and merging the first definition code and the second definition code to obtain a service definition code.
3. The service registration and interception method according to claim 1, wherein said scanning annotation id in said main program code, and performing registration operation and binding operation on said service to be registered and said interceptor to be registered, comprises:
scanning a program segment carrying an annotation identifier in the main program code, and performing correctness check on the program segment;
and when the verification passes, generating interception data based on the program segment, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered based on the interception data.
4. A service registration and interception method according to claim 3, wherein after performing a correctness check on said program segment, said method further comprises:
and if the verification fails, identifying the program segment and sending early warning information to the client.
5. The service registration and interception method according to claim 1, wherein said performing an interception process on the call request based on the name of the service to be called and the name of the method to be called comprises:
judging whether each service to be called is bound with an interceptor;
when judging that a certain specified service to be called is bound with an interceptor, judging whether a method to be called of the specified service to be called exists in a list of names of methods to be intercepted of the specified service to be called;
and when judging that the method exists in the list of the names of the methods to be intercepted of the appointed service to be called, executing interception processing on the calling request.
6. The service registration and interception method according to claim 5, wherein after determining whether each service to be invoked binds to an interceptor, said method further comprises:
and if judging that each service to be called is not bound with an interceptor or the method to be called of the appointed service to be called does not exist in the name list of the method to be intercepted of the appointed service to be called, executing the calling operation corresponding to the calling request.
7. A service registration and interception apparatus, the apparatus comprising:
the system comprises an analysis module, a service registration module and a service registration module, wherein the analysis module is used for analyzing a service registration request aiming at a target application program sent by a user based on a client, and acquiring a name of a service to be registered, a name of an interceptor to be registered, a binding relation between the service to be registered and the interceptor to be registered and a name list of a method to be intercepted of the service to be registered, which are carried by the service registration request;
the generation module is used for acquiring a predetermined annotation definition code from a database, and generating 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 a name list of a method to be intercepted of the service to be registered, wherein the service definition code comprises an annotation identifier;
the scanning module is used for filling the annotation definition codes and the service definition codes into main program codes corresponding to the target application program, scanning annotation identifications in the main program codes, and executing registration operation and binding operation on the service to be registered and the interceptor to be registered;
and the intercepting module is used for monitoring the calling request aiming at the target application program in real time, acquiring one or more names of the service to be called and the name of the method to be called carried by the calling request, and executing intercepting processing on the calling 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 apparatus according to claim 7, wherein said scanning the annotation id in the main program code, and performing registration and binding operations on the service to be registered and the interceptor to be registered, comprises:
scanning a program segment carrying an annotation identifier in the main program code, and performing correctness check on the program segment;
and when the verification passes, generating interception data based on the program segment, and executing registration operation and binding operation 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 the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores a service registration and interception program executable by the at least one processor to enable the at least one processor to perform the service registration and interception method of any one of claims 1 to 6.
10. A computer-readable storage medium having stored thereon a service registration and interception program executable by one or more processors to implement the service registration and interception method of any one of claims 1 to 6.
CN202110020904.0A 2021-01-04 2021-01-04 Service registration and interception method and device, electronic equipment and readable storage medium Pending CN112596932A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110020904.0A CN112596932A (en) 2021-01-04 2021-01-04 Service registration and interception method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110020904.0A CN112596932A (en) 2021-01-04 2021-01-04 Service registration and interception method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN112596932A true CN112596932A (en) 2021-04-02

Family

ID=75207479

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110020904.0A Pending CN112596932A (en) 2021-01-04 2021-01-04 Service registration and interception method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN112596932A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113111378A (en) * 2021-04-14 2021-07-13 山东英信计算机技术有限公司 Terminal, storage medium, annotation method and system, and pre-verification method and system
CN113162998A (en) * 2021-04-07 2021-07-23 广州炫视智能科技有限公司 Intelligent interactive communication method and communication system
CN113220723A (en) * 2021-04-27 2021-08-06 深圳市云网万店科技有限公司 Flow control method and device, computer equipment and storage medium
CN113691511A (en) * 2021-08-13 2021-11-23 广州华多网络科技有限公司 Service request processing method, device, equipment and medium thereof
CN115269060A (en) * 2022-06-15 2022-11-01 知学云(北京)科技股份有限公司 Service execution pre-post processing method based on aPaaS platform
CN116909681A (en) * 2023-06-13 2023-10-20 北京远舢智能科技有限公司 Method and device for generating data processing assembly, electronic equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040143625A1 (en) * 2002-12-13 2004-07-22 Joseph Sheinis Component proxy with interception logic in remote component container
US20060031176A1 (en) * 2004-05-21 2006-02-09 Bea Systems, Inc. System and method for message handling using message interceptors
CN104811453A (en) * 2012-09-29 2015-07-29 北京奇虎科技有限公司 Active defense method and device
CN105956470A (en) * 2016-05-03 2016-09-21 北京金山安全软件有限公司 Method and terminal for intercepting application program behaviors
CN111314496A (en) * 2020-05-15 2020-06-19 太平金融科技服务(上海)有限公司 Registration request intercepting method and device, computer equipment and storage medium
WO2020167481A1 (en) * 2019-02-14 2020-08-20 Microsoft Technology Licensing, Llc Extensible device driver verification
CN111913741A (en) * 2020-08-31 2020-11-10 网易(杭州)网络有限公司 Object interception method, device, medium and electronic equipment

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040143625A1 (en) * 2002-12-13 2004-07-22 Joseph Sheinis Component proxy with interception logic in remote component container
US20060031176A1 (en) * 2004-05-21 2006-02-09 Bea Systems, Inc. System and method for message handling using message interceptors
CN104811453A (en) * 2012-09-29 2015-07-29 北京奇虎科技有限公司 Active defense method and device
CN105956470A (en) * 2016-05-03 2016-09-21 北京金山安全软件有限公司 Method and terminal for intercepting application program behaviors
WO2020167481A1 (en) * 2019-02-14 2020-08-20 Microsoft Technology Licensing, Llc Extensible device driver verification
CN111314496A (en) * 2020-05-15 2020-06-19 太平金融科技服务(上海)有限公司 Registration request intercepting method and device, computer equipment and storage medium
CN111913741A (en) * 2020-08-31 2020-11-10 网易(杭州)网络有限公司 Object interception method, device, medium and electronic equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
阿伟: "gRPC拦截器那点事,希望帮到你", pages 1 - 4, Retrieved from the Internet <URL:https://cloud.tencent.com/developer/article/1507514> *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113162998A (en) * 2021-04-07 2021-07-23 广州炫视智能科技有限公司 Intelligent interactive communication method and communication system
CN113111378A (en) * 2021-04-14 2021-07-13 山东英信计算机技术有限公司 Terminal, storage medium, annotation method and system, and pre-verification method and system
CN113220723A (en) * 2021-04-27 2021-08-06 深圳市云网万店科技有限公司 Flow control method and device, computer equipment and storage medium
CN113691511A (en) * 2021-08-13 2021-11-23 广州华多网络科技有限公司 Service request processing method, device, equipment and medium thereof
CN113691511B (en) * 2021-08-13 2024-01-19 广州华多网络科技有限公司 Service request processing method and device, equipment and medium thereof
CN115269060A (en) * 2022-06-15 2022-11-01 知学云(北京)科技股份有限公司 Service execution pre-post processing method based on aPaaS platform
CN115269060B (en) * 2022-06-15 2023-06-20 知学云(北京)科技股份有限公司 Service execution pre-post processing method based on aPaaS platform
CN116909681A (en) * 2023-06-13 2023-10-20 北京远舢智能科技有限公司 Method and device for generating data processing assembly, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN112596932A (en) Service registration and interception method and device, electronic equipment and readable storage medium
CN107948314B (en) Business processing method and device based on rule file and server
JP5021886B2 (en) System and method for actively managing an enterprise comprising configurable components
CN112491602B (en) Behavior data monitoring method and device, computer equipment and medium
CN108427550B (en) Web service generation method, device and equipment
CN110365724B (en) Task processing method and device and electronic equipment
CN112860737B (en) Data query method and device, electronic equipment and readable storage medium
CN115150261B (en) Alarm analysis method, device, electronic equipment and storage medium
CN112866348A (en) Database access method and device, computer equipment and storage medium
US20150302089A1 (en) Recovery of Information from Commercial Web Portals
CN112860507B (en) Control method and device for sampling rate of distributed link tracking system
CN114006885A (en) Data acquisition method and device based on intelligent equipment and electronic equipment
CN113485927A (en) Test data generation method, device, equipment and storage medium
CN110674426B (en) Webpage behavior reporting method and device
CN115086047B (en) Interface authentication method and device, electronic equipment and storage medium
CN114036068A (en) Update detection method, device, equipment and storage medium based on privacy security
CN114611046A (en) Data loading method, device, equipment and medium
CN114238391A (en) Data paging query method and device, electronic equipment and storage medium
CN114637672A (en) Automatic data testing method and device, computer equipment and storage medium
CN112051952A (en) Picture dynamic browsing method and device, electronic equipment and readable storage medium
CN112686759A (en) Account checking monitoring method, device, equipment and medium
CN110413644B (en) Data caching method, electronic device and computer readable storage medium
CN111488230A (en) Method and device for modifying log output level, electronic equipment and storage medium
CN113535568B (en) Verification method, device, equipment and medium for application deployment version
CN116401319B (en) Data synchronization method and device, electronic equipment and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination