Mock service management method, system, device, medium and product
By dynamically updating the Host configuration information in a container environment and sending service requests to the Mock server, the existing Mock service processing solution cannot meet the dynamic needs of the business in the microservice scenario, and the Mock service management without intrusion, low maintenance costs and high security is achieved.
Patent Information
- Application Number
- CN202510188930.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-06-27
AI Technical Summary
The existing Mock service processing solution cannot meet the dynamic business needs in microservice scenarios, and it has a large intrusion into the business system, increasing maintenance costs and posing security risks.
In the client's container environment, the Host configuration update service and business service are started in turn based on the preset startup script, and the Host configuration information is dynamically obtained and reported to the Mock server. The Host configuration interface of the Mock server is called to query the Host resolution domain name to determine whether to update the Host configuration information. If it is updated, a service request is sent to the Mock server.
It realizes Mock service management without intrusion of business systems in microservice scenarios, meets business dynamic needs, reduces maintenance costs, and avoids security risks.
Smart Images

Figure CN120223530A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and particularly to a Mock service management method, system, device, medium and product. Background Art
[0002] A Mock service refers to a technology or tool that simulates a real service, capable of simulating the interfaces and behaviors of a real service, and is usually used in software development, testing, and system integration, so that developers and testers can perform function verification and user testing when there is no real service or resource available.
[0003] There are mainly two existing Mock service processing solutions. One is the local proxy setting solution, and the other is the request forwarding solution. The local proxy setting solution means intercepting user access requests through a proxy and directly modifying the interface return value to achieve Mock capabilities. However, in the microservices scenario, the number of external dependency domain names and ports is large, and it increases dynamically with business iteration. The local proxy setting solution cannot meet the business requirements. The request forwarding solution intercepts requests initiated by the business system at the middleware level of the business system code. If it determines that the request initiated by the business system is a Mock request, it forwards the request to the Mock server and returns the corresponding Mock data to the business system. This solution can meet the business dynamic requirements of the microservices scenario, but it has a large intrusion into the middleware code to be tested and brings Mock logic into the production environment, increasing the business maintenance cost and posing a large security risk. Summary of the Invention
[0004] This application provides a Mock service management method, system, device, medium and product, which can meet the business dynamic requirements of the microservices scenario, without invading the business system, reducing the business maintenance cost, and avoiding security risks.
[0005] This application provides a Mock service management method, which is applicable to the container environment of the client, and includes: Sequentially starting the preset Host configuration update service and business service of the current container based on a preset startup script; The Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls the preset Host configuration interface of the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result; If the Host configuration information is updated, the business service sends a business request to the Mock server based on the updated Host configuration information.
[0006] As an example, the Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls the Host configuration interface preset in the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result, including: Read the Host configuration information of the current container from the Host configuration file of the current container; Call the Host configuration interface of the Mock server to report the Host configuration information to the Mock server; Call the Host configuration interface preset in the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and obtain the query result, where the query result includes successful query and failed query; If the query is successful, update the Host configuration information based on the queried Host resolution domain name. If the query fails, restore the Host configuration information to the preset initial value; After a preset time interval, return to execute the step of reading the Host configuration information of the current container from the Host configuration file of the current container until the Host configuration update service stops running.
[0007] As an example, the sequential startup of the preset Host configuration update service and business service of the current container based on the preset startup script includes: Determine whether there is a Host configuration update service file in the current container. If there is, execute the next step. If not, download the Host configuration update service file; Determine whether the Host configuration update service has been started in the current container. If so, execute the next step. If not, suspend the Host configuration update service file to start the Host configuration update service; Determine whether the business service has been started in the current container. If so, end the process. If not, start the business service and end the process.
[0008] The present application also provides a Mock service management method, which is applicable to a Mock server and includes: Obtain the Host configuration information of the current container reported by the client; the client is used to sequentially start the preset Host configuration update service and business service of the current container based on the preset startup script, dynamically obtain the Host configuration information of the current container based on the Host configuration update service and report it; In response to the client invoking a preset Host configuration interface, query the Host resolution domain name corresponding to the Host configuration information, and feedback the query result to the client. The client is further configured to determine whether to update the Host configuration information based on the query result. If the Host configuration information is updated, send a service request to the Mock server based on the service and the updated Host configuration information.
[0009] As an embodiment, after receiving the service request, it further includes: Start the call chain filling service and construct a call chain corresponding to the service request; Extract the domain name and request path from the service request, and filter a list of Mock data corresponding to the domain name and the request path from a pre-constructed database; According to the service scenario corresponding to the service request, extract the call chain unique identifier, call chain user identifier, or request parameter from the service request, and determine whether there is Mock data in the Mock data list corresponding to the call chain unique identifier, the call chain user identifier, or the request parameter; If it exists, filter the response data and header data of the Mock data from the database according to the database primary key corresponding to the Mock data, and fill the response data and header data of the Mock data into the response result corresponding to the service request; If it does not exist, forward the request parameter, header data, and body data of the service request to the service server corresponding to the service request, and fill the data feedback by the service server into the response result corresponding to the service request.
[0010] This application also provides a Mock service management system, including a client and a Mock server; The client is configured to sequentially start a preset Host configuration update service and a service of the current container based on a preset startup script. The Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server; The Mock server is configured to obtain the Host configuration information of the current container reported by the client. In response to the client invoking a preset Host configuration interface, query the Host resolution domain name corresponding to the Host configuration information, and feedback the query result to the client. Correspondingly, the client is further configured to determine whether to update the Host configuration information based on the query result. If the Host configuration information is updated, send a service request to the Mock server based on the service and the updated Host configuration information.
[0011] As an example, the Mock server is also used to periodically query all Mock domain name configurations, extract a domain name port list from all the Mock domain name configurations, compare the domain name port list with a pre-determined list of listened ports, determine whether there are unlistened domain name ports, and if so, listen to the unlistened domain name ports.
[0012] The present application also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the Mock service management method as described in any one of the above is implemented.
[0013] The present application also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the Mock service management method as described in any one of the above is implemented.
[0014] The present application also provides a computer program product, including a computer program. When the computer program is executed by a processor, the Mock service management method as described in any one of the above is implemented.
[0015] The Mock service management method, system, device, medium, and product provided by the present application run in the container environment of the client, call the Host configuration interface preset by the Mock server to query the Host resolution domain name corresponding to the Host configuration information, determine whether to update the Host configuration information based on the query result, and if the Host configuration information is updated, send a service request to the Mock server to forward the service request to be mocked to the Mock server, which can meet the dynamic service requirements in the microservice scenario, have zero intrusion into the service system of the client, reduce the service maintenance cost, and avoid security risks. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0017] Figure 1 is one of the flow diagrams of the Mock service management method provided by the present application.
[0018] Figure 2 is the flow diagram of the startup script provided by the present application.
[0019] Figure 3 is the flow diagram of the Host configuration update service provided by the present application.
[0020] Figure 4 It is the second flow schematic diagram of the Mock service management method provided by this application.
[0021] Figure 5 It is the flow schematic diagram of the Mock server processing service requests provided by this application.
[0022] Figure 6 It is one of the structural schematic diagrams of the Mock service management system provided by this application.
[0023] Figure 7 It is the second structural schematic diagram of the Mock service management system provided by this application.
[0024] Figure 8 It is the functional flow schematic diagram of the Mock port startup module provided by this application.
[0025] Figure 9 It is the structural schematic diagram of the electronic device provided by this application. Specific embodiments
[0026] To make the objectives, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below with reference to the accompanying drawings in this application. Apparently, the described embodiments are some but not all of the embodiments of this application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without making creative efforts shall fall within the scope of protection of this application.
[0027] It should be noted that all actions of obtaining signals, information or data in this application are carried out on the premise of complying with the corresponding data protection regulations and policies of the location and with the authorization given by the owner of the corresponding device.
[0028] Figure 1 It is one of the flow schematic diagrams of the Mock service management method provided by this application. As Figure 1 shown, this application provides a Mock service management method applicable to the container environment of the client, including step S110-step S130.
[0029] In step S110, the preset Host configuration update service and business service of the current container are started in sequence based on a preset startup script. The startup script starts the Host configuration update service and then starts the business service. The business service refers to the business service provided by the microservice architecture to cope with the ever-changing business requirements arising from market changes, user behaviors or technological evolution in the microservice scenario.
[0030] Step S120: The Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls the Host configuration interface preset by the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result. The Mock server pre-stores a mapping relationship table or mapping database of Host configuration information and domain names. The query result is used to indicate whether the Host resolution domain name corresponding to the Host configuration information has been successfully queried. If the query result indicates that the Host resolution domain name corresponding to the Host configuration information has been successfully queried, the Host configuration information is updated.
[0031] Step S130: If the Host configuration information is updated, the business service sends a business request to the Mock server based on the updated Host configuration information.
[0032] It can be understood that this application is an improved request forwarding solution, which runs in the container environment of the client, calls the Host configuration interface preset by the Mock server to query the Host resolution domain name corresponding to the Host configuration information, determines whether to update the Host configuration information based on the query result, and if the Host configuration information is updated, sends a business request to the Mock server to forward the business request to be mocked to the Mock server. It is easy to access, can meet the dynamic business requirements of the microservice scenario, has zero intrusion into the business system of the client, reduces the business maintenance cost, and avoids security risks.
[0033] As Figure 2 shown, on the basis of the above embodiment, as an optional embodiment, the step of sequentially starting the preset Host configuration update service and business service of the current container based on the preset startup script includes steps S111 - S113.
[0034] Step S111: Determine whether there is a Host configuration update service file in the current container. If so, proceed to the next step; if not, download the Host configuration update service file.
[0035] Optionally, in the embodiment of this application, the startup script is named hostagent.sh, and the Host configuration update service is named hostagent.jar. The startup script is used to complete the startup of the Host configuration update service and the business service. First, it detects whether there is a Host configuration update service file in the current container. If not, it downloads the Host configuration update service file. If so, it executes step S120.
[0036] Step S112: Determine whether the current container has started the Host configuration update service. If yes, proceed to the next step; if not, suspend the Host configuration update service file to start the Host configuration update service. Suspending the Host configuration update service file includes suspending the start of the hostagent.jar script in the background.
[0037] Step S113: Determine whether the current container has started the business service. If yes, end the process; if not, start the business service and end the process. Starting the business service includes calling the container startup script start.sh to start the business service.
[0038] It can be understood that in this application, only by starting the integrated startup script can the Host configuration update service and the business service be started in sequence. Only the container startup script needs to be modified, without the need to transform the middleware and deploy the configuration service, making the access more convenient.
[0039] As Figure 3 shown, on the basis of the above embodiments, as an optional embodiment, the Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls the Host configuration interface preset by the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result, including steps S121 - S125.
[0040] Step S121: Read the Host configuration information of the current container from the Host configuration file of the current container. The Host configuration information is used to represent the relevant information for configuring and managing the network, storage, and other resources between the current container and its host, so that the current container can run correctly and interact with external systems or other containers.
[0041] The Host configuration update service (hostagent.jar) is the core component for forwarding business requests to the Mock server. The Host configuration file of the current container is the / etc / host file. When the Host configuration update service is started, the content of the / etc / host file of the current container is read to determine the Host configuration information of the current container. In other embodiments, the read content can also be saved in a static variable, and using a static variable can improve data sharing efficiency and state management capabilities.
[0042] Step S122: Invoke the Host configuration interface of the Mock server to report the Host configuration information to the Mock server. In other embodiments, the IP address of the current container and the application system information may also be reported to the Mock server, and the Mock server stores the received Host configuration information, IP address, and application system information to update the mapping relation table or mapping database.
[0043] Step S123: Invoke the preset Host configuration interface of the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and obtain the query result. The query result includes query success and query failure. Query success means that the Host resolution domain name corresponding to the Host configuration information is successfully queried, and query failure means that the Host resolution domain name corresponding to the Host configuration information is not queried.
[0044] Step S124: If the query is successful, update the Host configuration information based on the queried Host resolution domain name. If the query fails, restore the Host configuration information to the preset initial value. If the query is successful, update the queried Host resolution domain name to the / etc / host file of the current container. Otherwise, restore the / etc / host file of the current container to the initial state.
[0045] Step S125: After a preset time interval (such as sleeping for N seconds), return to execute the step of reading the Host configuration information of the current container from the Host configuration file of the current container until the Host configuration update service stops running.
[0046] It can be understood that in this application, by constructing a Host configuration update service, query the Host resolution domain name corresponding to the Host configuration information from the Mock server, and update the Host resolution domain name to / etc / host, so that the business service can initiate a business request to the Mock server according to the content of the / etc / host file. By adopting the method of dynamically modifying the / etc / host file of the container, the request is forwarded to the Mock server under the condition of zero intrusion into the application.
[0047] The Mock service management method provided by this application is described below. The Mock service management method described below can be mutually corresponding and referred to the Mock service management method described above.
[0048] Figure 4 It is the second flow diagram of the Mock service management method provided by this application. As Figure 4 shown, this application also provides a Mock service management method, which is applicable to the Mock server and includes steps S210 - S220.
[0049] Step S210: Obtain the Host configuration information of the current container reported by the client; the client is used to sequentially start the preset Host configuration update service and business service of the current container based on a preset startup script, dynamically obtain the Host configuration information of the current container based on the Host configuration update service, and report it.
[0050] Step S220: In response to the client's invocation of a preset Host configuration interface, query the Host resolution domain name corresponding to the Host configuration information, and feedback the query result to the client. The client is also used to determine whether to update the Host configuration information based on the query result. If the Host configuration information is updated, send a business request to the Mock server based on the business service and the updated Host configuration information.
[0051] It can be understood that the Mock server of the present application cooperates with the client to determine the update of the Host configuration information, does not invade the business system, can meet the business dynamic requirements of the microservice scenario, reduce the business maintenance cost, and avoid security risks.
[0052] As Figure 5 shown, on the basis of the above embodiment, as an optional embodiment, after receiving the business request, steps S230 - S270 are further included.
[0053] Step S230: Start the call chain filling service and construct a call chain corresponding to the business request.
[0054] Step S240: Extract the domain name and request path from the business request, and filter out a list of Mock data corresponding to the domain name and the request path from a pre-constructed database. The database is obtained based on all the Host configuration information uploaded by the clients, a pre-stored mapping table or mapping database of Host configuration information and domain names, and the updated mapping table or mapping database.
[0055] Specifically, extracting the domain name and request path from the business request means extracting the domain name (domain) from the Host configuration information in the header data (header data) of the business request, extracting the request path from the uniform resource identifier (uri) of the business request, and filtering out a list of Mock data (MockList) from the database according to the domain name and the request path.
[0056] In other embodiments, the IP address of the caller, i.e., the client, can also be extracted from the call chain, and the application system information (systemId) corresponding to the caller IP address can be queried in the database, and a Mock data list (MockList) corresponding to the domain name, request path, and application system information can be filtered out.
[0057] Step S250: According to the service scenario corresponding to the service request, extract the call chain unique identifier, call chain user identifier, or request parameter from the service request, and determine whether there is Mock data in the Mock data list that corresponds to the call chain unique identifier, the call chain user identifier, or the request parameter.
[0058] The Host configuration information includes the domain name domain, request path, application system information systemId, call chain unique identifier traceId, call chain user identifier opId, request parameter params, response data response, and response header headers. The service request is obtained based on the Host configuration information and also includes the above field information.
[0059] During the request path matching process, the request path in the database is a regular expression, and the request path in the service request is matched with the regular expression request path to implement the identification of service requests with variables in the uri.
[0060] The call chain unique identifier traceId is applicable to the automated dial test scenario. When passing the call chain parameter during the interface call and filling the traceId with a fixed value, the external dependencies on the call chain will transparently transmit the traceId, realizing the stability of the request-dependent data in the automated dial test scenario, thereby supporting regular automated dial tests.
[0061] The call chain user identifier opId is applicable to the service test scenario where the service data changes with the user. By configuring Mock data for the user identifier opId of the tester, the function of verifying the service logic in different scenarios can be realized.
[0062] The request parameter params includes the url path parameter, header parameter, and body parameter. After extracting the request parameter from the service request, it is converted into a one-dimensional array, and the one-dimensional data is used to match the Mock data list (MockList). The request parameter params is applicable to the service test scenario where the service data changes with the request parameter, and different data can be returned according to different request parameters.
[0063] Step S260, if it exists, according to the database primary key corresponding to the Mock data, filter the response data and header data of the Mock data from the database, and fill the response data and header data of the Mock data into the response result corresponding to the service request.
[0064] Step S270, if it does not exist, forward the request parameters, header data, and body data of the service request to the service server corresponding to the service request, and fill the data feedback by the service server into the response result corresponding to the service request.
[0065] After receiving a service request, the Mock server will execute the call chain filling step (Step S230), the request routing step (Steps S240 and S250), the Mock request processing step (Step S260), and the request forwarding processing step (Step S270). The call chain filling step is used to implement traceability, and the request routing step is used to determine whether the service request belongs to a Mock request, so as to decide whether to execute the Mock request processing step or the request forwarding processing step.
[0066] It can be understood that the processing steps of the Mock server can be viewed through the call chain, so that the Mock server can be transparent to the business process and leave traces in the call chain. According to the business scenario corresponding to the service request, the unique call chain identifier, call chain user identifier, or request parameters are extracted from the service request, which can adapt to different business scenarios and has a wide range of applications.
[0067] Next, the Mock service management system provided by this application will be described. The Mock service management system described below can be correspondingly referred to the Mock service management method described above.
[0068] Figure 6 is a schematic structural diagram of the Mock service management system provided by this application. As Figure 6 shown, this application also provides a Mock service management system, including a client 100 and a Mock server 200.
[0069] The client 100 is used to sequentially start the preset Host configuration update service and business service of the current container based on a preset startup script. The Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server.
[0070] The Mock server 200 is used to obtain the Host configuration information of the current container reported by the client. In response to the client's invocation of a preset Host configuration interface, it queries the Host resolution domain name corresponding to the Host configuration information and feeds the query result back to the client. Correspondingly, the client is also used to determine whether to update the Host configuration information based on the query result. If the Host configuration information is updated, a service request is sent to the Mock server based on the service and the updated Host configuration information.
[0071] As an embodiment, the Mock server is further used to periodically query all Mock domain name configurations, extract a domain name port list from all the Mock domain name configurations, compare the domain name port list with a pre-determined list of listened ports, and determine whether there are unlistened domain name ports. If so, listen on the unlistened domain name ports.
[0072] As Figure 7 As shown, the Mock service management system provided by this application includes a client, a Mock server, and a service server. The client includes a container Host dynamic update module for executing a Mock service management method applicable to the container environment of the client. If the Host configuration information is updated, the service request is forwarded to the Mock server. If the Host configuration information is not updated, the service request is sent to the service server.
[0073] The Mock server includes a Spring Boot server module, a Mock port startup module, a request listening module, and a Mock request processing module.
[0074] The Spring Boot server module is used to implement operations related to the addition, deletion, modification, and query (create, delete, update, query) of the Host configuration and Mock configuration of the Mock server. The Spring Boot server uses a non-standard port, such as 1234, to avoid conflicts with the ports of the services to be mocked.
[0075] The Mock port startup module detects all dependent external ports according to the Host configuration information of the business system. When a new port appears, it starts a Netty Server for port listening and hands over the started Netty Server to the request listening module for management. As Figure 8As shown, the Mock port startup module periodically queries all Mock domain name configurations, extracts a domain name port list (mockPortList) from all the Mock domain name configurations, obtains a list of listened ports (bindPortList) corresponding to the ports listened by all Netty Servers managed by the request listening module, compares mockPortList and bindPortList, determines whether there are new ports to be listened, and if there are new ports to be listened, starts a NettyServer for listening, and the Netty Server started is managed by the request listening module.
[0076] The request listening module consists of a group of Netty Servers of the Mock port startup module, receives requests from the client to configure the Host domain name, and forwards the requests to the Mock request processing module.
[0077] The Mock request processing module is the specific processing module of the Mock server, including a system identification module, a call chain filling module, a request routing module, a request forwarding processing module, and a Mock processing module, which are used to complete the Mock or forwarding processing of specific business requests.
[0078] The system identification module is used to implement the isolation of Mock data configuration for business systems.
[0079] The call chain filling module integrates the call chain in the Netty-Server, records the entire process of the Mock server's processing of business requests, makes the Mock server transparent to the business process, and leaves a trace of the call chain.
[0080] The request routing module is used to determine whether a business request belongs to a Mock request, so as to decide whether to execute by the Mock processing module or by the request forwarding module next.
[0081] The Mock processing module is used to screen out the response data and header data of the Mock data from the database according to the database primary key corresponding to the Mock data, and fill the response data and header data of the Mock data into the response result corresponding to the business request.
[0082] The request forwarding processing module is used to forward the request parameters, header data, and body data of the business request to the business server corresponding to the business request, and fill the data feedback by the business server into the response result corresponding to the business request.
[0083] It can be understood that this application adopts the method of dynamically starting the Mock service port of the Mock server to realize the dynamic start of the Mock server for the external dependent services of the microservices. The Mock server configures for the business Mock domain name, automatically detects new ports and starts port listening, which can well solve the problems of many external dependencies and dynamic increase of the microservices. The Mock data of the Mock server can be isolated from each other according to the business system and support the call relationships of microservice systems with any complexity.
[0084] Figure 9 An example of the entity structure diagram of an electronic device is shown as Figure 9 shown. The electronic device may include: a processor 910, a communication interface 920, a memory 930, and a communication bus 940. Among them, the processor 910, the communication interface 920, and the memory 930 communicate with each other through the communication bus 940. The processor 910 can call the logical instructions in the memory 930 to execute the Mock service management method, which includes: sequentially starting the preset Host configuration update service and business service of the current container based on a preset startup script; the Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls the preset Host configuration interface of the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result; if the Host configuration information is updated, the business service sends a business request to the Mock server based on the updated Host configuration information.
[0085] In addition, when the logical instructions in the above-mentioned memory 930 can be implemented in the form of software functional units and sold or used as an independent product, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of this application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.
[0086] On the other hand, the present application also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the Mock service management method provided by each of the above methods. The method includes: sequentially starting a preset Host configuration update service and a business service of the current container based on a preset startup script; the Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls a preset Host configuration interface of the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result; if the Host configuration information is updated, the business service sends a business request to the Mock server based on the updated Host configuration information.
[0087] In another aspect, the present application also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is implemented to execute the Mock service management method provided by each of the above methods. The method includes: sequentially starting a preset Host configuration update service and a business service of the current container based on a preset startup script; the Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls a preset Host configuration interface of the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result; if the Host configuration information is updated, the business service sends a business request to the Mock server based on the updated Host configuration information.
[0088] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative labor.
[0089] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0090] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of each embodiment of the present application.
Claims
1. A Mock service management method, characterized in that: Container environment for clients, including: Start the preset Host configuration update service and business service of the current container in sequence based on the preset startup script; The Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls the Host configuration interface preset by the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result; If the Host configuration information is updated, the business service sends a business request to the Mock server based on the updated Host configuration information.
2. The Mock service management method according to claim 1, characterized in that: The Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server, calls the Host configuration interface preset by the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and determines whether to update the Host configuration information based on the query result, including: Read the Host configuration information of the current container from the Host configuration file of the current container; Calling the Host configuration interface of the Mock server to report the Host configuration information to the Mock server; Calling the Host configuration interface preset by the Mock server to query the Host resolution domain name corresponding to the Host configuration information, and obtaining the query result, wherein the query result includes query success and query failure; If the query is successful, the Host configuration information is updated based on the queried Host resolution domain name; if the query fails, the Host configuration information is restored to a preset initial value; After a preset time interval, return to the step of reading the Host configuration information of the current container from the Host configuration file of the current container until the Host configuration update service stops running.
3. The Mock service management method according to claim 1 or 2, characterized in that: The preset startup script is based on the preset Host configuration update service and business service of the current container, starting in sequence, including: Determine whether the current container has a Host configuration update service file. If so, execute the next step. If not, download the Host configuration update service file. Determine whether the current container has started the Host configuration update service, if so, execute the next step, if not, suspend the Host configuration update service file to start the Host configuration update service; Determine whether the business service has been started in the current container. If so, end the process. If not, start the business service and end the process.
4. A Mock service management method, characterized in that: Applicable to Mock servers, including: Obtaining Host configuration information of the current container reported by the client; the client is used to start the preset Host configuration update service and business service of the current container in sequence based on the preset startup script, and dynamically obtain and report the Host configuration information of the current container based on the Host configuration update service; In response to the client calling a preset Host configuration interface, the Host resolution domain name corresponding to the Host configuration information is queried, and the query result is fed back to the client. The client is also used to determine whether to update the Host configuration information based on the query result. If the Host configuration information is updated, a business request is sent to the Mock server based on the business service and the updated Host configuration information.
5. The Mock service management method according to claim 4, characterized in that: After receiving the service request, the method further includes: Start a call chain filling service to build a call chain corresponding to the business request; Extracting a domain name and a request path from the service request, and filtering and obtaining a Mock data list corresponding to the domain name and the request path from a pre-built database; According to the business scenario corresponding to the business request, extract the call chain unique identifier, the call chain user identifier or the request parameter from the business request, and determine whether the Mock data list contains Mock data corresponding to the call chain unique identifier, the call chain user identifier or the request parameter; If it exists, according to the database primary key corresponding to the Mock data, the response data and header data of the Mock data are obtained from the database, and the response data and header data of the Mock data are filled into the response result corresponding to the business request; If not, the request parameters, header data and body data of the business request are forwarded to the business server corresponding to the business request, and the data fed back by the business server is filled into the response result corresponding to the business request.
6. A Mock service management system, characterized in that: Including client and Mock server; The client is used to start the preset Host configuration update service and business service of the current container in sequence based on the preset startup script, and the Host configuration update service dynamically obtains the Host configuration information of the current container and reports it to the Mock server; The Mock server is used to obtain the Host configuration information of the current container reported by the client, and in response to the client calling a preset Host configuration interface, query the Host resolution domain name corresponding to the Host configuration information, and feed back the query result to the client. Correspondingly, the client is also used to determine whether to update the Host configuration information based on the query result. If the Host configuration information is updated, a business request is sent to the Mock server based on the business service and the updated Host configuration information.
7. The Mock service management system according to claim 6, characterized in that: The Mock server is also used to periodically query all Mock domain name configurations, extract a domain name port list from all the Mock domain name configurations, compare the domain name port list with a predetermined list of monitored ports, and determine whether there are any unmonitored domain name ports. If so, monitor the unmonitored domain name ports.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the Mock service management method according to any one of claims 1 to 5 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the Mock service management method according to any one of claims 1 to 5 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the Mock service management method according to any one of claims 1 to 5 is implemented.