Micro-service implementation method, system and storage medium based on probe mode
By intercepting and modifying microservice class files using JAVA probes, microservice functionality can be dynamically extended. This solves the problems of complex code modification and high hardware requirements in existing technologies, achieving low-intrusion and low-resource-consumption microservice extension, and adapting to access from different architectures.
Patent Information
- Application Number
- CN202111500547.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-09
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2041-12-09
AI Technical Summary
Existing microservice implementations suffer from complex code modifications, high hardware requirements, high entry barriers, and high switching costs, especially Spring Cloud and Kubernetes implementations, which require significant modification costs when switching.
It adopts a JAVA probe-based approach to intercept and dynamically modify the class files of microservices, and uses a proxy server to extend the functionality of microservices, including functions such as registry center, configuration center, logging, and tracing, and supports interface configuration and function switching.
It achieves low-intrusive extension of the original code, with low resource consumption and low access cost, and supports flexible function expansion and switching to adapt to different microservice architectures.
Smart Images

Figure CN114416047B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer information processing technology, and in particular to a method, system and storage medium for implementing microservices based on a probe approach. Background Technology
[0002] Microservices are an emerging software architecture that breaks down a single application into several microservices, each responsible for a specific business domain, and each deployed, started, and configured independently. Correspondingly, this requires the establishment of a registry center, configuration center, logging system, and tracing mechanism.
[0003] Currently, the main implementation methods for microservices are the Spring Cloud framework and the Kubernetes (K8S) proxy mechanism. The former requires significant code modifications and the establishment of separate registry centers, configuration centers, and other additional services, which also necessitate clustering, resulting in a large and complex workload. While the K8S proxy mechanism overcomes the shortcomings of the former and introduces advantages such as easier unified deployment and monitoring, K8S requires a management platform and corresponding virtual network, leading to a higher learning curve and hardware requirements. Furthermore, code already modified for Spring Cloud is not easily integrated directly into K8S. Both implementation methods also have several technical architecture branches, and switching to a different branch incurs significant modification costs once a branch is chosen. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a microservice implementation method, system and storage medium based on probe method, which addresses the above-mentioned defects of the prior art.
[0005] This invention constructs a microservice implementation method based on a probe approach. After obtaining the class files of the microservice's Java source code compiled using a Java compiler, the following steps are performed:
[0006] Step S10. Based on the interfaces to be intercepted that the user has pre-configured in the JAVA probe, intercept the corresponding interfaces in the microservice;
[0007] Step S20. Dynamically modify the class file or add a new class file according to the various options pre-configured by the user in the JAVA probe;
[0008] Step S30. Send the modified class file and the new class file to the proxy server for processing, so that the proxy server can implement the corresponding functions of the microservice by executing the received class file.
[0009] Preferably, between step S20 and step S30, the method further includes:
[0010] Determine whether the modified class file and the new class file conform to the preset configuration rules. If so, proceed to step S30.
[0011] Preferably, in step S30, the proxy server performs the following processing:
[0012] The proxy server handles input parameter processing, output parameter processing, load balancing, and configuration management.
[0013] Preferably, in step S10, intercepting the corresponding interface in the microservice includes: intercepting the registration interface in the microservice;
[0014] Step S20 includes:
[0015] Based on the various options pre-configured by the user in the JAVA probe, the target domain name is modified by dynamically modifying the class file;
[0016] Step S30 includes:
[0017] The modified class file is sent to the proxy server for processing, so that the proxy server can implement the service flow control of the registry center by executing the received class file.
[0018] Preferably, in step S10, intercepting the corresponding interface in the microservice includes: intercepting the configuration interface in the microservice;
[0019] Step S20 includes:
[0020] Based on the various options pre-configured by the user in the JAVA probe, the corresponding configurations are stored or retrieved by dynamically modifying the class file;
[0021] Step S30 includes:
[0022] The modified class file is sent to the proxy server for processing, so that the proxy server can implement the configuration center function of the microservice by executing the received class file.
[0023] Preferably, in step S10, intercepting the corresponding interface in the microservice includes: intercepting the log interface in the microservice;
[0024] Step S20 includes:
[0025] Based on the various options pre-configured by the user in the JAVA probe, logs of the microservice calls are recorded by adding new class files;
[0026] Step S30 includes:
[0027] The modified class file and the new class file are sent to the proxy server for processing, so that the proxy server can implement the logging function of the microservice by executing the received class file.
[0028] Preferably, in step S10, intercepting the corresponding interface in the microservice includes: intercepting the link interface in the microservice;
[0029] Step S20 includes:
[0030] Based on the various options pre-configured by the user in the JAVA probe, the entire chain of microservice calls is traced by dynamically modifying the class files;
[0031] Step S30 includes:
[0032] The modified class file is sent to the proxy server for processing, so that the proxy server can implement the microservice tracing function by executing the received class file.
[0033] Preferably, in step S10, intercepting the corresponding interface in the microservice includes: intercepting the gateway interface in the microservice;
[0034] Step S20 includes:
[0035] Based on the various options pre-configured by the user in the JAVA probe, traffic control and mirroring services are performed by dynamically modifying the class files.
[0036] Step S30 includes:
[0037] The modified class file is sent to the proxy server for processing, so that the proxy server can implement the gateway control function of the microservice by executing the received class file.
[0038] The present invention also constructs a storage medium storing a computer program, which, when executed by a processor, implements the probe-based microservice implementation method described above.
[0039] The present invention also constructs a probe-based microservice implementation system, including a processor and a memory storing a computer program, wherein the processor implements the probe-based microservice implementation method described above when executing the computer program.
[0040] The technical solution of this invention achieves low intrusion into the original code of the microservices and low resource consumption because it uses JAVA probes to implement additional functions of the microservices. Furthermore, since the functional expansion of the microservices is achieved through interface configuration, the integration cost is low. Attached Figure Description
[0041] The present invention will be further described below with reference to the accompanying drawings and embodiments. In the accompanying drawings:
[0042] Figure 1 This is a logical structure diagram of the microservice implementation system of this invention;
[0043] Figure 2 This is a flowchart of an embodiment of the microservice implementation method based on the probe method of the present invention. Detailed Implementation
[0044] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0045] First, it should be noted that Java probes were introduced in JDK 1.5 and are a technology that allows dynamic modification of Java bytecode (class files). After a Java class is compiled, it forms bytecode that is executed by the JVM. Before executing this bytecode, the JVM obtains this bytecode information and modifies it to perform additional functions.
[0046] This invention provides a microservice implementation method based on JAVA probes, such as... Figure 1 As shown, the JAVA probe can intercept requests before loading JAVA class files and modify or add new class files. All requests are intercepted and sent to the proxy server for processing. The proxy server can execute and define various rules, including the usual functions of microservice registry, configuration center, and tracing. It can also periodically execute various functions such as modifying input parameters, modifying output parameters, and service mirroring. The corresponding rules or microservices can be turned on or off by switching them on and off.
[0047] Figure 2 This is a flowchart of an embodiment of the microservice implementation method based on the probe method of the present invention. In this embodiment, after obtaining the class file after compiling the JAVA source code of the microservice using a JAVA compiler, the following steps are performed:
[0048] Step S10. Based on the interfaces to be intercepted that the user has pre-configured in the JAVA probe, intercept the corresponding interfaces in the microservice;
[0049] Step S20. Dynamically modify the class file or add a new class file according to the various options pre-configured by the user in the JAVA probe;
[0050] Step S30. Send the modified class file and the new class file to the proxy server for processing, so that the proxy server can implement the corresponding functions of the microservice by executing the received class file, such as implementing the microservice's registration center, configuration center, logging, tracing, gateway control, and other functions.
[0051] Regarding this embodiment, it should be noted that each original microservice can use Java's probe technology to import a proxy package, and the microservice name (default Java source file name) and port number can be set via startup parameters. Furthermore, multiple microservices under a single virtual machine can share a single proxy package, or separate proxy packages can be set for multiple microservices under a single virtual machine, with multiple proxy packages configured to use the same storage layer to achieve cluster functionality.
[0052] The technical solution of this embodiment achieves low intrusion into the original microservice code and low resource consumption because it uses a JAVA probe method to implement additional functions of the microservice. Furthermore, since the microservice functionality is extended through interface configuration, when deploying the microservice to Kubernetes, only this extended code needs to be hidden or modified, resulting in low integration costs. Table 1 compares the characteristics of this embodiment's microservice implementation method with two corresponding methods:
[0053] Features Spring Cloud K8S probe Implementation Introducing technical architecture Virtual Network probe Code intrusion high Low Low Resource usage medium high Low Access cost high high Low
[0054] Table 1
[0055] Furthermore, in an optional embodiment, between step S20 and step S30, the following step is further included:
[0056] Determine whether the modified class file and the new class file conform to the preset configuration rules. If yes, proceed to step S30; otherwise, call the original interface and end.
[0057] Furthermore, in an optional embodiment, the processing performed by the proxy server in step S30 includes: input parameter processing; output parameter processing; load balancing; and configuration management. In this embodiment, the proxy server can execute various defined rules, including common microservice functions such as registry center, configuration center, and link tracing. It can also periodically execute other functions such as modifying input parameters, modifying output parameters, and service mirroring. Moreover, the corresponding rules or microservices can be enabled or disabled via switches.
[0058] Furthermore, in an alternative embodiment, users can use the system's predefined service interface (i.e., the default HTTP service interface implemented by the original Java microservice), or they can choose not to use the system's predefined service interface and instead define their own interface to flexibly implement various rule definitions, thus achieving zero intrusion into the original microservice code.
[0059] In one specific embodiment, step S10 involves intercepting the corresponding interface in the microservice, including intercepting the registration interface in the microservice. Step S20 includes modifying the target domain name by dynamically modifying the class file according to the various options pre-configured by the user in the JAVA probe. Step S30 includes sending the modified class file to the proxy server for processing, so that the proxy server can implement service flow control of the registry center by executing the received class file. In this embodiment, a default HTTP service interface standard is first defined and implemented by the original JAVA microservice. When the probe intercepts the corresponding interface, it will modify the target domain name according to the predefined configuration rules to implement service flow control of the registry center. The predefined rules may include polling, weight, system load, input parameter checking, service mirroring, etc. If the corresponding interface is not intercepted, or the user disables the registration function in the configuration, the interface called by the microservice is not controlled, and the corresponding function can be implemented by the K8S POD to ensure compatibility with K8S and other technologies that have implemented the corresponding registry center.
[0060] In one specific embodiment, step S10 involves intercepting the corresponding interfaces in the microservice, including intercepting the configuration interfaces in the microservice. Step S20 includes dynamically modifying the class file to store or retrieve the corresponding configuration according to the options pre-configured by the user in the JAVA probe. Step S30 includes sending the modified class file to the proxy server for processing, so that the proxy server implements the configuration center function of the microservice by executing the received class file. In this embodiment, a set of configuration read / write interface standards is first defined and implemented by the original JAVA microservice. When the probe intercepts the corresponding interface, it stores or retrieves the corresponding configuration to local storage, database, cache, Kubernetes ConfigMap, etc., according to the configured options, thereby realizing the configuration center function of the original microservice.
[0061] In one specific embodiment, step S10 involves intercepting the corresponding interfaces in the microservice, including intercepting the logging interface in the microservice. Step S20 includes adding a new class file to record the logs called by the microservice, based on the options pre-configured by the user in the JAVA probe. Step S30 includes sending the modified class file and the new class file to the proxy server for processing, so that the proxy server implements the logging function of the microservice by executing the received class file. It should be noted that after the modified class file and the new class file are sent to the proxy server, the two class files are executed in different threads. In this embodiment, when the user configures the logging function in the probe configuration, the corresponding logs of the microservice calls will be recorded and stored. The storage medium includes, but is not limited to, local files, Elasticsearch, databases, caching systems, etc.
[0062] In one specific embodiment, step S10 involves intercepting the corresponding interfaces in the microservice, including intercepting the link interfaces in the microservice. Step S20 includes dynamically modifying the class file to trace the entire link of microservice calls according to the options pre-configured by the user in the JAVA probe. Step S30 includes sending the modified class file to the proxy server for processing, so that the proxy server implements the link tracing function of the microservice by executing the received class file. In this embodiment, when the user configures the link function in the probe configuration, SpanID and TradeID parameters are added to all HTTP services to trace the entire link of microservice calls, thereby realizing the link tracing function of microservices. In addition, the response time and other indicators of the corresponding microservices are also recorded.
[0063] Furthermore, users can also configure the probe configuration to forward link tracing to other link tracing systems they have set up, such as Zipkin, Jaeger, etc.
[0064] In one specific embodiment, step S10 involves intercepting the corresponding interfaces in the microservice, including intercepting the gateway interface in the microservice. Step S20 includes dynamically modifying the class file to perform traffic control and mirroring services based on the options pre-configured by the user in the JAVA probe. Step S30 includes sending the modified class file to the proxy server for processing, so that the proxy server implements the gateway control function of the microservice by executing the received class file. In this embodiment, when the user configures the interface gateway function in the probe configuration, microservice gateway control is implemented on the configured microservice calls, specifically including traffic control, mirroring services, and blue-green deployment, etc.
[0065] In summary, probe technology enables functions such as a microservice registry, configuration center, logging, tracing, and gateway control. Furthermore, these functions can be flexibly enabled or disabled via switches. Additionally, a non-intrusive design is achieved through a custom interface.
[0066] The present invention also constructs a storage medium storing a computer program, which, when executed by a processor, implements the probe-based microservice implementation method described above.
[0067] The present invention also constructs a probe-based microservice implementation system, including a processor and a memory storing a computer program. When the processor executes the computer program, it implements the probe-based microservice implementation method described above.
[0068] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of the claims of the present invention.
Claims
1. A microservice implementation method based on probes, characterized in that, After obtaining the class files compiled from the Java source code of the microservice using a Java compiler, perform the following steps: Step S10. Based on the interfaces to be intercepted that the user has pre-configured in the JAVA probe, intercept the corresponding interfaces in the microservice; Step S20. Dynamically modify the class file or add a new class file according to the various options pre-configured by the user in the JAVA probe; Step S30. Send the modified class file and the new class file to the proxy server for processing, so that the proxy server can implement the corresponding functions of the microservice by executing the received class file in the manner of interface configuration, and turn the implementation of the corresponding functions on or off by using a switch; In step S10, the corresponding interfaces in the microservice are intercepted, including: intercepting the registration interface in the microservice; step S20 includes: modifying the target domain name by dynamically modifying the class file according to the various options pre-configured by the user in the JAVA probe; step S30 includes: sending the modified class file to the proxy server for processing, so that the proxy server can implement the service flow control of the registration center by executing the received class file; wherein, a default HTTP service interface standard is first defined and implemented by the original JAVA microservice. When the probe intercepts the corresponding interface, the target domain name is modified according to the predefined configuration rules to implement the service flow control of the registration center. The predefined rules include polling, weight, system load, input parameter checking, and service mirroring; when the corresponding interface is not intercepted, or the user disables the registration function in the configuration, the interface called by the microservice is not controlled, and the corresponding function is implemented by the K8S POD to ensure compatibility with K8S technology; In step S10, intercepting the corresponding interface in the microservice also includes intercepting the configuration interface in the microservice; step S20 further includes storing or retrieving the corresponding configuration by dynamically modifying the class file according to the various options pre-configured by the user in the JAVA probe; step S30 further includes sending the modified class file to the proxy server for processing, so that the proxy server can implement the configuration center function of the microservice by executing the received class file. Here, a set of configuration read and write interface standards are first defined and implemented by the original JAVA microservice. When the probe intercepts the corresponding interface, the corresponding configuration is stored or retrieved to the local machine, database, cache, or Kubernetes ConfigMap according to the configured options, thereby realizing the configuration center function of the original microservice.
2. The microservice implementation method based on probe method according to claim 1, characterized in that, Between step S20 and step S30, the following is also included: Determine whether the modified class file and the new class file conform to the preset configuration rules. If so, proceed to step S30.
3. The microservice implementation method based on probe method according to claim 1, characterized in that, In step S30, the proxy server performs the following processing: The proxy server handles input parameter processing, output parameter processing, load balancing, and configuration management.
4. The microservice implementation method based on probe method according to claim 1, characterized in that, In step S10, intercepting the corresponding interface in the microservice also includes: intercepting the log interface in the microservice; Step S20 further includes: Based on the various options pre-configured by the user in the JAVA probe, logs of the microservice calls are recorded by adding new class files; Step S30 further includes: The modified class file and the new class file are sent to the proxy server for processing, so that the proxy server can implement the logging function of the microservice by executing the received class file.
5. The microservice implementation method based on probe method according to claim 1, characterized in that, In step S10, intercepting the corresponding interface in the microservice also includes: intercepting the link interface in the microservice; Step S20 further includes: Based on the various options pre-configured by the user in the JAVA probe, the entire chain of microservice calls is traced by dynamically modifying the class files; Step S30 further includes: The modified class file is sent to the proxy server for processing, so that the proxy server can implement the microservice tracing function by executing the received class file.
6. The microservice implementation method based on probe method according to claim 1, characterized in that, In step S10, intercepting the corresponding interface in the microservice also includes: intercepting the gateway interface in the microservice. Step S20 further includes: Based on the various options pre-configured by the user in the JAVA probe, traffic control and mirroring services are performed by dynamically modifying the class files. Step S30 further includes: The modified class file is sent to the proxy server for processing, so that the proxy server can implement the gateway control function of the microservice by executing the received class file.
7. A storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the probe-based microservice implementation method according to any one of claims 1-6.
8. A microservice implementation system based on a probe approach, comprising a processor and a memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the probe-based microservice implementation method according to any one of claims 1-6.
Citation Information
Patent Citations
Micro-service link monitoring method, device, equipment and medium
CN112035317A
Automatic index generation method and system based on byte codes
CN113254317A