Micro-service development, debugging and forwarding method and system
By embedding a custom header identifying the target instance in the HTTP protocol request, and combining it with a registry center and gateway to build a targeted routing mechanism, the problem of low development and testing efficiency in microservice architecture is solved, and precise debugging and efficient debugging forwarding are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-03-24
AI Technical Summary
In a microservice architecture, the inability to specify the target machine during the development and testing phase leads to low debugging efficiency, and random calls result in a low probability of reproduction. Existing temporary solutions are cumbersome to operate and may compromise the authenticity of the test environment.
By embedding a custom extended header containing the target instance's network identifier in the HTTP protocol request, and combining it with a registry center and gateway to build a targeted routing mechanism, precise calls to specific microservice instances can be achieved, ensuring the freshness of instance data and the accuracy of debugging forwarding.
It achieves improved efficiency and controllability in development and testing under a microservice architecture, ensuring that developers can accurately locate target instances, significantly improving debugging efficiency without affecting the production environment.
Smart Images

Figure CN121728007A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of microservice development technology, and more specifically, to a microservice development, debugging, and forwarding method and system. Background Technology
[0002] Microservice architecture has become the core technological foundation for enterprise digital transformation. With the popularization of cloud computing, containerization, and DevOps culture, more and more products are choosing to be built on microservices. Its advantages in agility, scalability, and technological heterogeneity are significant. Each service can be developed and deployed independently, supporting dynamic elastic scaling and flexible selection of technology stacks, such as... Figure 4 As shown, in a microservice architecture, the registry center acts as a service discovery hub, dynamically managing the registration and discovery of service instances. When a client registers, it randomly selects a cluster node. After obtaining the instance list, the service caller randomly selects a target instance, thus improving throughput. The gateway, as a traffic entry point, supports millions of concurrent connections based on a reactive architecture. It dynamically loads routing rules from the configuration center, integrates random load balancing strategies, and enables random calls from multiple instances through load balancing between the client and the server.
[0003] like Figure 5 As shown, in a multi-instance deployment scenario of microservices, the development and testing phases often fall into an efficiency dilemma because the target machine cannot be specified. Since service calls rely on the random load balancing strategy of the registry center, requests will be automatically distributed to any instance in the cluster. When developers debug, it is difficult to trigger the code logic of the target instance. Developers need to send dozens of requests repeatedly to accidentally hit the instance to be debugged. Each breakpoint debugging requires re-triggering the request. The debugging time of a single interface may be extended from 5 minutes in a monolithic architecture to more than 30 minutes.
[0004] Furthermore, when a bug is triggered by an abnormal local cache in an instance, testers need to sift through a massive number of instance logs in the log aggregation platform and locate the specific instance by combining the tracing chain. Random calls result in the execution node of the same operation being not fixed, and the probability of reproduction may be as low as less than 10%. Although existing technologies use temporary solutions such as temporarily removing non-target instances and modifying load balancing weights, these are cumbersome to operate in large-scale clusters and may destroy the authenticity of the test environment, thus introducing new interference in the investigation.
[0005] There are currently no effective solutions to the problems in the relevant technologies. Summary of the Invention
[0006] To address the problems in related technologies, this invention proposes a microservice development, debugging, and forwarding method and system to overcome the aforementioned technical problems existing in existing related technologies.
[0007] Therefore, the specific technical solution adopted by the present invention is as follows: In a first aspect, the present invention provides a microservice development, debugging, and forwarding method, comprising: Define variables in the front-end code project using the Hypertext Transfer Protocol (HTTP), add interceptors for the HTTP service based on the variable states, and build a directed routing mechanism based on the results of the interceptors. The result is integrated into a dynamic interceptor chain based on the directed routing mechanism. The dynamic interceptor chain is used to trigger a dedicated routing decision engine in the interception phase in a filter manner to ensure the freshness of instance data. A dedicated routing decision engine is used to perform dimensional validation on the target header value, and the corresponding list of microservice instances is obtained based on the dimensional validation results. Routing decision operations are then performed to complete the debugging and forwarding process.
[0008] Preferably, variables are defined in the front-end code project using the Hypertext Transfer Protocol (HTTP), and interceptors for the HTTP service are added based on the variable states. A directed routing mechanism is then built based on the interceptor results, including: Based on the Hypertext Transfer Protocol, a new metadata strategy is added. Environment-level variables are defined in the front-end code project, and these variables are defined as whether debug routing is enabled and the target value of debug routing. The variables are the header forward flag and the forward path. If the header forward flag is not enabled, it indicates that the environment is in production and the target value of the debug route is ignored. If the header forward flag is enabled, the target value of the debug route is determined. Based on the result of the target value judgment in the debugging route, a Hypertext Transfer Protocol (HTTP) service interceptor is added to the front-end code project, and the service interceptor is used to intercept the headers in the HTTP request. Based on the interception results and variables, a decision is made on whether to embed the target header. According to the decision result, the value of the target header is set according to the format specification in order to carry the network endpoint information of the target service instance and complete the construction of the directed routing mechanism.
[0009] Preferably, the value of the target header is equal to the forward path value, and the value of the target header must conform to the network association format specification.
[0010] Preferably, a dynamic interceptor chain is constructed based on the directed routing mechanism. This dynamic interceptor chain is used to trigger a dedicated routing decision engine during the interception phase in a filter-like manner, ensuring the freshness of instance data, including: The result is an integrated dynamic pluggable interceptor chain built based on the directed routing mechanism, which inherits the reactive load balancing client filter to obtain the filter technology, and triggers a dedicated routing decision engine during the interception phase. A dedicated routing decision engine is used to identify and adapt to the registration center protocol through the microservice registry, and metadata query processing is initiated based on the identification results. The system retrieves a full list of microservice instances for the target service based on the query results and maintains real-time synchronization with the microservice registry via a long connection to ensure the freshness of the full list of microservice instances.
[0011] Preferably, the full list of microservice instances includes network association, port, health status, and version tag.
[0012] Preferably, a dedicated routing decision engine is used to perform dimensional validation on the target header value, and based on the dimensional validation results, a list of corresponding microservice instances is obtained. Routing decision operations are then performed to complete the debug forwarding process, including: The legality of the target header value is parsed using a dedicated routing decision engine, and the full list of corresponding microservice instances is extracted by combining the method of the target service discovery client in the service registry. The system performs precise matching based on the instance host and network association from the full list of microservice instances, and then selects target instances with completely consistent network endpoints and in a healthy state according to the matching results and filtering rules. Based on the screening results, the gateway's built-in load balancer is used to force the request to be routed to the target instance. When the target instance is offline, a degradation strategy is triggered to select an instance that meets the requirements to complete the debugging forwarding process.
[0013] Preferably, the filtering rules include successful heartbeat detection and all microservice instances being started and not offline.
[0014] Secondly, the present invention also provides a microservice development, debugging, and forwarding system, the system comprising: The routing mechanism building module uses the Hypertext Transfer Protocol to define variables in the front-end code project, and adds interceptors for the Hypertext Transfer Protocol service based on the variable status. Based on the interceptors, it adds results to build a targeted routing mechanism. The gateway layer module is used to build a result integration dynamic interceptor chain based on the directed routing mechanism. The dynamic interceptor chain is used to trigger a dedicated routing decision engine in the interception phase in a filter manner to ensure the freshness of instance data. The routing decision module is used to perform dimensional validation on the target header value using a dedicated routing decision engine, obtain the corresponding list of microservice instances based on the dimensional validation results, execute routing decision operations, and complete the debugging forwarding process.
[0015] Thirdly, the present invention also proposes an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the above-described method.
[0016] Fourthly, the present invention also provides a computer-readable storage medium on which a computer program is stored, the computer program implementing the above-described method when executed by a processor.
[0017] The beneficial effects of this invention are as follows: This invention addresses the bottleneck in development and testing efficiency caused by dynamic scheduling of multiple instances in a microservice architecture. It constructs a precise routing system based on enhanced request metadata. During the development and testing phase, a custom extension header carrying the network identifier of the target instance is embedded in the HTTP protocol request to achieve targeted calls to specific microservice instances. This accurately locates the developer's local development machine or dedicated test node. Combined with a registry center and gateway for precise request forwarding, it is non-intrusive to the production environment and does not affect developers. Each developer can specify the target instance, completely solving the problem of blind debugging requests in the traditional random load balancing mode, and significantly improving the controllability and efficiency of testing. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a flowchart of a microservice development, debugging, and forwarding method according to an embodiment of the present invention; Figure 2 This is a schematic diagram of a microservice development, debugging, and forwarding system according to an embodiment of the present invention. Figure 3 This is a schematic diagram of the hardware operating environment involved in the embodiments of the present invention; Figure 4 This is a schematic diagram of a microservice architecture in existing technologies; Figure 5 This is a diagram illustrating a multi-instance deployment scenario for microservices in existing technologies. Figure 6 This is a schematic diagram illustrating the operation of a microservice development, debugging, and forwarding method according to an embodiment of the present invention.
[0020] In the picture: 1. Routing mechanism construction module; 2. Gateway layer module; 3. Routing decision module. Detailed Implementation
[0021] To further illustrate the various embodiments, the present invention provides accompanying drawings, which are part of the disclosure of the present invention. These drawings are mainly used to illustrate the embodiments and can be used in conjunction with the relevant descriptions in the specification to explain the operating principles of the embodiments. With reference to these drawings, those skilled in the art should be able to understand other possible implementation methods and the advantages of the present invention.
[0022] According to an embodiment of the present invention, a method and system for microservice development, debugging and forwarding are provided.
[0023] The present invention will now be further described in conjunction with the accompanying drawings and specific embodiments, such as... Figure 1 As shown, the microservice development, debugging, and forwarding method according to an embodiment of the present invention includes: Step S1: Define variables in the front-end code project using the Hypertext Transfer Protocol (HTTP), and add interceptors for the HTTP service based on the variable status. Then, build a directed routing mechanism based on the results of the interceptors. Step S2: Construct a result integration dynamic interceptor chain based on the directed routing mechanism. Use the dynamic interceptor chain to trigger a dedicated routing decision engine in the interception phase in a filter manner to ensure the freshness of instance data. Step S3: Use a dedicated routing decision engine to perform dimensional verification on the target header value, obtain the corresponding list of microservice instances based on the dimensional verification results, execute the routing decision operation, and complete the debugging forwarding process.
[0024] In one embodiment, variables are defined in the front-end code project using the Hypertext Transfer Protocol (HTTP), and an interceptor for the HTTP service is added based on the variable status. A directed routing mechanism is then constructed based on the interceptor's results. This includes: adding a new metadata policy based on the HTTP service; defining environment-level variables in the front-end code project; defining these variables as whether debug routing is enabled and the target value for debug routing; the variables are a header forward flag and a forward path; if the header forward flag is disabled, it indicates a production environment, and the target value for debug routing is ignored; if the header forward flag is enabled, the target value for debug routing is determined; based on the determination of the target value for debug routing, an HTTP service interceptor is added to the front-end code project, and the service interceptor intercepts the headers in the HTTP request; based on the interception result and the variables, it is determined whether to embed the target header; the value of the target header is set according to the format specification based on the determination result, in order to carry the network endpoint information of the target service instance, thus completing the construction of the directed routing mechanism.
[0025] In one embodiment, the result of constructing a dynamic interceptor chain based on a directed routing mechanism, and using the dynamic interceptor chain to trigger a dedicated routing decision engine during the interception phase in a filter-like manner to ensure the freshness of instance data, includes: constructing a dynamic pluggable interceptor chain based on the result of the directed routing mechanism, inheriting the reactive load balancing client filter to obtain filtering technology, and triggering a dedicated routing decision engine during the interception phase; using the dedicated routing decision engine to identify and adapt the registry center protocol through the microservice registry center, and initiating metadata query processing based on the identification result; and pulling the full list of microservice instances of the target service based on the query result, and maintaining real-time synchronization with the microservice registry center through a long connection to ensure the freshness of the full list of microservice instances.
[0026] In one embodiment, a dedicated routing decision engine is used to perform dimensional validation on the target header value, and a list of corresponding microservice instances is obtained based on the dimensional validation results. The routing decision operation to complete the debug forwarding process includes: using the dedicated routing decision engine to parse the legality of the target header value, and extracting the full list of corresponding microservice instances by combining the instance acquisition method of the target service discovery client in the service registry; performing precise matching from the full list of microservice instances based on the instance host and network association, and filtering out target instances with completely consistent network endpoints and in a healthy state according to the matching results and filtering rules; and using the gateway's built-in load balancer to forcibly route requests to the target instances based on the filtering results, and triggering a degradation strategy when the target instance is offline to select qualified instances to complete the debug forwarding process.
[0027] It needs to be explained that, for example Figure 6As shown, in the scenario of fine-grained traffic governance in a distributed microservice architecture, the problem of precise scheduling in development and testing under multi-instance environments can be solved by building a directional routing mechanism based on HTTP protocol extensions. Specifically, a new metadata strategy is adopted in HTTP (Hypertext Transfer Protocol) requests. In the front-end code project, environment-level variables HeadForwardFlag and ForwardPath are defined. These two variables represent whether debug routing is enabled and the target value of the route, respectively. If HeadForwardFlag is not enabled, it means that we are currently in a production environment and the ForwardPath value will not be checked. If it is enabled, the ForwardPath value will continue to be checked. An HTTP service interceptor is added to the front-end code project. It intercepts the headers of each HTTP request and decides whether to embed a custom identifier field x-target-header based on the above two variables. The value of x-target-header is equal to the value of ForwardPath, and its value must strictly follow the IP format specification (such as 192.168.0.10) to carry the network endpoint information of the target service instance, thereby achieving the goal of enabling this function only in the test environment.
[0028] The gateway layer integrates a dynamic pluggable interceptor chain, inherits ReactiveLoadBalancerClientFilter, and implements the filter method. During the interception phase, a dedicated routing decision engine is triggered. This engine first discovers the client through the microservice registry (adapting to the registry protocol) and initiates a metadata query. It not only pulls the full list of microservice instances of the target service (including IP, port, health status, version tags, etc.), but also maintains real-time synchronization with the registry through a long connection to ensure the freshness of instance data.
[0029] During the routing decision phase, the engine performs multi-dimensional verification on the x-target-header value: First, it parses the validity of the IP address, then obtains the corresponding list of microservice instances through the getInstances method of the target DiscoveryClient in the microservice registry. Next, it performs precise matching based on the instance host and IP address to filter out target instances with completely identical network endpoints and in a healthy state. The filtering requirements include successful heartbeat detection and the instance being started and not offline. If the match is successful, the request is forcibly routed to the instance through the load balancer built into the gateway. If the match fails (e.g., the target instance is offline), a degradation strategy is triggered to randomly select an instance that meets the requirements.
[0030] like Figure 2 As shown, according to another embodiment of the present invention, a microservice development, debugging, and forwarding system is also provided, the system comprising: The routing mechanism construction module 1 uses the Hypertext Transfer Protocol to define variables in the front-end code project, and adds interceptors for the Hypertext Transfer Protocol service based on the variable status. Based on the interceptors, it adds results to build a directed routing mechanism. Gateway layer module 2 is used to build a result integration dynamic interceptor chain based on the directed routing mechanism. The dynamic interceptor chain is used to trigger a dedicated routing decision engine in the interception stage in a filter manner to ensure the freshness of instance data. The routing decision module 3 is used to perform dimensional verification on the target header value using a dedicated routing decision engine, obtain the corresponding list of microservice instances based on the dimensional verification results, perform routing decision operations, and complete the debugging forwarding process.
[0031] Furthermore, the present invention also provides an electronic device. For example... Figure 3 The diagram illustrates the hardware operating environment of an electronic device, which may include: a processor (e.g., CPU), memory, a user interface, a network interface, and a communication bus. The communication bus is used to enable communication between components. The user interface may include a display screen and an input unit such as a keyboard; optionally, the user interface may also include a standard wired interface or a wireless interface. The network interface may optionally include a standard wired interface or a wireless interface. The memory may be high-speed RAM or stable memory (non-RAM). (e.g., volatile memory), such as disk storage. Alternatively, the memory can be a storage device independent of the aforementioned processor.
[0032] Those skilled in the art will understand that Figure 3 The electronic devices shown do not constitute a limitation on electronic devices and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0033] like Figure 3 As shown, a memory, as a type of computer storage medium, may include an operating system, a network communication module, a user interface module, and device management programs. The operating system is a program that manages and controls the hardware and software resources of electronic devices, supporting the operation of electronic devices and other software or programs. Figure 3 In the electronic device shown, the user interface is mainly used to connect to the terminal and communicate with the terminal, such as receiving user signaling data sent by the terminal; the network interface is mainly used to communicate with the backend server; the processor can be used to call the program stored in the memory and execute the steps of the method or system described above.
[0034] Furthermore, the present invention also proposes a computer-readable storage medium storing a device management program, which, when executed by a processor, implements the steps of the method or system described above.
[0035] The specific embodiments of the computer-readable storage medium of the present invention are basically the same as those of the above-described methods or systems, and will not be repeated here. Furthermore, to achieve the above objectives, the present invention also provides a computer program product, comprising: a computer program, which, when executed by a processor, implements the steps of the methods or systems described above.
[0036] Those skilled in the art will recognize that the units and algorithm steps described in conjunction with the embodiments herein can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0037] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A microservice development, debugging, and forwarding method, characterized in that, The method includes: Define variables in the front-end code project using the Hypertext Transfer Protocol (HTTP), add interceptors for the HTTP service based on the variable states, and build a directed routing mechanism based on the results of the interceptors. The result is integrated into a dynamic interceptor chain based on the directed routing mechanism. The dynamic interceptor chain is used to trigger a dedicated routing decision engine in the interception phase in a filter manner to ensure the freshness of instance data. A dedicated routing decision engine is used to perform dimensional validation on the target header value, and the corresponding list of microservice instances is obtained based on the dimensional validation results. Routing decision operations are then performed to complete the debugging and forwarding process.
2. The microservice development, debugging, and forwarding method according to claim 1, characterized in that, The method of defining variables in the front-end code project using the Hypertext Transfer Protocol (HTTP), adding interceptors for the HTTP service based on the variable states, and building a directed routing mechanism based on the interceptor results includes: Based on the Hypertext Transfer Protocol, a new metadata strategy is added. Environment-level variables are defined in the front-end code project, and these variables are defined as whether debug routing is enabled and the target value of debug routing. The variables are the header forward flag and the forward path. If the header forward flag is not enabled, it indicates that the environment is in production and the target value of the debug route is ignored. If the header forward flag is enabled, the target value of the debug route is determined. Based on the result of the target value judgment in the debugging route, a Hypertext Transfer Protocol (HTTP) service interceptor is added to the front-end code project, and the service interceptor is used to intercept the headers in the HTTP request. Based on the interception results and variables, a decision is made on whether to embed the target header. According to the decision result, the value of the target header is set according to the format specification to achieve the purpose of carrying the network endpoint information of the target service instance and complete the construction of the directed routing mechanism.
3. The microservice development, debugging, and forwarding method according to claim 2, characterized in that, The value of the target header is equal to the forward path value, and the value of the target header must conform to the network association format specification.
4. The microservice development, debugging, and forwarding method according to claim 1, characterized in that, The result constructed based on the directed routing mechanism integrates a dynamic interceptor chain. This dynamic interceptor chain is used to trigger a dedicated routing decision engine during the interception phase, ensuring the freshness of instance data, including: The result is an integrated dynamic pluggable interceptor chain built based on the directed routing mechanism, which inherits the reactive load balancing client filter to obtain the filter technology, and triggers a dedicated routing decision engine during the interception phase. A dedicated routing decision engine is used to identify and adapt to the registration center protocol through the microservice registry, and metadata query processing is initiated based on the identification results. The system retrieves a full list of microservice instances for the target service based on the query results and maintains real-time synchronization with the microservice registry via a long connection to ensure the freshness of the full list of microservice instances.
5. The microservice development, debugging, and forwarding method according to claim 4, characterized in that, The full list of microservice instances includes network association, port, health status, and version tag.
6. The microservice development, debugging, and forwarding method according to claim 1, characterized in that, The process of using a dedicated routing decision engine to perform dimensional validation on the target header value, obtaining the corresponding microservice instance list based on the dimensional validation results, executing routing decision operations, and completing debug forwarding processing includes: The legality of the target header value is parsed using a dedicated routing decision engine, and the full list of corresponding microservice instances is extracted by combining the method of the target service discovery client in the service registry. The system performs precise matching based on the instance host and network association from the full list of microservice instances, and then selects target instances with completely consistent network endpoints and in a healthy state according to the matching results and filtering rules. Based on the screening results, the gateway's built-in load balancer is used to force the request to be routed to the target instance. When the target instance is offline, a degradation strategy is triggered to select an instance that meets the requirements to complete the debugging forwarding process.
7. A microservice development, debugging, and forwarding method according to claim 6, characterized in that, The filtering rules include successful heartbeat detection and all microservice instances being started and not offline.
8. A microservice development, debugging, and forwarding system, used to implement the microservice development, debugging, and forwarding method according to any one of claims 1-7, characterized in that, The system includes: The routing mechanism building module uses the Hypertext Transfer Protocol to define variables in the front-end code project, and adds interceptors for the Hypertext Transfer Protocol service based on the variable status. Based on the interceptors, it adds results to build a targeted routing mechanism. The gateway layer module is used to build a result integration dynamic interceptor chain based on the directed routing mechanism. The dynamic interceptor chain is used to trigger a dedicated routing decision engine in the interception phase in a filter manner to ensure the freshness of instance data. The routing decision module is used to perform dimensional validation on the target header value using a dedicated routing decision engine, obtain the corresponding list of microservice instances based on the dimensional validation results, execute routing decision operations, and complete the debugging forwarding process.
9. An electronic device, characterized in that, The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the microservice development, debugging, and forwarding method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the microservice development, debugging, and forwarding method as described in any one of claims 1 to 7.