Service instance control method, system and equipment based on micro-service architecture and medium
By receiving pre-downline notifications in the microservice architecture, updating the instance list and coordinating with the client, the problem of request response interruption when service instances are updated is solved, and seamless service updates and user experience improvements are achieved.
Patent Information
- Application Number
- CN202411720226.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-21
AI Technical Summary
In the microservice architecture, the service instance is directly and roughly stopped when the service instance is updated, resulting in interruption of request response or inability to arrive, affecting the user experience.
By receiving pre-download notifications of the target service instance, the instance list is updated, and coordinated with the client. After receiving the updated instance list, the client sends confirmation information to the server. After the server times to the preset time, the server controls the service instance to stop running.
It realizes seamless service updates, avoids request loss and service interruption, and improves the stability and user experience of the microservice architecture.
Smart Images

Figure CN119676300A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of microservice architecture technology, and in particular to a service instance control method, system, device and medium based on a microservice architecture. Background Art
[0002] With the rapid development of cloud computing technology, microservice architecture has gradually become the mainstream service deployment method in the industry today. In the microservice architecture, applications with the same set of functions are usually packaged into an application package and deployed to multiple virtual machines or containers to form multiple service instances. These service instances can handle client request traffic in parallel. When facing high concurrent requests, the processing capacity can be guaranteed by increasing the number of service instances. However, with the changes in business needs and the continuous iteration of application functions, new application packages need to be redeployed to virtual machines or containers to achieve functional upgrades of service instances.
[0003] The inventors found that in the process of redeployment, it is usually necessary to stop the service instance first, then deploy the new application package to the virtual machine or container, and then start the upgraded service instance. However, in the previous processing control process, the request being processed usually cannot be responded to due to the stop of the service instance, or the request that was just about to come in cannot be directly received, resulting in request loss and affecting the user experience. Summary of the invention
[0004] The embodiments of the present invention provide a service instance control method, apparatus, device and storage medium based on a microservice architecture to solve the problem that when an existing service instance is updated, the service instance is directly and roughly stopped, resulting in interruption or inability to reach the request response.
[0005] In a first aspect, a service instance control method based on a microservice architecture is provided, which is applied to a server, and the method includes: Receiving a pre-offline notification of a target service instance, wherein the pre-offline notification is used to indicate that the target service instance is about to be updated; According to the pre-offline notification, the state of the target service instance in the instance list is updated to pre-offline, and an updated instance list is obtained; Get the subscription request sent by the client at a preset time interval; According to the subscription request, the updated instance list is sent to the client, so that the client sends a confirmation message to the server after receiving the updated instance list; The confirmation information returned by the client is received, and after timing to a first preset time, the target service instance is controlled to stop running.
[0006] In a second aspect, a service instance control method based on a microservice architecture is provided, which is applied to a client, and the method includes: Sending a subscription request to the server at a preset time interval, so that the server sends an updated instance list to the client based on the subscription request, wherein the updated instance list is an instance list in which the server updates the state of the target service instance in the instance list to the pre-offline state after receiving the pre-offline notification of the target service instance; Receive the updated instance list sent by the server, and send confirmation information to the server, so that the server controls the target service instance to stop running after receiving the confirmation information returned by the client and timing to a first preset time.
[0007] In a third aspect, a service instance control system based on a microservice architecture is provided, wherein the service instance control system includes a server, and the server includes: A receiving module, configured to receive a pre-offline notification of a target service instance, wherein the pre-offline notification is used to indicate that the target service instance is about to be updated; An updating module, configured to update the state of the target service instance in the instance list to pre-offline according to the pre-offline notification, and obtain an updated instance list; An acquisition module is used to acquire subscription requests sent by the client at preset time intervals; A first sending module, configured to send the updated instance list to the client according to the subscription request, so that the client sends confirmation information to the server after receiving the updated instance list; The control module is used to receive the confirmation information returned by the client, and control the target service instance to stop running after timing to a first preset time.
[0008] In a fourth aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the service instance control method based on the microservice architecture described in the first aspect is implemented; alternatively, when the processor executes the computer program, the service instance control method based on the microservice architecture described in the second aspect is implemented.
[0009] In a fifth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the service instance control method based on the microservice architecture as described in the first aspect above is implemented, or when the processor executes the computer program, the service instance control method based on the microservice architecture as described in the second aspect above is implemented.
[0010] In a scheme implemented by the service instance control method, device, computer equipment and storage medium based on the microservice architecture, the method includes: receiving a pre-offline notification of a target service instance, wherein the pre-offline notification is used to indicate that the target service instance is about to be updated; according to the pre-offline notification, updating the state of the target service instance in the instance list to pre-offline, and obtaining an updated instance list; obtaining a subscription request sent by the client at a preset time interval; according to the subscription request, sending the updated instance list to the client, so that the client sends a confirmation message to the server after receiving the updated instance list; receiving the confirmation message returned by the client, and controlling the target service instance to stop running after the first preset time length. In this embodiment, the server receives the pre-offline notification of the target service instance, updates the instance list, and sends the updated instance list to the client in combination with the subscription request of the client, so that the client can stop sending new requests to the service instance to be updated in advance, and after a preset safety buffer period, the server controls the target service instance to go offline, thereby realizing seamless service update, avoiding request loss and service interruption, and improving the stability and user experience of the microservice architecture. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0012] Figure 1 This is a schematic diagram of an application environment of a service instance control method based on a microservice architecture in one embodiment of the present invention; Figure 2 is a flow chart of a service instance control method based on a microservice architecture in one embodiment of the present invention; Figure 3 is another flow chart of a service instance control method based on a microservice architecture in one embodiment of the present invention; Figure 4 is another flow chart of a service instance control method based on a microservice architecture in one embodiment of the present invention; Figure 5 is a schematic diagram of a service instance control system based on a microservice architecture in one embodiment of the present invention; Figure 6 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0013] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0014] The service instance control method based on the microservice architecture provided in the embodiment of the present invention can be applied as follows: Figure 1 Specifically, the service instance control method based on the microservice architecture is applied in a service instance control system based on the microservice architecture, and the service instance control system based on the microservice architecture includes: Figure 1 The client, server, and target machine shown. The client may include, but is not limited to, various personal computers, laptops, smart phones, and tablet computers. The target machine includes the machine where the virtual machine (or container) running the service instance is located. The server can be implemented as an independent server or a server cluster consisting of multiple servers.
[0015] A service instance control method based on a microservice architecture provided by the present invention will be described in detail with specific embodiments below.
[0016] First, as Figure 2 As shown, a service instance control method based on a microservice architecture is provided, and the method is applied in Figure 1 The server in the example is used as an example to illustrate the following steps: S101. Receive a pre-offline notification of a target service instance, where the pre-offline notification is used to indicate that the target service instance is about to be updated.
[0017] In this embodiment, the target service instance is one of a plurality of pre-built service instances, wherein the target service instance refers to a service instance that needs to be upgraded in terms of application functions.
[0018] In some implementations, the sending of the pre-offline notification can be automatically triggered by the target service instance when preparing to update, or it can be manually triggered by the administrator, which is not limited here. As an example, when the administrator packages the code containing the new function into a JAR application package, the JAR application package will be uploaded to the target machine running the target service instance, and then the target service instance can send the pre-offline notification message to the server through the communication mechanism in the microservice architecture (such as RESTful API, gRPC, etc.). Among them, the pre-offline notification includes IP address, identification information (such as service instance ID and service name), key and service name, etc.
[0019] It should be understood that the target service instance runs on a virtual machine or container built on the target machine, wherein a virtual machine is a complete computer system simulated by software, and a container is a lightweight, portable software packaging and operating environment.
[0020] It should be noted that before sending the pre-offline notification of the target service instance, a notification will be sent to the server to determine whether the target service instance and the server are connected. If the notification is successful, the pre-offline notification will be sent to the server.
[0021] S102: According to the pre-offline notification, update the status of the target service instance in the instance list to pre-offline, and obtain an updated instance list.
[0022] In this embodiment, the instance list may include but is not limited to the status of each service instance (such as online, pre-offline and offline), IP address, and identification information (such as service instance ID and service name).
[0023] In some implementations, after receiving the pre-offline notification sent by the target service instance, the server locates the record of the target service instance from the instance list maintained by the server according to the identification information of the target service instance contained in the pre-offline notification. After successfully matching the target service instance, the server will update the state of the target service instance from "online" to "pre-offline" according to the pre-offline notification, and generate an updated instance list.
[0024] S103: Obtain a subscription request sent by the client at a preset time interval.
[0025] In some implementations, the client sends a subscription request to the server at a preset time interval (e.g., 15 seconds or 20 seconds) set by the user to obtain the latest status of each service instance. Through this periodic subscription mechanism, it can be ensured that the client always maintains the latest perception of the status of each service instance in the instance list when the service instance status changes, thereby achieving dynamic adjustment of the request.
[0026] S104: Send the updated instance list to the client according to the subscription request, so that the client sends confirmation information to the server after receiving the updated instance list.
[0027] In this embodiment, after receiving the subscription request sent by the client, the server will send the updated instance list containing the latest status of the target service instance (such as the "pre-offline" status) to the client. After receiving the updated instance list, the client will adjust its request routing logic according to the status of the target service instance.
[0028] For example, when the status of the target service instance is "pre-offline", the client will stop sending new requests to the target service instance and send a confirmation message to the server through a communication mechanism (such as HTTP request or message queue) to indicate that the service instance status has been synchronized. This two-way interactive mechanism further reduces the situation where the client does not receive the updated instance list and the server directly stops the pre-offline service instance, resulting in request loss.
[0029] S105: Receive confirmation information returned by the client, and after timing to a first preset time, control the target service instance to stop running.
[0030] In this embodiment, the confirmation information is used to indicate that the client has received the updated instance list.
[0031] In some embodiments, after receiving the confirmation information from the client, the server starts timing until the first preset duration is reached. When the first preset duration is reached, the server will control the target service instance to stop running and remove the target service instance from the instance list, thereby avoiding the problem of request response interruption or inability to arrive due to direct and rough stopping of the service instance, achieving seamless service updates and improving user experience. It should be noted that the above-mentioned first preset duration can be 5 seconds, 6 seconds, 7 seconds or 8 seconds, etc., which is only used as an example here and does not constitute a limitation of the present invention.
[0032] In summary, the server receives a pre-offline notification sent by the target service instance, which is used to indicate that the target service instance is about to be updated. Based on the pre-offline notification, the server locates the target service instance in the instance list and updates its status to "pre-offline", thereby generating an updated instance list. Subsequently, the server obtains the subscription request sent by the client at a preset time interval, and based on the subscription request, sends the updated instance list to the client, so that the client knows the latest status of the target service instance. When the client receives the updated instance list, it sends a confirmation message to the server, indicating that it has completed status synchronization. After receiving the confirmation message, the server starts timing, and after the first preset time is reached, the target service instance is controlled to stop running, thereby realizing seamless service updates, avoiding request loss and service interruptions, and improving the stability and user experience of the microservice architecture.
[0033] As an example, in an online banking system, the service instance "TransactionService-X" is responsible for processing user transaction requests. When the function of "TransactionService-X" needs to be upgraded, the service instance will send a pre-offline notification to the server. The pre-offline notification includes the service instance's IP address "192.xxx.1.x", the service instance ID "TSX-01" and the key "SecureKey123". After receiving the pre-offline notification, the server searches for the corresponding "TransactionService-X" entry in the instance list and updates its status from "online" to "pre-offline".
[0034] The client (such as a mobile banking app or online banking page) will send a subscription request to the server at a preset interval of 15 seconds to ensure that it obtains the latest instance list. After receiving the subscription request, the server sends the updated instance list to the client, in which the status of "TransactionService-X" is marked as "pre-offline". After receiving the updated instance list, the client stops sending new transaction requests to "TransactionService-X" and assigns the user's new transactions to other service instances with a status of "online", such as "TransactionService-Y" or "TransactionService-Z".
[0035] After the client completes the instance list synchronization, it will send a confirmation message to the server. After receiving the confirmation message, the server starts timing. For example, the first preset time is set to 5 seconds. After the timer ends, the server controls "TransactionService-X" to stop running, so as to ensure that it can be upgraded safely and avoid affecting the user's transaction experience.
[0036] It should be understood that the above is only an example and does not constitute a limitation of the present invention.
[0037] In one embodiment, in step S102, that is, according to the pre-offline notification, the state of the target service instance in the instance list is updated to pre-offline, and the updated instance list is obtained, including the following steps: S1021, obtaining a first IP address for sending the pre-logoffline notification, and parsing a first key from the pre-logoffline notification; S1022. Query the second IP address and the second key corresponding to the target service instance from the authentication data table; S1023. Using a fixed algorithm, verify whether the first IP address matches the second IP address, and whether the first key is consistent with the second key; S1024. If the first IP address matches the second IP address, and the first key is consistent with the second key, updating the state of the target service instance in the instance list to pre-offline, and obtaining an updated instance list; S1025. If the first IP address does not match the second IP address, and / or the first key does not match the second key, refusing to update the status of the target service instance in the instance list to pre-offline; S1026: If the number of times that the status of the target service instance in the instance list is refused to be updated to pre-offline is greater than or equal to a preset number within a second preset time period, the first IP address is added to a blacklist.
[0038] In this embodiment, the fixed algorithm includes but is not limited to a symmetric encryption algorithm, an asymmetric encryption algorithm or a hash algorithm. The authentication data table stores information such as the IP address, key, service instance ID and service name corresponding to each service instance.
[0039] In some embodiments, after receiving the pre-offline notification of the target service instance, the server will obtain the first IP address for sending the pre-offline notification, and extract the first key for sending the pre-offline request from the pre-offline notification. Next, the server will query the authentication data table to obtain the second IP address and the second key of the target service instance. Then, a fixed algorithm is used to match the first IP address with the second IP address, and the first key with the second key. If both match, it indicates that the pre-offline request is legal, and the server allows the status of the target service instance to be updated to "pre-offline" and generates an updated instance list. If the match fails, it indicates that the pre-offline request is illegal, and the server will reject the pre-offline request and will not allow the status of the target service instance to be updated to "pre-offline". In addition, if illegal pre-offline notifications appear multiple times within the second preset time, the server will take protective measures to add the IP address that sends the pre-offline request to the blacklist and block the IP address, thereby preventing malicious attacks. It should be understood that the second preset duration may be 1 minute, 2 minutes, 3 minutes or 5 minutes, etc., which is only used as an example here and does not constitute a limitation of the present invention.
[0040] Through the above method, the server can ensure that the update process of the service instance is both safe and not subject to malicious interference, avoiding potential service interruptions or security issues caused by illegal requests, effectively preventing unauthorized service instance operations, and enhancing reliability.
[0041] It should be understood that the above-mentioned preset number of times may be 3 times, 4 times, 5 times, 6 times, 7 times or 8 times, etc., which is only used as an example here and does not constitute a limitation to the present invention.
[0042] As an example, Figure 3 As shown, assuming that service instance C needs to be updated, service instance C will send a pre-offline notification to the server. After receiving the pre-offline notification, the server will obtain the first IP address (assuming it is "192.xxx.1.13") that sent the pre-offline notification, and parse out the first key (for example, "abc123") in the pre-offline notification. Then, the server will query the authentication data table to find the second IP address and second key of instance B. Assume that the second IP address corresponding to service instance C is "192.xxx.1.13" and the second key is "abc123". Then, use a fixed algorithm (for example, a hash algorithm) to verify whether the first IP address matches the second IP address and whether the first key matches the second key. If the verification passes, that is, if the first IP address matches the second IP address and the first key matches the second key, the status of service instance C is updated to "pre-offline". If the verification fails, that is, if the first IP address does not match the second IP address, and / or the first key does not match the second key, it is prohibited to update the status of the service instance C to "pre-offline".
[0043] However, if someone tries to forge a pre-offline notification and send it to the server, suppose the first IP address sent is "192.xxx.1.14" and the key is "wrongkey". In this case, the server will find that the IP address does not match the expected IP address of service instance C, and the key is inconsistent, so it will refuse to update the status of service instance C and keep its original status as "online". If the malicious request is sent multiple times within a certain period of time (for example, more than 3 times the preset number), the server will add the IP address ("192.xxx.1.11") to the blacklist to prevent the IP address from launching further attacks.
[0044] It should be noted that the above is only an example and does not constitute a limitation of the present invention.
[0045] In one embodiment, in step S105, that is, receiving the confirmation information returned by the client and timing to the first preset time, controlling the target service instance to stop running includes the following steps: S1051, when receiving the confirmation information returned by the client and timing to a first preset time, determining whether the target service instance has any unfinished processing tasks; S1052: If it does not exist, control the target service instance to stop running; S1053: If so, control the target service instance to continue executing the unfinished processing task until it is completed.
[0046] In some embodiments, after receiving the confirmation information returned by the client and timing to the first preset time, the server will further determine whether there are still unfinished processing tasks for the target service instance. If there are no unfinished processing tasks, the server will directly control the target service instance to stop running and remove the target service instance from the instance list. If there are unfinished processing tasks, the server will continue to monitor the processing status of the service instance until all tasks are completed, and then stop the target service instance. Through the above method, it is ensured that when the service instance is upgrading the application function, the tasks or data being processed will not be lost, further improving the user experience.
[0047] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0048] Second, as Figure 3 and 4 As shown, a service instance control method based on a microservice architecture is provided, and the method is applied in Figure 1 The client in the example is used to illustrate the process, including the following steps: S201, sending a subscription request to the server at a preset time interval, so that the server sends an updated instance list to the client based on the subscription request, wherein the updated instance list is an instance list in which the server updates the state of the target service instance in the instance list to the pre-offline state after receiving a pre-offline notification of the target service instance; S202, receiving the updated instance list sent by the server, and sending confirmation information to the server, so that the server controls the target service instance to stop running after receiving the confirmation information returned by the client and timing to a first preset time.
[0049] In some embodiments, the client sends a subscription request to the server at a preset time interval (e.g., every 5 seconds or 10 seconds), and the purpose of the subscription request is to obtain the status of each service instance in the instance list from the server. Specifically, each time the server receives a subscription request, it returns the current instance list to the client, where the current instance list can be an updated instance list. For example, the server receives a pre-offline notification of the target service instance, and updates the status of the target service instance in the instance list to the instance list generated after "pre-offline", thereby ensuring that the client can obtain the latest status of each service instance.
[0050] When the client receives the instance list, it will send a confirmation message to the server so that the server can perform subsequent operations after receiving the confirmation message. For example, when the server sends an updated instance list, after the server receives the confirmation message returned by the client, it starts timing and controls the target service instance to stop running after the first preset time, so as to avoid the problem of direct stopping of the service instance, resulting in request loss and service interruption, thereby improving the stability of the microservice architecture and user experience.
[0051] It should be noted that the specific real-time details of the above steps S201 to S202 can refer to the description of steps S101 to S105, and will not be repeated here to avoid repetition.
[0052] In one embodiment, after step S202, that is, after receiving the updated instance list sent by the server and sending confirmation information to the server, the following steps are included: S203, judging whether to continue to send a new request to the target service instance according to the state of the target service instance in the updated instance list; S204: If the status of the target service instance is pre-offline, stop sending new requests to the target service instance; S205: If the status of the target service instance is online, continue to send new requests to the target service instance.
[0053] In one embodiment, if the client receives an updated instance list, it first determines whether to continue to send new requests to the target service instance according to the status of the target service instance in the updated instance list. As an example, if the status of the target service instance is "pre-offline", the client will stop sending new requests to the target service instance to avoid losing new requests. On the contrary, if the status of the target service instance is "online", the client will continue to send new requests to the service instance.
[0054] In one embodiment, after step S204, that is, after stopping sending new requests to the target service instance if the status of the target service instance is pre-offline, the following steps are included: S206, filtering out service instances in an online state from the updated instance list as online service instances; S207: Allocate the new request to the online service instance based on a load balancing algorithm.
[0055] In this embodiment, the load balancing algorithm includes but is not limited to the classic random algorithm and the polling algorithm. Among them, the classic random algorithm randomly selects a service instance with a status of "online" from the instance list each time. The polling algorithm traverses all service instances with a status of "online" in the instance list in a certain order.
[0056] In some implementations, after receiving the updated instance list sent by the server, if the status of the target service instance is "pre-offline", the client stops sending new requests to the target service instance. Next, the client will filter out the service instances with a status of "online" from the updated instance list and regard these instances as "online service instances". Next, the client will distribute new requests to these online service instances based on the load balancing algorithm, ensuring that new requests can be evenly distributed to the currently available service instances and reducing the problem of excessive load or uneven request processing.
[0057] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0058] like Figure 3 As shown, the following is a complete example of the service instance control method based on the microservice architecture provided by the present invention: Assume that the pre-built service instances include service instances A, B, and C, where, during operation, each service instance will send a heartbeat to the server at a preset duration (for example, 5 seconds) to indicate that the service instance is a normally running service instance. However, when it is necessary to upgrade the function of one of the service instances, for example, when upgrading service instance C, service instance C will send a pre-offline notification to the server. After receiving the pre-offline notification, the server will update the status of service instance C to "pre-offline". The client will send a subscription request to the server at a preset time interval. At this time, after the client subscribes to the instance list, it will find that the status of service instance C is "pre-offline", so it stops sending new requests to service instance C. Next, the client filters out service instances A and B with a status of "online" from the instance list, and distributes new requests to service instances A and B based on the load balancing algorithm. In addition, the server will directly remove service instances that have no heartbeat for more than a preset period (for example, 3 periods) to prevent the client from subscribing to a downed service instance, ensuring that each request can be responded to quickly, avoiding request loss and service interruption, and improving user experience.
[0059] It should be noted that the preset period can also be 4 periods, wherein the duration of each period can be 5 seconds or 6 seconds, etc., which is not limited here and does not constitute a limitation on the present invention.
[0060] In a third aspect, a service instance control system based on a microservice architecture is provided, wherein the service instance control system includes a server, such as Figure 5 As shown, the server includes a receiving module 101, an updating module 102, an acquiring module 103, a first sending module 104 and a control module 105. Each functional module is described in detail as follows: A receiving module 101 is used to receive a pre-offline notification of a target service instance, where the pre-offline notification is used to indicate that the target service instance is about to be updated; An updating module 102 is configured to update the state of the target service instance in the instance list to pre-offline according to the pre-offline notification, and obtain an updated instance list; The acquisition module 103 is used to acquire the subscription request sent by the client at a preset time interval; A first sending module 104, configured to send the updated instance list to the client according to the subscription request, so that the client sends confirmation information to the server after receiving the updated instance list; The control module 105 is used to receive the confirmation information returned by the client, and control the target service instance to stop running after timing to a first preset time.
[0061] In one embodiment, the updating module 102 is specifically configured to: Acquire a first IP address for sending the pre-offline notification, and parse a first key from the pre-offline notification; Query the second IP address and the second key corresponding to the target service instance from the authentication data table; Using a fixed algorithm, verify whether the first IP address matches the second IP address, and whether the first key is consistent with the second key; If the first IP address matches the second IP address, and the first key is consistent with the second key, updating the state of the target service instance in the instance list to pre-offline, and obtaining an updated instance list; If the first IP address does not match the second IP address, and / or the first key does not match the second key, then the status of the target service instance in the instance list is refused to be updated to pre-offline.
[0062] In one embodiment, the updating module 102 is further configured to: If within a second preset time period, the number of times that the status of the target service instance in the instance list is refused to be updated to pre-offline is greater than or equal to a preset number of times, the first IP address is added to the blacklist.
[0063] In one embodiment, the control module 105 is specifically configured to: When receiving the confirmation information returned by the client and timing to a first preset time, determining whether the target service instance has any unfinished processing tasks; If it does not exist, controlling the target service instance to stop running; If so, the target service instance is controlled to continue executing the unfinished processing task until it is completed.
[0064] In one embodiment, the service instance control system further includes a client, and the client includes a second sending module 201 and a third sending module 202. Each functional module is described in detail as follows: The second sending module 201 is used to send a subscription request to the server at a preset time interval, so that the server sends an updated instance list to the client based on the subscription request, and the updated instance list is the instance list in which the server updates the state of the target service instance in the instance list to the pre-offline instance list after receiving the pre-offline notification of the target service instance; The third sending module 202 is used to receive the updated instance list sent by the server and send a confirmation message to the server, so that the server controls the target service instance to stop running after receiving the confirmation message returned by the client and timing to a first preset time.
[0065] In one embodiment, the client further includes a determination module 203; The determination module 203 is specifically used for: Determine whether to continue sending a new request to the target service instance according to the status of the target service instance in the updated instance list; If the status of the target service instance is pre-offline, stop sending new requests to the target service instance; If the status of the target service instance is online, continue to send new requests to the target service instance.
[0066] In one embodiment, the client further includes an allocation module 204; The allocation module 204 is specifically used for: Filter out service instances in an online state from the updated instance list as online service instances; Based on the load balancing algorithm, new requests are allocated to the online service instances.
[0067] For the specific limitations of the service instance control system based on the microservice architecture, please refer to the limitations of the service instance control method based on the microservice architecture above. In order to avoid repetition, it will not be repeated here.
[0068] In a fourth aspect, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 6 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data required for running a service instance control method based on a microservice architecture. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements the service instance control method based on the microservice architecture described in the first aspect above, or, when the computer program is executed by the processor, it implements the service instance control method based on the microservice architecture described in the second aspect above.
[0069] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented: Receiving a pre-offline notification of a target service instance, wherein the pre-offline notification is used to indicate that the target service instance is about to be updated; According to the pre-offline notification, the state of the target service instance in the instance list is updated to pre-offline, and an updated instance list is obtained; Get the subscription request sent by the client at a preset time interval; According to the subscription request, the updated instance list is sent to the client, so that the client sends a confirmation message to the server after receiving the updated instance list; The confirmation information returned by the client is received, and after timing to a first preset time, the target service instance is controlled to stop running.
[0070] or, Sending a subscription request to the server at a preset time interval, so that the server sends an updated instance list to the client based on the subscription request, wherein the updated instance list is an instance list in which the server updates the state of the target service instance in the instance list to the pre-offline state after receiving the pre-offline notification of the target service instance; Receive the updated instance list sent by the server, and send confirmation information to the server, so that the server controls the target service instance to stop running after receiving the confirmation information returned by the client and timing to a first preset time.
[0071] In a fifth aspect, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the following steps are implemented: Receiving a pre-offline notification of a target service instance, wherein the pre-offline notification is used to indicate that the target service instance is about to be updated; According to the pre-offline notification, the state of the target service instance in the instance list is updated to pre-offline, and an updated instance list is obtained; Get the subscription request sent by the client at a preset time interval; According to the subscription request, the updated instance list is sent to the client, so that the client sends a confirmation message to the server after receiving the updated instance list; The confirmation information returned by the client is received, and after timing to a first preset time, the target service instance is controlled to stop running.
[0072] or, Sending a subscription request to the server at a preset time interval, so that the server sends an updated instance list to the client based on the subscription request, wherein the updated instance list is an instance list in which the server updates the state of the target service instance in the instance list to the pre-offline state after receiving the pre-offline notification of the target service instance; Receive the updated instance list sent by the server, and send confirmation information to the server, so that the server controls the target service instance to stop running after receiving the confirmation information returned by the client and timing to a first preset time.
[0073] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0074] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0075] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A service instance control method based on microservice architecture, characterized in that: Applied to the server, the method includes: Receiving a pre-offline notification of a target service instance, wherein the pre-offline notification is used to indicate that the target service instance is about to be updated; According to the pre-offline notification, the state of the target service instance in the instance list is updated to pre-offline, and an updated instance list is obtained; Get the subscription request sent by the client at a preset time interval; According to the subscription request, the updated instance list is sent to the client, so that the client sends a confirmation message to the server after receiving the updated instance list; The confirmation information returned by the client is received, and after timing to a first preset time, the target service instance is controlled to stop running.
2. The service instance control method based on microservice architecture according to claim 1, characterized in that: The updating, according to the pre-offline notification, of the state of the target service instance in the instance list to pre-offline, and obtaining an updated instance list, comprises: Acquire a first IP address for sending the pre-offline notification, and parse a first key from the pre-offline notification; Query the second IP address and the second key corresponding to the target service instance from the authentication data table; Using a fixed algorithm, verify whether the first IP address matches the second IP address, and whether the first key is consistent with the second key; If the first IP address matches the second IP address, and the first key is consistent with the second key, updating the state of the target service instance in the instance list to pre-offline, and obtaining an updated instance list; If the first IP address does not match the second IP address, and / or the first key does not match the second key, then the status of the target service instance in the instance list is refused to be updated to pre-offline.
3. The service instance control method based on microservice architecture as claimed in claim 2, characterized in that: If within a second preset time period, the number of times that the status of the target service instance in the instance list is refused to be updated to pre-offline is greater than or equal to a preset number of times, the first IP address is added to the blacklist.
4. The service instance control method based on microservice architecture according to claim 1, characterized in that: The receiving of the confirmation information returned by the client and controlling the target service instance to stop running after the first preset time has elapsed includes: When receiving the confirmation information returned by the client and timing to a first preset time, determining whether the target service instance has any unfinished processing tasks; If it does not exist, controlling the target service instance to stop running; If so, the target service instance is controlled to continue executing the unfinished processing task until it is completed.
5. A service instance control method based on microservice architecture, characterized in that: Applied to a client, the method comprises: Sending a subscription request to the server at a preset time interval, so that the server sends an updated instance list to the client based on the subscription request, wherein the updated instance list is an instance list in which the server updates the state of the target service instance in the instance list to the pre-offline state after receiving the pre-offline notification of the target service instance; Receive the updated instance list sent by the server, and send confirmation information to the server, so that the server controls the target service instance to stop running after receiving the confirmation information returned by the client and timing to a first preset time.
6. The service instance control method based on microservice architecture according to claim 5, characterized in that: After receiving the updated instance list sent by the server and sending confirmation information to the server, the method further includes: Determine whether to continue sending a new request to the target service instance according to the status of the target service instance in the updated instance list; If the status of the target service instance is pre-offline, stop sending new requests to the target service instance; If the status of the target service instance is online, continue to send new requests to the target service instance.
7. The service instance control method based on microservice architecture according to claim 6, characterized in that: If the state of the target service instance is pre-offline, then after stopping sending new requests to the target service instance, the method further comprises: Filter out service instances in an online state from the updated instance list as online service instances; Based on the load balancing algorithm, new requests are allocated to the online service instances.
8. A service instance control system based on microservice architecture, characterized in that: The service instance control system includes a server, and the server includes: A receiving module, configured to receive a pre-offline notification of a target service instance, wherein the pre-offline notification is used to indicate that the target service instance is about to be updated; An updating module, configured to update the state of the target service instance in the instance list to pre-offline according to the pre-offline notification, and obtain an updated instance list; An acquisition module is used to acquire subscription requests sent by the client at preset time intervals; A first sending module, configured to send the updated instance list to the client according to the subscription request, so that the client sends confirmation information to the server after receiving the updated instance list; The control module is used to receive the confirmation information returned by the client, and control the target service instance to stop running after timing to a first preset time.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the service instance control method based on the microservice architecture is implemented as described in any one of claims 1 to 4, or, when the processor executes the computer program, the service instance control method based on the microservice architecture is implemented as described in any one of claims 5 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by the processor, the service instance control method based on the microservice architecture as described in any one of claims 1 to 4 is implemented, or when the processor executes the computer program, the service instance control method based on the microservice architecture as described in any one of claims 5 to 7 is implemented.