Method, device, electronic equipment and computer readable medium for accessing a service

By periodically querying the address information of the registry center for service consumers and retaining the local information when the information is empty, the service interruption problem caused by registry center upgrades and restarts is resolved, ensuring the stability of service access.

CN116582594BActive Publication Date: 2025-11-11CHINA CONSTRUCTION BANK +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310685676.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-09
Publication Date
2025-11-11
Estimated Expiration
2043-06-09

AI Technical Summary

Technical Problem

During the process of upgrading and restarting nodes one by one, the registration center may experience temporary failures and be unable to provide services, resulting in service consumers being unable to obtain valid address information and access the services.

Method used

Service consumers query the registry center for the latest address information via scheduled tasks. If the information is empty, the local address information is retained; otherwise, it is updated to the latest address information, or the local address information is deleted after a certain number of times or a certain time threshold is reached.

Benefits of technology

This avoids request failures due to the registry center's inability to provide addressing services, ensuring that service consumers can continuously access the service.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116582594B_ABST
    Figure CN116582594B_ABST
Patent Text Reader

Abstract

This invention discloses a method, apparatus, electronic device, and computer-readable medium for accessing services, relating to the field of microservices technology. One specific embodiment of the method includes: sending an address query request to a registry center, the address query request carrying a service identifier; receiving the latest address information corresponding to the service identifier returned by the registry center; ignoring the latest address information corresponding to the service identifier if it is empty, and retaining the address information corresponding to the service identifier already stored locally; and updating the address information corresponding to the service identifier already stored locally to the latest address information corresponding to the service identifier if it is not empty. This embodiment can solve the technical problem of request failure caused by the registry center being unable to provide services during node upgrades and restarts.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of microservices technology, and more particularly to a method, apparatus, electronic device, and computer-readable medium for accessing services. Background Technology

[0002] Nacos or ZooKeeper are widely used as service registry centers in distributed systems, providing addressing functionality for service consumers. Figure 1 As shown, Step 1: The service consumer sends an address query request to the registration center; Step 2: The registration center returns the queried service provider's address information to the service consumer; Step 3: The service consumer sends a business request to the service provider based on the received service provider's address information, thereby accessing the service.

[0003] In the process of realizing this invention, the inventors discovered at least the following problems in the prior art:

[0004] During the process of upgrading and restarting nodes one by one, the registry center may experience temporary failures and be unable to provide services. In other words, the address information obtained by service consumers from the registry center will be empty, and they will not be able to obtain valid address information, thus preventing service consumers from accessing the service. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method, apparatus, electronic device, and computer-readable medium for accessing services, to solve the technical problem of request failure caused by the inability of the registry center to provide services during the process of upgrading and restarting nodes one by one.

[0006] To achieve the above objectives, according to one aspect of the present invention, a method for accessing a service is provided, applied to a service consumer, comprising:

[0007] Send an address query request to the registration center, the address query request carrying a service identifier;

[0008] The system receives the latest address information corresponding to the service identifier returned by the registration center; wherein the registration center is used to register each service and stores the latest address information corresponding to each service identifier.

[0009] In response to the fact that the latest address information corresponding to the service identifier is empty, the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier that has been stored locally is retained;

[0010] In response to the fact that the latest address information corresponding to the service identifier is not empty, the address information corresponding to the service identifier that is already stored locally is updated to the latest address information corresponding to the service identifier.

[0011] Optionally, in response to the latest address information corresponding to the service identifier being non-empty, updating the address information corresponding to the service identifier already stored locally to the latest address information corresponding to the service identifier includes:

[0012] In response to the fact that the latest address information corresponding to the service identifier is not empty, compare whether the address information corresponding to the service identifier already stored locally is consistent with the latest address information corresponding to the service identifier;

[0013] If so, ignore the latest address information corresponding to the service identifier and retain the address information corresponding to the service identifier that has been stored locally;

[0014] If not, the address information corresponding to the service identifier already stored locally will be updated to the latest address information corresponding to the service identifier.

[0015] Optionally, in response to the latest address information corresponding to the service identifier being empty, after ignoring the latest address information corresponding to the service identifier and retaining the address information corresponding to the service identifier already stored locally, the method further includes:

[0016] The number of times the latest address information corresponding to the service identifier is continuously empty is accumulated. In response to the number of times the latest address information corresponding to the service identifier is continuously empty being greater than or equal to the number of times, the address information corresponding to the service identifier that has been stored locally is deleted.

[0017] Optionally, in response to the latest address information corresponding to the service identifier being empty, after ignoring the latest address information corresponding to the service identifier and retaining the address information corresponding to the service identifier already stored locally, the method further includes:

[0018] If the duration of the latest address information corresponding to the service identifier being continuously empty is greater than or equal to a duration threshold, the address information corresponding to the service identifier that has been stored locally will be deleted.

[0019] Optionally, before sending an address lookup request to the registry center, the following steps are also included:

[0020] Send a service query request to the registration center, the service query request carrying service keywords;

[0021] Receive the service name and service identifier corresponding to the service keyword returned by the registration center;

[0022] Configure one or more of the service identifiers corresponding to the service keywords as the service identifiers carried in the address query request.

[0023] Optionally, it also includes:

[0024] Determine the target service that needs to be accessed, and obtain the address information corresponding to the target service from the local machine;

[0025] A service request is assembled based on the address information and service information corresponding to the target service, thereby accessing the target service.

[0026] Optionally, the registration center is a Nacos cluster or a ZooKeeper cluster.

[0027] Furthermore, according to another aspect of the present invention, an apparatus for accessing a service is provided, disposed at a service consumer, comprising:

[0028] The query module is used to send an address query request to the registration center, and the address query request carries a service identifier;

[0029] A receiving module is used to receive the latest address information corresponding to the service identifier returned by the registration center; wherein, the registration center is used to register each service and store the latest address information corresponding to each service identifier;

[0030] The storage module is configured to, in response to the latest address information corresponding to the service identifier being empty, ignore the latest address information corresponding to the service identifier and retain the address information corresponding to the service identifier already stored locally; and in response to the latest address information corresponding to the service identifier not being empty, update the address information corresponding to the service identifier already stored locally to the latest address information corresponding to the service identifier.

[0031] Optionally, the storage module is further configured to:

[0032] In response to the fact that the latest address information corresponding to the service identifier is not empty, compare whether the address information corresponding to the service identifier already stored locally is consistent with the latest address information corresponding to the service identifier;

[0033] If so, ignore the latest address information corresponding to the service identifier and retain the address information corresponding to the service identifier that has been stored locally;

[0034] If not, the address information corresponding to the service identifier already stored locally will be updated to the latest address information corresponding to the service identifier.

[0035] Optionally, the storage module is further configured to:

[0036] In response to the latest address information corresponding to the service identifier being empty, the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier already stored locally is retained. The number of times the latest address information corresponding to the service identifier is continuously empty is accumulated. In response to the number of times the latest address information corresponding to the service identifier is continuously empty being greater than or equal to the number of times the number of times the latest address information corresponding to the service identifier is continuously empty being greater than or equal to the number of times the number of times the address information corresponding to the service identifier is continuously empty being deleted from the local storage.

[0037] Optionally, the storage module is further configured to:

[0038] In response to the latest address information corresponding to the service identifier being empty, the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier already stored locally is retained. The duration for which the latest address information corresponding to the service identifier is continuously empty is accumulated. In response to the duration for which the latest address information corresponding to the service identifier is continuously empty being greater than or equal to the duration threshold, the address information corresponding to the service identifier already stored locally is deleted.

[0039] Optionally, the query module is further configured to:

[0040] Send a service query request to the registration center, the service query request carrying service keywords;

[0041] Receive the service name and service identifier corresponding to the service keyword returned by the registration center;

[0042] Configure one or more of the service identifiers corresponding to the service keywords as the service identifiers carried in the address query request.

[0043] Optionally, an access module is also included for:

[0044] Determine the target service that needs to be accessed, and obtain the address information corresponding to the target service from the local machine;

[0045] A service request is assembled based on the address information and service information corresponding to the target service, thereby accessing the target service.

[0046] Optionally, the registration center is a Nacos cluster or a ZooKeeper cluster.

[0047] According to another aspect of the present invention, an electronic device is also provided, comprising:

[0048] One or more processors;

[0049] Storage device for storing one or more programs.

[0050] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the above embodiments.

[0051] According to another aspect of the present invention, a computer-readable medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the methods described in any of the above embodiments.

[0052] According to another aspect of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements the methods described in any of the above embodiments.

[0053] One embodiment of the above invention has the following advantages or beneficial effects: Because it employs the technical means of ignoring the latest address information corresponding to the service identifier when it is empty, and retaining the address information already stored locally, and updating the address information already stored locally to the latest address information when it is not empty, it overcomes the technical problem in the prior art where requests fail due to the registry center's inability to provide services during node upgrades and restarts. This embodiment of the invention uses a scheduled task to periodically query the latest address information from the registry center. If the address information is empty, the address information already stored locally is retained, thereby avoiding the problem of request failure due to the registry center's inability to provide addressing services.

[0054] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description

[0055] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein:

[0056] Figure 1 This is a schematic diagram of the system architecture for serving consumers accessing services in the existing technology;

[0057] Figure 2 This is a flowchart of a method for accessing services according to an embodiment of the present invention;

[0058] Figure 3 This is a flowchart of a method for accessing a service according to a possible embodiment of the present invention;

[0059] Figure 4This is a flowchart of a method for accessing a service according to another applicable embodiment of the present invention;

[0060] Figure 5 This is a flowchart of a method for accessing a service according to another possible embodiment of the present invention;

[0061] Figure 6 This is a schematic diagram of an apparatus for accessing services according to an embodiment of the present invention;

[0062] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;

[0063] Figure 8 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation

[0064] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0065] It should be noted that the collection, analysis, use, transmission, and storage of user personal information involved in the technical solution of this invention all comply with relevant laws and regulations, are used for legitimate and reasonable purposes, and are not shared, disclosed, or sold outside of these legitimate uses, and are subject to supervision and management by regulatory authorities. Necessary measures should be taken to prevent unauthorized access to such personal information data, ensure that personnel authorized to access personal information data comply with relevant laws and regulations, and ensure the security of user personal information. Once this user personal information data is no longer needed, the risk should be minimized by restricting or even prohibiting data collection and / or deleting the data.

[0066] When applicable, including in certain relevant applications, data deidentification is used to protect user privacy, such as by removing specific identifiers (e.g., account, name, gender, date of birth, etc.), controlling the amount or specificity of stored data, controlling how data is stored, and / or other methods of deidentification.

[0067] Figure 2 This is a flowchart of a method for accessing a service according to an embodiment of the present invention. As one embodiment of the present invention, such as... Figure 2 As shown, the method for accessing the service is applied to service consumers and may include:

[0068] Step 201: Send an address query request to the registration center, the address query request carrying a service identifier.

[0069] The service consumer executes steps 201-205 periodically via a scheduled task. This means that the service consumer periodically queries the registration center for the address information of the services provided by the service provider and stores the address information obtained from the registration center on the service consumer's local machine. When the service consumer needs to access a certain service, it directly retrieves the address information of that service from its local machine.

[0070] The registry center is the communication hub in a microservice architecture, from which service consumers can obtain information such as the address and status of service providers. Optionally, the registry center can be a Nacos cluster or a ZooKeeper cluster.

[0071] In this step, the service consumer sends an address lookup request to the registry center, which may carry one or more service identifiers.

[0072] Step 202: Receive the latest address information corresponding to the service identifier returned by the registration center; wherein, the registration center is used to register each service and store the latest address information corresponding to each service identifier.

[0073] After receiving an address query request from a service consumer, the registry parses it and, based on one or more service identifiers, matches the latest address information corresponding to each service identifier. The registry then returns this latest address information to the service consumer. The service consumer receives the latest address information for each service identifier returned by the registry.

[0074] It should be noted that before a service provider provides services to the outside world, it needs to register the latest address information of the service with the registry center. The registry center assigns a service identifier to the registered services and stores each service identifier and its corresponding latest address information.

[0075] Step 203: Is the latest address information corresponding to the service identifier empty? If yes, proceed to step 204; if no, proceed to step 205.

[0076] The service consumer checks one by one whether the latest address information corresponding to each received service identifier is empty.

[0077] Step 204: Ignore the latest address information corresponding to the service identifier, and retain the address information corresponding to the service identifier that has been stored locally.

[0078] If the latest address information corresponding to the service identifier is empty, it means that the registry center is temporarily unable to provide addressing services. In this case, the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier that is already stored locally on the service consumer is retained.

[0079] Step 205: Update the address information corresponding to the service identifier that is already stored locally to the latest address information corresponding to the service identifier.

[0080] If the latest address information corresponding to the service identifier is not empty, then the address information already stored locally by the service consumer for that service identifier will be updated to the latest address information. This means that if the registry center can provide addressing services, then the latest obtained address information will overwrite the address information already stored locally by the service consumer.

[0081] It should be noted that the address information corresponding to the service identifier already stored locally on the service consumer's machine may be the same as or different from the latest address information corresponding to the service identifier retrieved from the registry center.

[0082] Optionally, step 205 may include: comparing whether the address information corresponding to the service identifier already stored locally is consistent with the latest address information corresponding to the service identifier; if yes, then the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier already stored locally is retained; if no, then the address information corresponding to the service identifier already stored locally is updated to the latest address information corresponding to the service identifier. To improve processing speed, the address information corresponding to the service identifier already stored locally by the service consumer is compared with the latest address information corresponding to the service identifier retrieved from the registry center. If they are consistent, then the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier already stored locally by the service consumer is retained; if they are inconsistent, then the address information corresponding to the service identifier already stored locally by the service consumer is updated to the latest address information corresponding to the service identifier obtained from the registry center, to ensure that the latest address information is stored in the service consumer's local memory.

[0083] Based on the various embodiments described above, it can be seen that the embodiments of the present invention solve the technical problem in the prior art where requests fail because the registration center cannot provide services during the process of upgrading and restarting nodes one by one. This is achieved by using a scheduled task to periodically query the latest address information from the registration center. If the address information is empty, the address information already stored locally is retained. This avoids the problem of request failure due to the registration center's inability to provide addressing services.

[0084] Figure 3 This is a flowchart of a method for accessing a service according to a possible embodiment of the present invention. As another embodiment of the present invention, such as... Figure 3 As shown, the method for accessing the service is applied to service consumers and may include:

[0085] Step 301: Send an address query request to the registration center, the address query request carrying a service identifier.

[0086] Step 302: Receive the latest address information corresponding to the service identifier returned by the registration center; wherein, the registration center is used to register each service and store the latest address information corresponding to each service identifier.

[0087] Step 303: Is the latest address information corresponding to the service identifier empty? If yes, proceed to step 304; if no, proceed to step 305.

[0088] Step 304: Ignore the latest address information corresponding to the service identifier, and retain the address information corresponding to the service identifier that has been stored locally.

[0089] Step 305: Update the address information corresponding to the service identifier that is already stored locally to the latest address information corresponding to the service identifier.

[0090] Step 306: Count the number of times the latest address information corresponding to the service identifier is continuously empty.

[0091] Step 307: Determine whether the number of times the latest address information corresponding to the service identifier is continuously empty is greater than or equal to the number threshold; if yes, proceed to step 308; otherwise, end.

[0092] Step 308: Delete the address information corresponding to the service identifier that has been stored locally.

[0093] If the latest address information received by the service consumer is empty, the number of times the latest address information is empty is recorded as 1. If the latest address information received by the service consumer is empty again, the number of times the latest address information is empty is recorded as 2, and so on, until the service consumer accumulates the number of times the latest address information corresponding to the same service identifier is continuously empty. If the number of times the latest address information corresponding to the service identifier is continuously empty is greater than or equal to the threshold (e.g., 3 times, 5 times, or 8 times), it means that the instance of the service provider has been taken offline, and the service consumer will delete the address information corresponding to the service identifier that has been stored locally.

[0094] Furthermore, the specific implementation details of the method for accessing services in one of the reference embodiments of the present invention have been described in detail in the above-described method for accessing services, so the details will not be repeated here.

[0095] Figure 4 This is a flowchart of a method for accessing a service according to another possible embodiment of the present invention. As another embodiment of the present invention, such as... Figure 4 As shown, the method for accessing the service is applied to service consumers and may include:

[0096] Step 401: Send an address query request to the registration center, the address query request carrying a service identifier.

[0097] Step 402: Receive the latest address information corresponding to the service identifier returned by the registration center; wherein, the registration center is used to register each service and store the latest address information corresponding to each service identifier.

[0098] Step 403: Is the latest address information corresponding to the service identifier empty? If yes, proceed to step 404; if no, proceed to step 405.

[0099] Step 404: Ignore the latest address information corresponding to the service identifier, and retain the address information corresponding to the service identifier that has been stored locally.

[0100] Step 405: Update the address information corresponding to the service identifier that is already stored locally to the latest address information corresponding to the service identifier.

[0101] Step 406: Accumulate the duration during which the latest address information corresponding to the service identifier remains empty.

[0102] Step 407: Determine if the duration of the latest address information corresponding to the service identifier being continuously empty is greater than or equal to the duration threshold; if yes, proceed to step 408; otherwise, end.

[0103] Step 408: Delete the address information corresponding to the service identifier that has been stored locally.

[0104] If the latest address information received by the service consumer is empty, it begins recording the duration of the empty address information. If the latest address information received by the service consumer is empty again, it accumulates the duration of the continuously empty address information corresponding to the service identifier, and so on, until the service consumer accumulates the duration of the continuously empty address information corresponding to the same service identifier. If the duration of the continuously empty address information corresponding to the service identifier is greater than or equal to a duration threshold (e.g., 3 seconds, 5 seconds, or 8 seconds), it indicates that the service provider's instance has gone offline, and the service consumer deletes the address information corresponding to that service identifier that has been stored locally.

[0105] In addition, the specific implementation of the method for accessing services in another reference embodiment of the present invention has been described in detail in the above-described method for accessing services, so it will not be repeated here.

[0106] Figure 5 This is a flowchart of a method for accessing a service according to another possible embodiment of the present invention. As another embodiment of the present invention, such as... Figure 5 As shown, the method for accessing the service is applied to service consumers and may include:

[0107] Step 501: Send a service query request to the registration center, the service query request carrying service keywords.

[0108] Service consumers send service query requests to the registry center, which carry one or more service keywords. Each service provider registers its services with the registry center, which assigns a service identifier to each service and stores the service identifier, service name, and corresponding address information.

[0109] Step 502: Receive the service name and service identifier corresponding to the service keyword returned by the registration center.

[0110] After receiving a service query request from a service consumer, the registry center matches the service keywords carried in the query request to identify the matching services and returns the service name and service identifier of the matched services to the service consumer. The service consumer then receives the service name and service identifier corresponding to the service keywords returned by the registry center.

[0111] Step 503: Configure one or more of the service identifiers corresponding to the service keyword as the service identifiers carried in the address query request.

[0112] Depending on business needs, one or more service identifiers returned by the registry can be configured as service identifiers carried in the address query request.

[0113] Next, the addressing task is executed periodically through a scheduled task, i.e., steps 504-508 are executed. The service identifier carried in the address query request is one or more configured service identifiers.

[0114] Step 504: Send an address query request to the registration center, the address query request carrying a service identifier.

[0115] Step 505: Receive the latest address information corresponding to the service identifier returned by the registration center; wherein, the registration center is used to register each service and store the latest address information corresponding to each service identifier.

[0116] Step 506: Is the latest address information corresponding to the service identifier empty? If yes, proceed to step 507; if no, proceed to step 508.

[0117] Step 507: Ignore the latest address information corresponding to the service identifier, and retain the address information corresponding to the service identifier that has been stored locally.

[0118] Step 508: Update the address information corresponding to the service identifier that is already stored locally to the latest address information corresponding to the service identifier.

[0119] Step 509: Determine the target service to be accessed and obtain the address information corresponding to the target service from the local machine.

[0120] Step 510: Assemble a service request based on the address information and service information corresponding to the target service, thereby accessing the target service.

[0121] When a service consumer needs to access a target service, it obtains the address information corresponding to the target service from the local machine, then assembles a business request based on the address information and business information, and sends the business request to the target service to access the target service.

[0122] Furthermore, the specific implementation details of the method for accessing services in another reference embodiment of the present invention have been described in detail in the above-described method for accessing services, so the details will not be repeated here.

[0123] Figure 6 This is a schematic diagram of an apparatus for accessing services according to an embodiment of the present invention. Figure 5As shown, the device 600 for accessing the service is located in the service consumer and includes a query module 601, a receiving module 602, and a storage module 603. The query module 601 sends an address query request to the registration center, the address query request carrying a service identifier. The receiving module 602 receives the latest address information corresponding to the service identifier returned by the registration center. The registration center registers various services and stores the latest address information corresponding to each service identifier. The storage module 603, in response to the latest address information corresponding to the service identifier being empty, ignores the latest address information corresponding to the service identifier and retains the address information corresponding to the service identifier already stored locally. In response to the latest address information corresponding to the service identifier not being empty, it updates the address information corresponding to the service identifier already stored locally to the latest address information corresponding to the service identifier.

[0124] Optionally, the storage module 603 is further configured to:

[0125] In response to the fact that the latest address information corresponding to the service identifier is not empty, compare whether the address information corresponding to the service identifier already stored locally is consistent with the latest address information corresponding to the service identifier;

[0126] If so, ignore the latest address information corresponding to the service identifier and retain the address information corresponding to the service identifier that has been stored locally;

[0127] If not, the address information corresponding to the service identifier already stored locally will be updated to the latest address information corresponding to the service identifier.

[0128] Optionally, the storage module 603 is further configured to:

[0129] In response to the latest address information corresponding to the service identifier being empty, the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier already stored locally is retained. The number of times the latest address information corresponding to the service identifier is continuously empty is accumulated. In response to the number of times the latest address information corresponding to the service identifier is continuously empty being greater than or equal to the number of times the number of times the latest address information corresponding to the service identifier is continuously empty being greater than or equal to the number of times the number of times the address information corresponding to the service identifier is continuously empty being deleted from the local storage.

[0130] Optionally, the storage module 603 is further configured to:

[0131] In response to the latest address information corresponding to the service identifier being empty, the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier already stored locally is retained. The duration for which the latest address information corresponding to the service identifier is continuously empty is accumulated. In response to the duration for which the latest address information corresponding to the service identifier is continuously empty being greater than or equal to the duration threshold, the address information corresponding to the service identifier already stored locally is deleted.

[0132] Optionally, the query module 601 is further configured to:

[0133] Send a service query request to the registration center, the service query request carrying service keywords;

[0134] Receive the service name and service identifier corresponding to the service keyword returned by the registration center;

[0135] Configure one or more of the service identifiers corresponding to the service keywords as the service identifiers carried in the address query request.

[0136] Optionally, an access module is also included for:

[0137] Determine the target service that needs to be accessed, and obtain the address information corresponding to the target service from the local machine;

[0138] A service request is assembled based on the address information and service information corresponding to the target service, thereby accessing the target service.

[0139] Optionally, the registration center is a Nacos cluster or a ZooKeeper cluster.

[0140] It should be noted that the specific implementation of the device for accessing the service described in this invention has been described in detail in the method for accessing the service described above, so the content will not be repeated here.

[0141] Figure 7 An exemplary system architecture 700 is shown, which can be applied to a method or apparatus for accessing services according to embodiments of the present invention.

[0142] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, and 703, a network 704, and a server 705. Network 704 serves as the medium for providing communication links between terminal devices 701, 702, and 703 and server 705. Network 704 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0143] Users can use terminal devices 701, 702, and 703 to interact with server 705 via network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).

[0144] Terminal devices 701, 702, and 703 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0145] Server 705 can be a server that provides various services, such as a backend management server that supports shopping websites browsed by users using terminal devices 701, 702, and 703 (this is just an example). The backend management server can analyze and process data such as received item information query requests, and then feed the processing results back to the terminal devices.

[0146] It should be noted that the access service method provided in the embodiments of the present invention is generally executed by terminal devices 701, 702, and 703, and correspondingly, the access service device is generally installed in terminal devices 701, 702, and 703.

[0147] It should be understood that Figure 7 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0148] The following is for reference. Figure 8 It shows a schematic diagram of the structure of a computer system 800 suitable for implementing a terminal device of the present invention. Figure 8 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0149] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the system 800. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0150] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.

[0151] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined above in the system of this invention.

[0152] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0153] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer programs according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0154] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor can be described as including a query module, a receiving module, and a storage module, wherein the names of these modules do not necessarily limit the module itself.

[0155] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the device, the device implements the following method: sending an address query request to a registry center, the address query request carrying a service identifier; receiving the latest address information corresponding to the service identifier returned by the registry center; wherein the registry center is used to register various services and stores the latest address information corresponding to each service identifier; in response to the latest address information corresponding to the service identifier being empty, ignoring the latest address information corresponding to the service identifier and retaining the address information corresponding to the service identifier already stored locally; in response to the latest address information corresponding to the service identifier not being empty, updating the address information corresponding to the service identifier already stored locally to the latest address information corresponding to the service identifier.

[0156] In another aspect, embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements the methods described in any of the above embodiments.

[0157] According to the technical solution of this invention, by employing the technical means of ignoring the latest address information corresponding to the service identifier when it is empty and retaining the address information already stored locally, and updating the address information already stored locally to the latest address information corresponding to the service identifier when it is not empty, this invention overcomes the technical problem in the prior art where requests fail because the registration center cannot provide services during the process of upgrading and restarting nodes one by one. This invention uses a scheduled task to periodically query the latest address information from the registration center. If the address information is empty, the address information already stored locally is retained, thereby avoiding the problem of request failure due to the registration center's inability to provide addressing services.

[0158] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A method for accessing a service, characterized in that, Applied to serving consumers, including: Send an address query request to the registration center, the address query request carrying a service identifier; The system receives the latest address information corresponding to the service identifier returned by the registration center; wherein the registration center is used to register each service and stores the latest address information corresponding to each service identifier. In response to the latest address information corresponding to the service identifier being empty, the latest address information corresponding to the service identifier is ignored, and the address information corresponding to the service identifier already stored locally is retained; the number of times the latest address information corresponding to the service identifier is continuously empty is accumulated, and in response to the number of times the latest address information corresponding to the service identifier is continuously empty being greater than or equal to a count threshold, the address information corresponding to the service identifier already stored locally is deleted; or, the duration of the latest address information corresponding to the service identifier being continuously empty is accumulated, and in response to the duration of the latest address information corresponding to the service identifier being continuously empty being greater than or equal to a duration threshold, the address information corresponding to the service identifier already stored locally is deleted. In response to the fact that the latest address information corresponding to the service identifier is not empty, the address information corresponding to the service identifier that is already stored locally is updated to the latest address information corresponding to the service identifier; When the service consumer needs to access the service, the address information of the service is obtained directly from the local machine.

2. The method according to claim 1, characterized in that, In response to the latest address information corresponding to the service identifier being non-empty, the address information corresponding to the service identifier already stored locally is updated to the latest address information corresponding to the service identifier, including: In response to the fact that the latest address information corresponding to the service identifier is not empty, compare whether the address information corresponding to the service identifier already stored locally is consistent with the latest address information corresponding to the service identifier; If so, ignore the latest address information corresponding to the service identifier and retain the address information corresponding to the service identifier that has been stored locally; If not, the address information corresponding to the service identifier already stored locally will be updated to the latest address information corresponding to the service identifier.

3. The method according to claim 1, characterized in that, Before sending an address lookup request to the registry center, the process also includes: Send a service query request to the registration center, the service query request carrying service keywords; Receive the service name and service identifier corresponding to the service keyword returned by the registration center; Configure one or more of the service identifiers corresponding to the service keywords as the service identifiers carried in the address query request.

4. The method according to claim 1, characterized in that, Also includes: Determine the target service that needs to be accessed, and obtain the address information corresponding to the target service from the local machine; A service request is assembled based on the address information and service information corresponding to the target service, thereby accessing the target service.

5. The method according to claim 1, characterized in that, The registration center is either a Nacos cluster or a ZooKeeper cluster.

6. An apparatus for accessing services, characterized in that, Set up to serve consumers, including: The query module is used to send an address query request to the registration center, and the address query request carries a service identifier; A receiving module is used to receive the latest address information corresponding to the service identifier returned by the registration center; wherein, the registration center is used to register each service and store the latest address information corresponding to each service identifier; The storage module is configured to: ignore the latest address information corresponding to the service identifier and retain the address information already stored locally if the latest address information corresponding to the service identifier is empty; accumulate the number of times the latest address information corresponding to the service identifier is continuously empty, and delete the address information already stored locally if the number of times the latest address information corresponding to the service identifier is continuously empty is greater than or equal to a threshold; or accumulate the duration of the latest address information corresponding to the service identifier being continuously empty, and delete the address information already stored locally if the duration of the latest address information corresponding to the service identifier is continuously empty is greater than or equal to a duration threshold; and update the address information already stored locally to the latest address information corresponding to the service identifier if the latest address information corresponding to the service identifier is not empty. When the service consumer needs to access the service, the address information of the service is obtained directly from the local machine.

7. The apparatus according to claim 6, characterized in that, The storage module is also used for: In response to the fact that the latest address information corresponding to the service identifier is not empty, compare whether the address information corresponding to the service identifier already stored locally is consistent with the latest address information corresponding to the service identifier; If so, ignore the latest address information corresponding to the service identifier and retain the address information corresponding to the service identifier that has been stored locally; If not, the address information corresponding to the service identifier already stored locally will be updated to the latest address information corresponding to the service identifier.

8. The apparatus according to claim 6, characterized in that, The query module is also used for: Send a service query request to the registration center, the service query request carrying service keywords; Receive the service name and service identifier corresponding to the service keyword returned by the registration center; Configure one or more of the service identifiers corresponding to the service keywords as the service identifiers carried in the address query request.

9. The apparatus according to claim 6, characterized in that, It also includes an access module for: Determine the target service that needs to be accessed, and obtain the address information corresponding to the target service from the local machine; A service request is assembled based on the address information and service information corresponding to the target service, thereby accessing the target service.

10. The apparatus according to claim 6, characterized in that, The registration center is either a Nacos cluster or a ZooKeeper cluster.

11. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-5.

12. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.

13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Method and device for accessing invalid website

    CN104915404A