A service discovery method, device, electronic device and storage medium
By allowing service callers to subscribe to services without data synchronization between local registry centers and other registry centers, the complex problem of data synchronization between registry centers in the prior art is solved, and more flexible service subscriptions and simpler services are achieved synchronization policy.
Patent Information
- Application Number
- CN202210267545.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-17
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2042-03-17
AI Technical Summary
In the existing service discovery method, data synchronization is required between registration centers, the implementation strategy is complex, and service subscription is not flexible enough. In particular, data resynchronization and data verification mechanisms are required in the event of network failure.
The service caller can subscribe to the service to the local registry center and the registry center other than the local registry center, and receive information from the service provider through the service subscription SDK to realize service discovery without the need for data synchronization between the registry centers.
Simplifies data synchronization strategies between registry centers, improves flexibility in service subscriptions, and avoids data resynchronization and verification complexity in the event of network failure.
Smart Images

Figure CN114598743B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer application technology, and further to cloud computing technology, and in particular to a service discovery method, device, electronic device, and storage medium. Background Art
[0002] Microservices is an architecture and organizational method for developing software. It divides and builds applications into independent service components. Each service component performs one or a group of functions, and the service components communicate using clearly defined interfaces. Since each service component runs independently, it can be updated, deployed, and expanded separately without affecting other service components. The advantage of using a microservice architecture is that each functional module can be independently developed by its own team, and the team can choose the appropriate technical tools to achieve agility, flexibility, and autonomous deployment.
[0003] As a key module in the microservice architecture, the registry provides functions such as addressing and configuration between modules and is the foundation of the microservice system. The service discovery function is generally implemented based on the registry. The registry has a single data center cluster or a multi-data center cluster. In the microservice system, service callers rely on the service discovery system to discover service providers. The service discovery system generally includes modules such as the registry, service publishing SDK (Software Development Kit), and service subscription SDK.
[0004] In the existing service discovery method, data synchronization is required between registration centers, the implementation strategy is relatively complex, and service subscription is not flexible enough. Summary of the invention
[0005] The present disclosure provides a service discovery method, device, electronic device and storage medium.
[0006] In a first aspect, the present application provides a service discovery method, the method comprising:
[0007] When a service caller relies on a service of a target service type, the target service type is subscribed to a local registration center and a registration center other than the local registration center;
[0008] The service subscription SDK receives information about the service provider corresponding to the target service type sent to the service caller by the local registration center and registration centers other than the local registration center, so that the service caller can find the service provider corresponding to the target service type.
[0009] In a second aspect, the present application provides a service discovery device, the device comprising: a subscription module and a receiving module; wherein:
[0010] The subscription module is used to subscribe the target service type to the local registration center and the registration center other than the local registration center when the service caller relies on the service of the target service type;
[0011] The receiving module is used to receive information about the service provider corresponding to the target service type sent to the service caller by the local registration center and a registration center other than the local registration center through the service subscription SDK, so that the service caller can discover the service provider corresponding to the target service type.
[0012] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0013] one or more processors;
[0014] a memory for storing one or more programs,
[0015] When the one or more programs are executed by the one or more processors, the one or more processors implement the service discovery method described in any embodiment of the present application.
[0016] In a fourth aspect, an embodiment of the present application provides a storage medium on which a computer program is stored, and when the program is executed by a processor, the service discovery method described in any embodiment of the present application is implemented.
[0017] In a fifth aspect, a computer program product is provided, which, when executed by a computer device, implements the service discovery method described in any embodiment of the present application.
[0018] The technology of the present application solves the problem that in the prior art each registration center needs to synchronize service information with other registration centers, and at the same time needs to implement its own synchronization strategy to solve the data resynchronization and data verification mechanism when the synchronization data is interrupted due to network failures, etc., and the technical problem that the implementation strategy is relatively complex. The technical solution provided by the present application allows service callers to subscribe to services in registration centers other than the local registration center. Data synchronization is not required between registration centers, the implementation strategy is relatively simple, and service subscription is more flexible.
[0019] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0021] Figure 1This is a first flow chart of the service discovery method provided in an embodiment of the present application;
[0022] Figure 2 It is a first structural diagram of the service discovery system provided in an embodiment of the present application;
[0023] Figure 3 is a second structural diagram of the service discovery system provided in an embodiment of the present application;
[0024] Figure 4 This is a second flow chart of the service discovery method provided in an embodiment of the present application;
[0025] Figure 5 It is a third flow diagram of the service discovery method provided in an embodiment of the present application;
[0026] Figure 6 It is a structural diagram of a service discovery device provided in an embodiment of the present application;
[0027] Figure 7 It is a block diagram of an electronic device used to implement the service discovery method of an embodiment of the present application. DETAILED DESCRIPTION
[0028] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0029] Embodiment 1
[0030] Figure 1 1 is a first flow chart of the service discovery method provided by the embodiment of the present application. The method can be executed by a service discovery device or electronic device. The device or electronic device can be implemented by software and / or hardware. The device or electronic device can be integrated in any smart device with network communication function. Figure 1 As shown, the service discovery method may include the following steps:
[0031] S101. When a service caller relies on a service of a target service type, the target service type is subscribed to a local registration center and a registration center other than the local registration center.
[0032] In this step, when the service caller relies on the service of the target service type, the service caller can subscribe to the target service type to the local registration center and the registration center other than the local registration center. Normally, the service caller can initiate a subscription to the local registration center and the registration center of other data centers at the same time when starting; in addition, the service caller can also initiate a subscription to the local registration center and the registration center of other data centers at the same time after starting. The target service type in the embodiment of the present application can be one service type or multiple service types, which is not limited here. The service type in the embodiment of the present application can refer to the name of the service that the service provider can provide, such as online service, long connection service, etc. In addition, the "simultaneous subscription" here can refer to initiating a subscription to the local registration center and the registration center of other data centers at a certain moment; it can also be initiated to the local registration center first, and then to the registration center of other data centers within a small time interval.
[0033] Specifically, the service caller can directly subscribe to the target service type from a registry other than the local registry; or, the service caller can subscribe to the target service type from a registry other than the local registry through a proxy. For example, assuming that the service caller depends on service type A, the service caller can subscribe to service type A from both the local registry and the registry other than the local registry. Assuming that the service caller depends on both service type A and service type B, the service caller can subscribe to both service type A and service type B from both the local registry and the registry other than the local registry.
[0034] S102. Receive information about the service provider corresponding to the target service type sent by the local registration center and the registration center other than the local registration center to the service caller through the service subscription SDK, so that the service caller can find the service provider corresponding to the target service type.
[0035] In this step, the service caller can receive the information of the service provider corresponding to the target service type sent to the service caller by the local registration center and the registration center other than the local registration center through the service subscription SDK, so that the service caller can discover the service provider corresponding to the target service type. For example, assuming that the service discovery system may include: registration center 1 and registration center 2; assuming that the service caller depends on service type A, service type B, service type C and service type D, the service caller can subscribe to service type A, service type B, service type C and service type D from registration center 1; at the same time, the service caller can also subscribe to service type A, service type B, service type C and service type D from registration center 2. Assuming that registration center 1 has the information of the service provider corresponding to service type A, and registration center 1 also has the information of the service provider corresponding to service type B, then registration center 1 will send the information of the service provider corresponding to service type A and the information of the service provider corresponding to service type B to the service caller. Assuming that registration center 2 has the information of the service provider corresponding to service type C, and registration center 2 also has the information of the service provider corresponding to service type D, then registration center 2 will send the information of the service provider corresponding to service type C and the information of the service provider corresponding to service type D to the service caller.
[0036] It should be noted that the service caller and the registration center are connected. If the registration center finds that there are changes in the service provider of the type of service that the service caller is interested in, it will push it. For example, if a service of type A adds a service node (that is, a new service provider), then the change will be pushed to the service caller who subscribes to the service of type A (through the long connection between the subscription SDK and the registration center).
[0037] Figure 2 Schematic diagram of the first structure of the service discovery system provided by the embodiment of the present application. Figure 2 As shown, the service discovery system may include: a registration center, a service publishing SDK (referred to as publishing SDK) and a service subscription SDK (referred to as subscription SDK). Figure 2The service discovery system in may include two data centers, namely: data center 1 and data center 2; wherein data center 1 may include: registration center 1, service type A provider A1, service type A caller CA1, service type B caller CB1; data center 2 may include: registration center 2, service type A provider A2, service type B provider B1 and service type A caller CA2; service type A provider A1 publishes services to registration center 1; service type A provider A2 and service type B provider B1 publish services to registration center 2; service type A caller CA1 subscribes to type A services on registration center 1 of local data center 1, and directly subscribes to type A services from registration centers (registration center 2) of other data centers (data center 2). Service caller CB1 subscribes to type B services on registration center 1 of local data center 1, and directly subscribes to type B services from registration centers (registration center 2) of other data centers (data center 2). Service caller CA2 subscribes to type A services on registration center 2 of local data center 2, and directly subscribes to type A services from registration centers (registration center 1) of other data centers (data center 1). Service caller CA1 selects service type A provider A1 or A2 to call type A service based on the general service selection algorithm or the nearest service selection algorithm described below. Similarly, service caller CA2 can also call type A service provided by A1 or A2 based on the selection algorithm. Service caller CB1 selects type B service provider based on the same algorithm. Since there is only one service provider B1, it can only call type B service from B1.
[0038] More specifically, Figure 2The workflow of the service discovery system shown may include the following steps: ① The service caller CA1 subscribes to the type A service on the registration center 1 of the local data center 1, and directly subscribes to the type A service from the registration center (registration center 2) of other data centers (data center 2); ② The service caller CA2 subscribes to the type A service on the registration center 2 of the local data center 2, and directly subscribes to the type A service from the registration center (registration center 1) of other data centers (data center 1); ③ The service type A provider A1 publishes the service to the registration center 1; ④ The service type A provider A2 publishes the service to the registration center 2; ⑤ The service caller CA1 selects the service type A provider A1 or A2 to call the type A service; ⑥ The service caller CA2 selects the service type A provider A1 or A2 to call the type A service; ⑦ The service caller CB1 subscribes to the type B service on the registration center 1 of the local data center 1, and directly subscribes to the type B service from the registration center (registration center 2) of other data centers (data center 2); ⑧ The service type B provider B1 publishes the service to the registration center 2; ⑨ The service caller CB 1 selects the service type B provider B1 to call the type B service.
[0039] Figure 3 is a second structural diagram of the service discovery system provided in the embodiment of the present application. Figure 3As shown, the service discovery system may include two data centers: data center 1 and data center 2; data center 1 may include: registration center 1, subscription service proxy proxy1, service type A provider A1, service type A caller CA1, service type B caller CB1; data center 2 may include: registration center 2, subscription service proxy proxy2, service type A provider A2, service type B provider B1, service type A caller CA2; service type A provider A1 publishes services to registration center 1; service type A provider A2 and service type B provider B1 publish services to registration center 2; service type A caller CA1 subscribes to type A services on registration center 1 of local data center 1, and subscribes to type A services from registration centers (registration center 2) of other data centers (data center 2) through subscription service proxy proxy1. Service caller CB1 subscribes to type B services on registration center 1 of local data center 1, and subscribes to type B services from registration centers (registration center 2) of other data centers (data center 2) through subscription service proxy proxy1. Service caller CB1 subscribes to type B services on registration center 1 of local data center 1, and subscribes to type B services from registration centers (registration center 2) of other data centers (data center 2) through subscription service proxy proxy1. The service caller CA2 subscribes to the type A service on the registration center 2 of the local data center 2, and at the same time subscribes to the type A service from the registration center (registration center 1) of the other data center (data center 1) through the subscription service proxy proxy2. The service caller CA1 selects the service type A provider A1 or A2 to call the type A service based on the general service selection algorithm or the nearest service selection algorithm described below. Similarly, the service caller CA2 can also call the type A service provided by A1 or A2 based on the selection algorithm. The service caller CB1 selects the type B service provider based on the same algorithm. Since there is only one service provider B1, it can only call the service of type B to B1.
[0040] More specifically, Figure 3The workflow of the service discovery system shown may include the following steps: ① The service caller CA1 subscribes to the service of type A on the registration center 1 of the local data center 1, and subscribes to the service of type A through the proxy to the registration center (registration center 2) of other data centers (data center 2); ② The service caller CA2 subscribes to the service of type A on the registration center 2 of the local data center 2, and subscribes to the service of type A through the proxy2 to the registration center (registration center 1) of other data centers (data center 1); ③ The service type A provider A1 publishes the service to the registration center 1; ④ The service type A provider A2 publishes the service to the registration center 2; ⑤ The service caller CA1 selects the service type A provider A1 or A2 to invoke the service of type A; ⑥ The service caller CA2 selects the service type A provider A1 or A2 to invoke the service of type A; ⑦ The service caller CB1 subscribes to the service of type B on the registration center 1 of the local data center 1, and subscribes to the service of type B through the proxy1 to the registration center (registration center 2) of other data centers (data center 2); ⑧ The service type B provider B1 publishes the service to the registration center 2; ⑨ The service caller CB 1 Select service type B provider B1 to call the service of type B.
[0041] In a specific embodiment of the present application, the service caller can also call the service of the target service type based on the information of the service provider corresponding to the target service type. When the service caller needs to call the service of a service type, the target service to be called this time can be first determined from the service providers of the service type based on a predetermined service selection algorithm; wherein the service selection algorithm may include: a general service selection algorithm and a nearby service selection algorithm; and then, based on the information of the service provider corresponding to the target service, a service call is initiated to the target service. When the service caller relies on multiple service types, the above operation can be repeated for each service type.
[0042] Further, the general service selection algorithm in the embodiment of the present application includes: a random algorithm, a polling algorithm without weights, a polling algorithm with weights, and a consistent hashing algorithm; the nearest service selection algorithm may include: a same environment priority selection algorithm, a same environment and data center priority selection algorithm, and a same environment and data center and same availability zone priority selection algorithm. Specifically, 1) the same environment priority selection algorithm: for example, if the service caller is in a pre-release environment, the service provider in the same pre-release environment is given priority; this option can also be very convenient for AB testing and other strategies. 2) The same environment and data center priority selection algorithm: add the same data center priority selection on the basis of the previous algorithm. 3) The same environment and data center and availability zone priority selection algorithm: add the same data center and availability zone priority selection on the basis of the previous algorithm. In the above service selection algorithm, the granularity from top to bottom is getting smaller and smaller. Generally, after a granularity is selected for the same service, if there is no available service at the same granularity, a service of a larger granularity will be considered. For example, if the same environment and data center priority selection strategy is adopted, if there is no available service provider in this data center, and there is a required service provider in other data centers, the service of other data centers will be selected for service call.
[0043] In the existing service discovery method, after the service provider is started, it will publish the service to the registration center, generally declaring the interface, call address, call protocol and other information provided by the service; when the service caller is started, it will subscribe to the service it depends on, such as the interface and protocol information it depends on. After the service provider publishes to the registration center, it generally maintains heartbeat information with the registration center to keep alive. Depending on business needs, the registration center can be deployed in a single data center cluster or a multi-data center cluster. For the multi-data center cluster method, there are two ways to implement it: (1) The registration center cluster directly spans multiple data centers, and the services of each data center are directly published to the entire cluster, and the subscription service information is also subscribed to the entire cluster. (2) Each data center has its own registration center cluster, and the services in this data center are only registered with the local registration center. The registration centers of each data center are synchronized with each other, and subscriptions are directly subscribed to the registration center of this data center. In the above implementation (1), the open source or self-developed implementation of the data center generally adopts a strong consistency model. When the registration center cluster is deployed across multiple data centers (for example, the three data centers in South China, North China, and East China), the delay when publishing services may be unstable due to the relatively unstable network between multiple data centers. In extreme cases, when the network between data centers is disconnected due to a fault, the cluster may fail and the subscription service cannot be published. In the above implementation (2), each registration center synchronizes service information with other registration centers through a dedicated line, and at the same time needs to implement its own synchronization strategy to solve the data resynchronization and data verification mechanism when the synchronization data is interrupted due to network failures, etc., and the implementation strategy is relatively complex.
[0044] The service discovery method proposed in the embodiment of the present application, when the service caller relies on the service of the target service type, subscribes to the target service type to the local registration center and the registration center other than the local registration center; then receives the information of the service provider corresponding to the target service type sent to the service caller by the local registration center and the registration center other than the local registration center through the service subscription SDK, so that the service caller can discover the service provider corresponding to the target service type. In other words, the service caller in the present application can subscribe to services to the local registration center and the registration center other than the local registration center at the same time, so that the local registration center does not need to synchronize data with other registration centers. In the existing service discovery method, each registration center needs to synchronize data with other registration centers, that is, each registration center saves all service information, and if the synchronization data is interrupted, the data needs to be resynchronized. Because the present application adopts the technical means that the service caller subscribes to the service in the registration center other than the local registration center, it overcomes the problem in the prior art that each registration center needs to synchronize service information with other registration centers, and at the same time needs to implement synchronization strategies by itself, solve the data resynchronization and data verification mechanism when the synchronization data is interrupted due to network failures, and the technical problem of complex implementation strategies. The technical solution provided by the present application allows the service caller to subscribe to the service in the registration center other than the local registration center, and there is no need for data synchronization between the registration centers. The implementation strategy is relatively simple and the service subscription is more flexible. In addition, the technical solution of the embodiment of the present application is simple and convenient to implement, easy to popularize, and has a wider range of applications.
[0045] Embodiment 2
[0046] Figure 4 1 is a second flow chart of the service discovery method provided in the embodiment of the present application. Based on the above technical solution, it is further optimized and expanded, and can be combined with the above optional implementation methods. Figure 4 As shown, the service discovery method may include the following steps:
[0047] S401. When a service caller relies on a service of a target service type, the target service type is subscribed to a local registration center and a registration center other than the local registration center.
[0048] S402. Receive information about the service provider corresponding to the target service type sent by the local registration center and the registration center other than the local registration center to the service caller through the service subscription SDK, so that the service caller can find the service provider corresponding to the target service type.
[0049] In the specific embodiment of the present application, the service publishing SDK and the service subscription SDK are integrated by the service publisher and service caller respectively. A business node can be both a service provider and a caller of other services, so it can have both roles. In addition, the registration center can be implemented based on etcd, or it can be implemented based on nacos, zookeeper, consul, etc. Each data center has its own registration center etcd cluster, which is only in a single data center, with small network latency and jitter, and the possibility of cluster failure is small. The service provider of this data center publishes the service to the local registration center through the service publishing SDK; the service caller subscribes to the services of this data center through the service subscription SDK, and also subscribes to the services of other data centers. Here, you can subscribe directly to other data centers, or you can subscribe to other data centers through a proxy. Through this subscription method, cross-regional data synchronization can be avoided, and the information of the data center of the entire system can be automatically obtained by the SDK from the global configuration.
[0050] S403: Based on the information of the service provider corresponding to the target service type, call the service of the target service type.
[0051] The service discovery method proposed in the embodiment of the present application, when the service caller relies on the service of the target service type, subscribes to the target service type to the local registration center and the registration center other than the local registration center; then receives the information of the service provider corresponding to the target service type sent to the service caller by the local registration center and the registration center other than the local registration center through the service subscription SDK, so that the service caller can discover the service provider corresponding to the target service type. In other words, the service caller in the present application can subscribe to services to the local registration center and the registration center other than the local registration center at the same time, so that the local registration center does not need to synchronize data with other registration centers. In the existing service discovery method, each registration center needs to synchronize data with other registration centers, that is, each registration center saves all service information, and if the synchronization data is interrupted, the data needs to be resynchronized. Because the present application adopts the technical means that the service caller subscribes to the service in the registration center other than the local registration center, it overcomes the problem in the prior art that each registration center needs to synchronize service information with other registration centers, and at the same time needs to implement synchronization strategies by itself, solve the data resynchronization and data verification mechanism when the synchronization data is interrupted due to network failures, and the technical problem of complex implementation strategies. The technical solution provided by the present application allows the service caller to subscribe to the service in the registration center other than the local registration center, and there is no need for data synchronization between the registration centers. The implementation strategy is relatively simple and the service subscription is more flexible. In addition, the technical solution of the embodiment of the present application is simple and convenient to implement, easy to popularize, and has a wider range of applications.
[0052] Embodiment 3
[0053] Figure 5 3 is a schematic diagram of the third process of the service discovery method provided in the embodiment of the present application. Based on the above technical solution, it is further optimized and expanded, and can be combined with the above optional implementation methods. Figure 5 As shown, the service discovery method may include the following steps:
[0054] S501. When a service caller relies on a service of a target service type, the target service type is subscribed to a local registration center and a registration center other than the local registration center.
[0055] S502. Receive information about the service provider corresponding to the target service type sent by the local registration center and the registration center other than the local registration center to the service caller through the service subscription SDK, so that the service caller can find the service provider corresponding to the target service type.
[0056] S503: When a service caller needs to call a service of a service type, a target service to be called this time is determined from service providers of the service type based on a predetermined service selection algorithm; wherein the service selection algorithm includes: a general service selection algorithm and a nearby service selection algorithm.
[0057] S504: Initiate a service call to the target service based on the information of the service provider corresponding to the target service.
[0058] In a specific embodiment of the present application, a service provider can use a structured data format to publish services to a registration center through a service publishing SDK, and the registration center will store the service information in a cluster; the structured data format includes: service type name, environment group where the service is located, data center where the service is located, availability zone of the data center where the service is located, service interface protocol and address information, and additional service information. Specifically, 1) Service type name: for example, application management service; 2) Service environment group: for example, test environment, pre-release environment, production environment, etc.; 3) Service data center: for example, South China data center, North China data center; 4) More detailed information such as the availability zone of the data center where the service is located; 5) Service interface protocol and address information, including: supported interfaces, protocol types, internal addresses of the data center, and global addresses that can be accessed from other data centers, etc.; 6) Additional information of the service is parsed by the specific application.
[0059] In a specific embodiment of the present application, if the service caller receives a service offline notification sent by the registration center through the service subscription SDK, the service notified offline is marked as temporarily unavailable, and the service notified offline is added to the list to be detected; then the survival status of the service notified offline is detected; wherein, the survival status includes: service survival and service non-survival; if the survival status of the service notified offline is service survival, the service mark notified offline is changed from temporarily unavailable to normal status in the list to be detected; if the survival status of the service notified offline is service non-survival, the service notified offline is deleted from the list to be detected. Specifically, the service provider will maintain a periodic heartbeat with the local registration center etcd cluster to indicate that it is in a survival state, and will actively deregister itself from the registration center etcd cluster before the service goes offline. After the registration center cluster detects that the service is offline, it will notify the service caller (including callers of this data center and other data centers). After the service caller confirms that the service provider is offline, this service is removed from the selector, and subsequent service calls will no longer call this service. If network jitter occurs between the service provider and the etcd cluster of the registration center, it may cause a heartbeat timeout, triggering a notification of service offline. The network between the service caller and the service provider may be normal, so there will be a situation where the service selector is mistakenly removed; at the same time, after the service provider reconnects to the registration center cluster, it will re-register, and then notify the service caller to add it back to the service selector. Under extreme conditions, this frequent removal and addition may cause a ping-pong effect. In response to this situation, this application has made some optimizations in the service subscription SDK to avoid this situation: after the service caller receives the offline notification from the registration center, the service provider is placed in the list to be detected, and the service provider is marked as being removed in the service selector. The priority of selecting this service is reduced, and this service is selected only when there are no other available services. After waiting for a period of time, it starts to detect whether the service is available. The waiting period here is to avoid the service not being completely exited after deregistering from the registration center when it is offline, resulting in subsequent successful detection and causing the service to be unable to go offline. After the detection, if the service is available, the service provider is re-marked as normal. The subsequent service online notification after the network between the service provider and the etcd cluster of the registration center is restored is ignored. If the detection fails, the service provider is eventually removed from the service selector.
[0060] The service discovery method proposed in the embodiment of the present application, when the service caller relies on the service of the target service type, subscribes to the target service type to the local registration center and the registration center other than the local registration center; then receives the information of the service provider corresponding to the target service type sent to the service caller by the local registration center and the registration center other than the local registration center through the service subscription SDK, so that the service caller can discover the service provider corresponding to the target service type. In other words, the service caller in the present application can subscribe to services to the local registration center and the registration center other than the local registration center at the same time, so that the local registration center does not need to synchronize data with other registration centers. In the existing service discovery method, each registration center needs to synchronize data with other registration centers, that is, each registration center saves all service information, and if the synchronization data is interrupted, the data needs to be resynchronized. Because the present application adopts the technical means that the service caller subscribes to the service in the registration center other than the local registration center, it overcomes the problem in the prior art that each registration center needs to synchronize service information with other registration centers, and at the same time needs to implement synchronization strategies by itself, solve the data resynchronization and data verification mechanism when the synchronization data is interrupted due to network failures, and the technical problem of complex implementation strategies. The technical solution provided by the present application allows the service caller to subscribe to the service in the registration center other than the local registration center, and there is no need for data synchronization between the registration centers. The implementation strategy is relatively simple and the service subscription is more flexible. In addition, the technical solution of the embodiment of the present application is simple and convenient to implement, easy to popularize, and has a wider range of applications.
[0061] Embodiment 4
[0062] Figure 6 Schematic diagram of the structure of the service discovery device provided in the embodiment of the present application. Figure 6 As shown, the device 600 includes: a subscription module 601 and a receiving module 602; wherein,
[0063] The subscription module 601 is used to subscribe the target service type to the local registration center and the registration center other than the local registration center when the service caller relies on the service of the target service type;
[0064] The receiving module 602 is used to receive information about the service provider corresponding to the target service type sent to the service caller by the local registration center and registration centers other than the local registration center through the service subscription SDK, so that the service caller can find the service provider corresponding to the target service type.
[0065] Furthermore, the subscription module 601 is specifically configured to directly subscribe the target service type to a registration center other than the local registration center; or to subscribe the target service type to a registration center other than the local registration center through a proxy.
[0066] Furthermore, the device also includes: a calling module 603 (not shown in the figure), which is used to determine the target service to be called this time among the service providers of the service type based on a predetermined service selection algorithm when the service caller needs to call a service of a service type; wherein the service selection algorithm includes: a general service selection algorithm and a nearby service selection algorithm; based on the information of the service provider corresponding to the target service, initiate a service call to the target service.
[0067] Furthermore, the general service selection algorithm includes: a random algorithm, an unweighted polling algorithm, a weighted polling algorithm, and a consistent hashing algorithm; the nearby service selection algorithm includes: a same-environment priority selection algorithm, a same-environment-and-data-center priority selection algorithm, and a same-environment-and-data-center-and-availability-zone priority selection algorithm.
[0068] Furthermore, the device also includes: a detection module 604 (not shown in the figure), which is used to mark the service that is notified to be offline as temporarily unavailable if the service caller receives the service offline notification sent by the registration center through the service subscription SDK, and add the service that is notified to be offline to a list to be detected; detect the survival status of the service that is notified to be offline; wherein the survival status includes: service survival and service non-survival; if the survival status of the service that is notified to be offline is service survival, then change the mark of the service that is notified to be offline from temporarily unavailable to normal status in the list to be detected.
[0069] Furthermore, the device also includes: a publishing module 605 (not shown in the figure), which is used for the service provider to use a structured data format to publish services to the registration center of this data center through the service publishing SDK, and the registration center stores the information of the service into the cluster; the structured data format includes: service type name, service environment group, service data center, availability zone of the service data center, service interface protocol and address information, and additional information of the service.
[0070] The above service discovery device can execute the method provided by any embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the service discovery method provided by any embodiment of the present application.
[0071] Embodiment 5
[0072] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0073] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0074] like Figure 7 As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0075] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0076] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as a service discovery method. For example, in some embodiments, the service discovery method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the computing unit 701, one or more steps of the service discovery method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform the service discovery method in any other appropriate manner (e.g., by means of firmware).
[0077] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0078] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0079] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0080] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0081] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0082] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0083] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here. In the technical solution of this disclosure, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good customs.
[0084] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A service discovery method, the method comprising: When a service caller relies on a service of a target service type, the target service type is subscribed to a local registration center and a registration center other than the local registration center; The service type is the name of the service provided by the service provider; Receiving, through a service subscription software development kit SDK, information about the service provider corresponding to the target service type sent to the service caller by the local registration center and a registration center other than the local registration center, so that the service caller can find the service provider corresponding to the target service type; If the service caller receives a service offline notification sent by the registration center through the service subscription software development kit SDK, the service notified of offline is marked as temporarily unavailable, and the service notified of offline is added to the list to be detected, and the service provider is marked as to be removed in the service selector, reducing the priority of selecting this service; Detecting the survival status of the service notified to be offline; wherein the survival status includes: service survival and service non-survival; If the survival status of the service notified to be offline is that the service is alive, changing the mark of the service notified to be offline in the to-be-detected list from temporarily unavailable to normal; If the survival status of the service notified to go offline is that the service is not alive, the service notified to go offline is deleted from the to-be-detected list.
2. The method according to claim 1, wherein: Subscribing the target service type to a registration center other than the local registration center includes: The target service type is subscribed to a registration center other than the local registration center directly; or the target service type is subscribed to a registration center other than the local registration center through a proxy.
3. The method according to claim 1, further comprising: When the service caller needs to call a service of a service type, the target service to be called this time is determined from the service providers of the service type based on a predetermined service selection algorithm; wherein the service selection algorithm includes: a general service selection algorithm and a nearby service selection algorithm; Based on the information of the service provider corresponding to the target service, a service call is initiated to the target service.
4. The method according to claim 3, wherein the general service selection algorithm comprises: Random algorithm, unweighted round-robin algorithm, weighted round-robin algorithm, consistent hashing algorithm; The nearby service selection algorithm includes: a same environment priority selection algorithm, a same environment and same data center priority selection algorithm, and a same environment and same data center and same availability zone priority selection algorithm.
5. The method according to claim 1, further comprising: The service provider uses a structured data format to publish services to a local registration center through a service publishing software development kit SDK, and the registration center stores the service information in the cluster; The structured data format includes: service type name, service environment group, service data center, service data center availability zone, service interface protocol and address information, and service additional information.
6. A service discovery device, comprising: Subscription module and receiving module; wherein, The subscription module is used to subscribe to the target service type from a local registration center and a registration center other than the local registration center when the service caller relies on the service of the target service type; the service type is the name of the service provided by the service provider; The receiving module is used to receive information about the service provider corresponding to the target service type sent by the local registration center and a registration center other than the local registration center to the service caller through a service subscription software development kit SDK, so that the service caller can find the service provider corresponding to the target service type; The device also includes: a detection module, which is used to mark the service that is notified of the offline as temporarily unavailable if the service caller receives the service offline notification sent by the registration center through the service subscription software development kit SDK, and add the service that is notified of the offline to a list to be detected, and at the same time mark this service provider as a to-be-removed state in the service selector to reduce the priority of selecting this service; detect the survival state of the service that is notified of the offline; wherein the survival state includes: service survival and service non-survival; if the survival state of the service that is notified of the offline is service survival, then change the mark of the service that is notified of the offline from temporarily unavailable to normal state in the list to be detected; if the survival state of the service that is notified of the offline is service non-survival, then delete the service that is notified of the offline from the list to be detected.
7. According to the device of claim 6, the subscription module is specifically used to subscribe to the target service type directly to a registration center other than the local registration center; or to subscribe to the target service type to a registration center other than the local registration center through an agent.
8. The device according to claim 6, further comprising: A calling module is used to determine the target service to be called this time from the service providers of the service type based on a predetermined service selection algorithm when the service caller needs to call a service of a service type; wherein the service selection algorithm includes: a general service selection algorithm and a nearby service selection algorithm; and based on the information of the service provider corresponding to the target service, initiate a service call to the target service.
9. The apparatus according to claim 8, wherein the general service selection algorithm comprises: Random algorithm, unweighted round-robin algorithm, weighted round-robin algorithm, consistent hashing algorithm; The nearby service selection algorithm includes: a same environment priority selection algorithm, a same environment and same data center priority selection algorithm, and a same environment and same data center and same availability zone priority selection algorithm.
10. The device according to claim 6, further comprising: A publishing module is used for the service provider to publish services to a local registration center using a structured data format through a service publishing software development kit SDK, and the registration center stores the service information in the cluster; The structured data format includes: service type name, service environment group, service data center, service data center availability zone, service interface protocol and address information, and service additional information.
11. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 5.
12. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-5.
13. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method of calling server and proxy server
CN109618005A
Service calling method and device in multi-registration-center scene
CN110377431A
Multi-type micro-service registration center management system and method
CN112311869A
Message sending method and device
CN113496004A