CN114598743A - Service discovery method, device, electronic equipment and storage medium - Google Patents

Service discovery method, device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114598743A
CN114598743A CN202210267545.3A CN202210267545A CN114598743A CN 114598743 A CN114598743 A CN 114598743A CN 202210267545 A CN202210267545 A CN 202210267545A CN 114598743 A CN114598743 A CN 114598743A
Authority
CN
China
Prior art keywords
service
type
registry
algorithm
local
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210267545.3A
Other languages
Chinese (zh)
Inventor
穆战松
陈智新
吴敏
林华平
程明
高首锋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Xiaodu Technology Co Ltd
Original Assignee
Shanghai Xiaodu Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Xiaodu Technology Co Ltd filed Critical Shanghai Xiaodu Technology Co Ltd
Priority to CN202210267545.3A priority Critical patent/CN114598743A/en
Publication of CN114598743A publication Critical patent/CN114598743A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Telephonic Communication Services (AREA)

Abstract

The application discloses a service discovery method, a service discovery device, electronic equipment and a storage medium, relates to the technical field of computer application, and particularly relates to cloud computing. The method comprises the following steps: when the service caller depends on the service of the target service type, subscribing the target service type to a local registry and registries except the local registry; receiving information of a service provider corresponding to the target service type sent to a service caller by a local registration center and a registration center except the local registration center through a service subscription SDK; so that the service caller can find the service provider corresponding to the target service type. In the embodiment of the application, the service caller can subscribe the service in the registration center except the local registration center, data synchronization is not needed between the registration centers, the strategy is simple to realize, and the service subscription is more flexible.

Description

Service discovery method, device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer application technologies, and further relates to a cloud computing technology, and in particular, to a service discovery method and apparatus, an electronic device, and a storage medium.
Background
Microservices are a framework and organizational approach to developing software by segmenting and building applications into independent service components, each performing one or a set of functions, which communicate using well-defined interfaces. Because each service component is independently operated, the service components can be updated, deployed and expanded independently without influencing other service components. The micro-service architecture has the advantages that each functional module can be independently developed by each team, and an appropriate technical tool is selected, so that the purposes of agility, flexibility and autonomous deployment are achieved.
The registry is used as a key module in the micro service architecture, provides functions of addressing, configuration and the like among all modules, and is the basis of the micro service system. The service discovery function is typically implemented based on a registry. The registry has a single data center cluster or multiple data center clusters. In a microservice system, a service caller relies on a service discovery system to discover service providers. The service discovery system generally includes a registry, a service publishing SDK (Software Development Kit), a service subscription SDK, and other modules.
In the existing service discovery mode, data synchronization is needed between the registration centers, the implementation strategy is complex, and the service subscription is not flexible enough.
Disclosure of Invention
The disclosure provides a service discovery method, a service discovery device, an electronic device and a storage medium.
In a first aspect, the present application provides a service discovery method, including:
when a service caller depends on a service of a target service type, subscribing the target service type to a local registration center and a registration center except the local registration center;
and receiving information of the service provider corresponding to the target service type sent to the service caller by the local registration center and the registration centers except the local registration center through a service subscription SDK (service subscription Key), so that the service caller discovers the service provider corresponding to the target service type.
In a second aspect, the present application provides a service discovery apparatus, the apparatus comprising: a subscription module and a receiving module; wherein,
the subscription module is used for subscribing the target service type to a local registry and registries except the local registry when the service caller depends on the service of the target service type;
the receiving module is configured to receive, through a service subscription SDK, information of a service provider corresponding to the target service type, which is sent to the service invoker by the local registry and a registry other than the local registry, so that the service invoker discovers the service provider corresponding to the target service type.
In a third aspect, an embodiment of the present application provides an electronic device, including:
one or more processors;
a memory 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 service discovery method according to any embodiment of the present application.
In a fourth aspect, the present application provides a storage medium, on which a computer program is stored, where the computer program is executed by a processor to implement the service discovery method according to any embodiment of the present application.
In a fifth aspect, a computer program product is provided, which when executed by a computer device implements the service discovery method of any of the embodiments of the present application.
According to the technical scheme provided by the application, a service caller can subscribe services in the registration centers except the local registration center without data synchronization, the strategy is simple to realize, and the service subscription is more flexible.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
fig. 1 is a first flowchart of a service discovery method provided in an embodiment of the present application;
fig. 2 is a first structural diagram of a service discovery system provided in an embodiment of the present application;
fig. 3 is a second structural diagram of a service discovery system provided in an embodiment of the present application;
fig. 4 is a second flowchart of a service discovery method provided in an embodiment of the present application;
fig. 5 is a schematic third flow chart of a service discovery method provided in an embodiment of the present application;
fig. 6 is a schematic structural diagram of a service discovery apparatus provided in an embodiment of the present application;
fig. 7 is a block diagram of an electronic device for implementing a service discovery method according to an embodiment of the present application.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of embodiments of the present disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Example one
Fig. 1 is a first flowchart of a service discovery method provided in an embodiment of the present application, where the method may be performed by a service discovery apparatus or an electronic device, where the apparatus or the electronic device may be implemented by software and/or hardware, and the apparatus or the electronic device may be integrated in any intelligent device with a network communication function. As shown in fig. 1, the service discovery method may include the steps of:
s101, when the service caller depends on the service of the target service type, the service caller subscribes to the local registration center and the registration centers except the local registration center.
In this step, when the service invoker depends on the service of the target service type, the service invoker may subscribe to the target service type with a local registry and a registry other than the local registry. In general, a service caller may initiate subscriptions to the local registry and the registries of other data centers at the same time when starting; in addition, the service caller can also initiate subscriptions to the local registry and the registries of other data centers simultaneously after startup. The target service type in the embodiment of the present application may be one service type, or may be multiple service types, which is not limited herein. The service type in the embodiment of the present application may refer to a name of a service that a service provider may provide, such as an online service, a long connection service, and the like. In addition, the "initiate subscription at the same time" here may mean that the subscription is initiated to the local registry and the registries of other data centers at a certain time; or the subscription can be initiated to the local registry first, and then initiated to the registries of other data centers within a small time interval.
Specifically, the service caller may directly subscribe the target service type to a registry other than the local registry; alternatively, the service caller may subscribe to the target service type through a proxy to a registry other than the local registry. For example, assuming that a service caller depends on service type a, the service caller may subscribe to service type a simultaneously with a local registry and registries other than the local registry. Assuming that the service invoker depends on both service type a and service type B, the service invoker may subscribe to both service type a and service type B from both the local registry and registries other than the local registry.
S102, receiving information of the service provider corresponding to the target service type sent to the service caller by a local registration center and a registration center except the local registration center through the service subscription SDK, so that the service caller discovers the service provider corresponding to the target service type.
In this step, the service caller may receive, through the service subscription SDK, information of the service provider corresponding to the target service type, which is sent to the service caller by the local registry and the registries other than the local registry, so that the service caller finds the service provider corresponding to the target service type. For example, assume that a service discovery system may include: a registry 1 and a registry 2; assuming that a service caller depends on service type A, service type B, service type C and service type D, the service caller can subscribe service type A, service type B, service type C and service type D to the registry 1; meanwhile, the service caller may also subscribe to service type a, service type B, service type C, and service type D from the registry 2. Assuming that the registry 1 has information about the service provider corresponding to the service type a and the registry 1 has information about the service provider corresponding to the service type B, the registry 1 will send the information about the service provider corresponding to the service type a and the information about the service provider corresponding to the service type B to the service caller. Assuming that the registry 2 has the information of the service provider corresponding to the service type C and the registry 2 also has the information of the service provider corresponding to the service type D, the registry 2 will send the information of the service provider corresponding to the service type C and the information of the service provider corresponding to the service type D to the service caller.
It should be noted that the service caller is connected to the registry, and the registry finds that there is a change in the service provider of the type of service the service caller is interested in, and pushes it. For example, if a service node (i.e., a new service provider) is added to a type a service, changes (via a long connection between the subscription SDK and the registry) are pushed to the caller of the service that subscribes to the type a service.
Fig. 2 is a schematic diagram of a first structure of a service discovery system provided in an embodiment of the present application. As shown in fig. 2, the service discovery system may include: the registration center, the service publishing SDK (referred to as publishing SDK for short) and the service subscribing SDK (referred to as subscribing SDK for short). The service discovery system in fig. 2 may include two data centers, respectively: data center 1 and data center 2; among them, the data center 1 may include: registry 1, provider a1 of service type a, caller CA1 of service type a, caller CB1 of service type B; the data center 2 may include: registry 2, service type a provider a2, service type B provider B1, and service type a caller CA 2; service type a provider a1 publishes the service to registry 1; service type a provider a2 and service type B provider B1 publish services to registry 2; service type a caller CA1 subscribes to type a services on registry 1 of local data center 1, while directly subscribing to type a services from registries (registries 2) of other data centers (data centers 2). The service invoker CB1 subscribes to the type B service on the registry 1 of the local data center 1, and simultaneously subscribes directly to the type B service from the registry (registry 2) of the other data center (data center 2). The service caller CA2 subscribes to the type a service on the registry 2 of the local data center 2, and simultaneously subscribes directly to the type a service from the registry (registry 1) of the other data center (data center 1). Service invoker CA1 selects service type a provider a1 or a2 to invoke type a services based on the general service selection algorithm or the near service selection algorithm described below. Also the service invoker CA2 may invoke a type a service provided by a1 or a2 based on the selection algorithm. The service invoker CB1 selects a service provider of type B based on the same algorithm, and can only call a service of type B to B1 because there is only one service provider B1.
More specifically, the workflow of the service discovery system shown in fig. 2 may include the steps of: firstly, a service caller CA1 subscribes to type A services on a registry 1 of a local data center 1, and simultaneously subscribes to type A services directly from registries (registries 2) of other data centers (data centers 2); a service caller CA2 subscribes to the type a service on the registry 2 of the local data center 2, and simultaneously subscribes to the type a service directly from the registry (registry 1) of another data center (data center 1); ③ the service type A provider A1 issues service to the registry 1; service type a provider a2 issues service to the registry 2; service caller CA1 selects service type A provider A1 or A2 to call A type service; sixthly, the service caller CA2 selects the service type A provider A1 or A2 to call the service of type A; seventhly, the service caller CB1 subscribes to the type B service on the registry 1 of the local data center 1, and simultaneously subscribes to the type B service directly to the registry (registry 2) of another data center (data center 2); service type B provider B1 issues service to registration center 2; ninthly, the service caller CB1 selects the service type B provider B1 to call the type B service.
Fig. 3 is a schematic diagram of a second structure of a service discovery system according to an embodiment of the present application. As shown in fig. 3, the service discovery system may include two data centers: respectively a data center 1 and a data center 2; among them, the data center 1 may include: registry 1, subscription service proxy1, provider of service type a1, caller of service type a CA1, caller of service type B CB 1; the data center 2 may include: registry 2, subscription service broker proxy2, service type a provider a2, service type B provider B1, and service type a caller CA 2; service type a provider a1 publishes the service to registry 1; service type a provider a2 and service type B provider B1 publish services to registry 2; service type a caller CA1 subscribes to type a services on registry 1 of local data center 1, while subscribing to type a services from registries (registries 2) of other data centers (data centers 2) through subscription service broker 1. The service invoker CB1 subscribes to the type B service on registry 1 of the local data center 1, and simultaneously subscribes to the type B service from registry 2 of another data center (data center 2) through the subscription service broker 1. The service invoker CA2 subscribes to type a services on registry 2 of the local data center 2, and simultaneously subscribes to type a services from registry 1 of other data center (data center 1) through subscription service broker 2. Service invoker CA1 selects service type a provider a1 or a2 to invoke type a services based on the general service selection algorithm or the near service selection algorithm described below. Likewise, service invoker CA2 may also invoke type a services provided by a1 or a2 based on the selection algorithm. The service invoker CB1 selects a service provider of type B based on the same algorithm, and can only call a service of type B to B1 because there is only one service provider B1.
More specifically, the workflow of the service discovery system shown in fig. 3 may include the steps of: firstly, a service caller CA1 subscribes to type A services on a registry 1 of a local data center 1, and simultaneously subscribes to type A services through proxy to registries (registries 2) of other data centers (data centers 2); a service caller CA2 subscribes to a type a service on the registry 2 of the local data center 2, and subscribes to a type a service through proxy2 from the registry (registry 1) of another data center (data center 1); ③ the service type A provider A1 issues service to the registry 1; fourthly, the service type A provider A2 issues service to the registration center 2; service caller CA1 selects service type A provider A1 or A2 to call A type service; sixthly, the service caller CA2 selects the service type A provider A1 or A2 to call the service of type A; seventhly, the service caller CB1 subscribes to the type B service on the registry 1 of the local data center 1, and subscribes to the type B service with the proxy1 from the registry (registry 2) of the other data center (data center 2); service type B provider B1 issues service to registration center 2; ninthly, the service caller CB1 selects the service type B provider B1 to call the type B service.
In an embodiment of the present application, the service invoker may also invoke the service of the target service type based on the information of the service provider corresponding to the target service type. When a service caller needs to call a service of a service type, a target service needing to be called at this time can be determined in a service provider 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 initiating service call to the target service based on the information of the service provider corresponding to the target service. When the service caller depends on a plurality of service types, the above operation may be repeatedly performed for each service type.
Further, the general service selection algorithm in the embodiment of the present application includes: a random algorithm, a polling algorithm without weight, a polling algorithm with weight and a consistent hash algorithm; the proximity service selection algorithm may include: the method comprises an environment-shared preference algorithm, an environment-shared preference algorithm and a data center-shared preference algorithm, and an environment-shared preference algorithm and a data center-shared preference algorithm. Specifically, 1) with the environment preference algorithm: for example, if the service caller is in the pre-release environment, the service provider in the pre-release environment is preferably selected; this option can also facilitate strategies such as AB testing. 2) And (3) a same-environment and same-data center preference algorithm: and increasing the preference of the same data center on the basis of the former algorithm. 3) And (3) a same environment, a same data center and a same available area preference selection algorithm: and increasing the preference of the same available area of the same data center on the basis of the former algorithm. In the service selection algorithm, the granularity is smaller from top to bottom, and after a similar service selects a granularity, if there is no available service in the same granularity, a service with a larger granularity is considered, for example, if a policy of preference selection from the environment and the data center is adopted, if there is no available service provider in the data center and there is a service provider needed in another data center, then services in another data center are selected for service invocation.
In the existing service discovery mode, after a service provider is started, the service provider issues a service to a registration center, and generally declares information such as an interface, a calling address, a calling protocol and the like provided by the service; when a service caller starts, the caller subscribes to the service on which he/she depends, for example, what interface and protocol information are depended on. After the service provider releases the registration center, heartbeat information is typically maintained with the registration center to keep alive. The registry can adopt single data center cluster deployment or multi-data center cluster deployment according to business requirements, and the multi-data center cluster mode is realized by two modes: (1) the registry cluster directly spans a plurality of data centers, the service of each data center is directly published to the whole cluster, and the subscription service information is also subscribed to the whole cluster. (2) Each data center has its own registration center cluster, the service in the data center is only registered to the local registration center, the registration centers of the data centers are mutually synchronous, and the subscription is directly subscribed to the registration center of the data center. In the implementation manner (1), a strong consistency model is generally adopted for the open source or self-research implementation of the data center, and when a registry cluster is deployed across multiple data centers (for example, three data centers of south China, north China and east China), delay instability during service release may be caused due to relatively unstable networks among the multiple data centers, and in an extreme case, when a network fault is disconnected among the data centers, the cluster may be failed and subscription service cannot be released; in the implementation mode (2), each registry synchronizes service information with other registries through a dedicated line, and simultaneously needs to implement a synchronization policy by itself, so that a data resynchronization and data verification mechanism when synchronous data is interrupted due to network failure and the like is solved, and the implementation policy is relatively complex.
According to the service discovery method provided by the embodiment of the application, when a service caller depends on the service of a target service type, the target service type is subscribed to a local registry and registries except the local registry; and then receiving 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 centers except the local registration center through the service subscription SDK, so that the service caller discovers the service provider corresponding to the target service type. That is, the service caller in the present application can subscribe to the service simultaneously with the local registry and the registries other than the local registry, so that the local registry does not need to perform data synchronization with other registries. In the existing service discovery method, each registry needs to perform data synchronization with other registries, that is, each registry stores all service information, and if data synchronization interruption occurs, data needs to be resynchronized. Because the technical means that the service caller subscribes the service to the registration centers except the local registration center is adopted, the technical problems that each registration center needs to synchronize service information with other registration centers and needs to realize a synchronization strategy by the service caller in the prior art are solved, and the technical problems that the strategies are complex to realize are solved by a data resynchronization and data verification mechanism when the synchronous data is interrupted due to network faults and the like; moreover, the technical scheme of the embodiment of the application is simple and convenient to implement, convenient to popularize and wide in application range.
Example two
Fig. 4 is a second flowchart of a service discovery method according to an embodiment of the present application. Further optimization and expansion are performed based on the technical scheme, and the method can be combined with the various optional embodiments. As shown in fig. 4, the service discovery method may include the steps of:
s401, when the service caller depends on the service of the target service type, the service caller subscribes to the local registration center and the registration centers except the local registration center.
S402, receiving information of the service provider corresponding to the target service type sent to the service caller by the local registration center and the registration centers except the local registration center through the service subscription SDK, so that the service caller discovers the service provider corresponding to the target service type.
In a specific embodiment of the present application, the service publishing SDK and the service subscribing SDK are integrated by the service publisher and the service caller, respectively, and one service node may be a service provider or another service caller, so that the service node may have two roles. In addition, the registration center can be realized based on etcd, and also can be realized based on nacos, zookeeper, consul and the like, each data center is provided with a registration center etcd cluster, the cluster is only in a single data center, network delay and jitter are small, and the probability of cluster failure is small. The service provider of the data center issues the service to a local registration center through a service issuing SDK; the service caller subscribes the service of the data center through the service subscription SDK, and subscribes the service of other data centers at the same time, and can directly subscribe to other data centers and also subscribe to other data centers through proxy.
S403, based on the information of the service provider corresponding to the target service type, calling the service of the target service type.
According to the service discovery method provided by the embodiment of the application, when a service caller depends on the service of a target service type, the target service type is subscribed to a local registry and registries except the local registry; and then receiving 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 centers except the local registration center through the service subscription SDK, so that the service caller discovers the service provider corresponding to the target service type. That is, the service caller in the present application can subscribe to the service simultaneously with the local registry and the registries other than the local registry, so that the local registry does not need to perform data synchronization with other registries. In the existing service discovery method, each registry needs to perform data synchronization with other registries, that is, each registry stores all service information, and if data synchronization interruption occurs, data needs to be resynchronized. Because the technical means that the service caller subscribes the service to the registration centers except the local registration center is adopted, the technical problems that each registration center needs to synchronize service information with other registration centers and needs to realize a synchronization strategy by the service caller in the prior art are solved, and the technical problems that the strategies are complex to realize are solved by a data resynchronization and data verification mechanism when the synchronous data is interrupted due to network faults and the like; moreover, the technical scheme of the embodiment of the application is simple and convenient to implement, convenient to popularize and wide in application range.
EXAMPLE III
Fig. 5 is a schematic diagram of a third flow of a service discovery method according to an embodiment of the present application. Further optimization and expansion are performed based on the technical scheme, and the method can be combined with the various optional embodiments. As shown in fig. 5, the service discovery method may include the steps of:
s501, when the service caller depends on the service of the target service type, the service caller subscribes to the local registration center and the registration centers except the local registration center.
S502, receiving information of the service provider corresponding to the target service type sent to the service caller by the local registration center and the registration centers except the local registration center through the service subscription SDK, so that the service caller discovers the service provider corresponding to the target service type.
S503, when the service caller needs to call a service of a service type, determining a target service to be called in a service provider of the service type based on a predetermined service selection algorithm; wherein, the service selection algorithm comprises: a general service selection algorithm and a proximity service selection algorithm.
S504, service calling is initiated to the target service based on the information of the service provider corresponding to the target service.
In the specific embodiment of the application, a service provider can adopt a structured data format, issue services to a registration center through a service issue SDK, and store information of the services into a cluster by the registration center; the structured data format includes: the service type name, the environment group where the service is located, the data center where the service is located, the available area of the data center where the service is located, the interface protocol and address information of the service, and the additional information of the service. Specifically, 1) service type name: such as application management services; 2) grouping environments where services are located: such as a test environment, a pre-release environment, a production environment, etc.; 3) the data center where the service is located: such as south China data center, North China data center; 4) more detailed information such as available areas of the data center where the service is located; 5) the interface protocol and address information of the service includes: supported interfaces, protocol types, data center internal addresses, global addresses accessible from other data centers, and the like; 6) additional information for the service is parsed by the specific application.
In a specific embodiment of the application, if a service caller receives a service offline notification sent by a registration center through a service subscription SDK, the service notifying offline is marked as temporarily unavailable, and the service notifying offline is added to a list to be detected; then detecting the survival state of the service notifying the offline; wherein the survival status comprises: service alive and service not alive; if the survival state of the service informing of offline is service survival, changing the service mark informing of offline from temporary unavailability to a normal state in the list to be detected; and if the survival state of the service informing the offline is that the service is not alive, deleting the service informing the offline in the list to be detected. Specifically, the service provider maintains a periodic heartbeat with the local registration center etcd cluster to indicate that the service provider is in a survival state, and actively logs out the service provider from the registration center etcd cluster before the service is offline. When the registry cluster detects that the service is offline, a service caller (including callers of the data center and other data centers) is informed, and after the service caller confirms that the service provider is offline, the service is removed from the selector, and the service can not be called by subsequent service calls. If network jitter occurs between the service provider and the registration center etcd cluster, the heartbeat timeout may cause triggering of notification of service offline, and the network between the service caller and the service provider may be normal, so that the service selector may be removed by mistake; meanwhile, after the service provider reconnects to the registry cluster, the service provider will re-register, and thus the service caller will be informed to add back the service selector again, which may cause the ping-pong effect of removing the adding back frequently in extreme conditions. For this situation, the present application makes some optimizations in the service subscription SDK to avoid this: after receiving the offline notification of the registration center, the service caller puts the service provider into the list to be detected, marks the service provider in the service selector as the state to be removed, selects the service with lower priority, and selects the service when there is no other available service. And starting to detect whether the service is available after waiting for a period of time, wherein the waiting for a period of time is to avoid that the service is not completely logged out after logging off to a registration center when the service is offline, so that the subsequent detection is successful and the service cannot be offline. If the service is available after the detection, the service provider is re-marked as normal. And ignoring the service online notification after the network of the subsequent service provider and the registration center etcd cluster is restored. If the detection fails, the service provider is eventually deleted from the service selector.
According to the service discovery method provided by the embodiment of the application, when a service caller depends on the service of a target service type, the target service type is subscribed to a local registry and registries except the local registry; and then receiving 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 centers except the local registration center through the service subscription SDK, so that the service caller discovers the service provider corresponding to the target service type. That is, the service caller in the present application can subscribe to the service simultaneously with the local registry and the registries other than the local registry, so that the local registry does not need to perform data synchronization with other registries. In the existing service discovery method, each registry needs to perform data synchronization with other registries, that is, each registry stores all service information, and if data synchronization interruption occurs, data needs to be resynchronized. Because the technical means that the service caller subscribes the service to the registration centers except the local registration center is adopted, the technical problems that each registration center needs to synchronize service information with other registration centers and needs to realize a synchronization strategy by the service caller in the prior art are solved, and the technical problems that the strategies are complex to realize are solved by a data resynchronization and data verification mechanism when the synchronous data is interrupted due to network faults and the like; moreover, the technical scheme of the embodiment of the application is simple and convenient to implement, convenient to popularize and wide in application range.
Example four
Fig. 6 is a schematic structural diagram of a service discovery apparatus according to an embodiment of the present application. As shown in fig. 6, the apparatus 600 includes: a subscription module 601 and a receiving module 602; wherein,
the subscription module 601 is configured to subscribe the target service type to a local registry and a registry other than the local registry when the service caller depends on the service of the target service type;
the receiving module 602 is configured to receive, through a service subscription SDK, information of a service provider corresponding to the target service type sent to the service invoker by the local registry and a registry other than the local registry, so that the service invoker discovers the service provider corresponding to the target service type.
Further, the subscription module 601 is specifically configured to subscribe the target service type directly to a registry other than the local registry; or subscribing the target service type to a registry other than the local registry through a proxy.
Further, the apparatus further comprises: a calling module 603 (not shown in the figure), configured to determine, based on a predetermined service selection algorithm, a target service to be called in the service provider of the service type if the service caller needs to call a service of the service type; wherein the service selection algorithm comprises: a general service selection algorithm and a nearby service selection algorithm; and initiating service call to the target service based on the information of the service provider corresponding to the target service.
Further, the generic service selection algorithm comprises: a random algorithm, a polling algorithm without weight, a polling algorithm with weight and a consistent Hash algorithm; the nearby service selection algorithm comprises: the method comprises an environment-shared preference algorithm, an environment-shared preference algorithm and a data center-shared preference algorithm, and an environment-shared preference algorithm and a data center-shared preference algorithm.
Further, the apparatus further comprises: a detecting module 604 (not shown in the figure), configured to mark, if the service caller receives a service offline notification sent by the registration center through the service subscription SDK, a service notifying offline as temporarily unavailable, and add the service notifying offline to a to-be-detected list; detecting the survival state of the service which is notified of the offline; wherein the survival status comprises: service alive and service not alive; and if the survival state of the service for notifying offline is service survival, changing the service mark for notifying offline from temporary unavailability to a normal state in the list to be detected.
Further, the apparatus further comprises: a publishing module 605 (not shown in the figure) for the service provider to publish the service to the registration center of the data center through the service publishing SDK by using a structured data format, and the registration center stores the information of the service into the cluster; the structured data format includes: the service type name, the environment group where the service is located, the data center where the service is located, the available area of the data center where the service is located, the interface protocol and address information of the service, and the additional information of the service.
The service discovery device can execute the method provided by any embodiment of the application, and has the corresponding functional modules and beneficial effects of the execution method. For details of the service discovery method provided in any embodiment of the present application, reference may be made to the technical details not described in detail in this embodiment.
EXAMPLE five
The present disclosure also provides an electronic device, a readable storage medium, and a computer program product according to embodiments of the present disclosure.
FIG. 7 illustrates a schematic block diagram of an example electronic device 700 that can be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may 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 meant to be examples only, and are not intended to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 7, the device 700 comprises a computing unit 701, which may perform various suitable 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 by a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
Various components in the device 700 are connected to the I/O interface 705, including: an input unit 706 such as a keyboard, a mouse, or the like; an output unit 707 such as various types of displays, speakers, and the like; a storage unit 708 such as a magnetic disk, optical disk, or the like; and a communication unit 709 such as a network card, modem, wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
Computing unit 701 may be a variety of general and/or special purpose 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 specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The computing unit 701 performs the various methods and processes described above, such as the service discovery method. For example, in some embodiments, the service discovery method may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as storage unit 708. In some embodiments, part or all of a computer program may be loaded onto and/or installed onto device 700 via ROM 702 and/or communications unit 709. When loaded into RAM 703 and executed by the computing unit 701, may perform one or more steps of the service discovery method described above. Alternatively, in other embodiments, the computing unit 701 may be configured to perform the service discovery method by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods 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, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The 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, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here 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 a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user may provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, 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 may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), blockchain networks, and the internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service are overcome.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel, sequentially, or in different orders, and are not limited herein as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved. In the technical scheme of the disclosure, the acquisition, storage, application and the like of the personal information of the related user all accord with the regulations of related laws and regulations, and do not violate the good customs of the public order.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.

Claims (15)

1. A method of service discovery, the method comprising:
when a service caller depends on a service of a target service type, subscribing the target service type to a local registry and registries except the local registry;
and receiving information of the service provider corresponding to the target service type sent to the service caller by the local registration center and the registration centers except the local registration center through a service subscription Software Development Kit (SDK), so that the service caller discovers the service provider corresponding to the target service type.
2. The method of claim 1, wherein subscribing to the target service type from a registry other than the local registry comprises:
directly subscribing the target service type to a registry other than the local registry; or subscribing the target service type to a registry other than the local registry through a proxy.
3. The method of claim 1, further comprising:
when the service caller needs to call a service of a service type, determining a target service needing to be called in a service provider of the service type based on a predetermined service selection algorithm; wherein the service selection algorithm comprises: a general service selection algorithm and a nearby service selection algorithm;
and initiating service call to the target service based on the information of the service provider corresponding to the target service.
4. The method of claim 3, the generic service selection algorithm comprising: a random algorithm, a polling algorithm without weight, a polling algorithm with weight and a consistent Hash algorithm; the nearby service selection algorithm comprises: the method comprises an environment-shared preference algorithm, an environment-shared preference algorithm and a data center-shared preference algorithm, and an environment-shared preference algorithm and a data center-shared preference algorithm.
5. The method of claim 1, further comprising:
if the service caller receives a service offline notification sent by the registration center through the service subscription SDK, marking the service notifying offline as temporarily unavailable, and adding the service notifying offline to a list to be detected;
detecting the survival state of the service which notifies off-line; wherein the survival status comprises: service alive and service not alive;
and if the survival state of the service notifying the offline is the service survival, changing the service mark notifying the offline from the temporary unavailability to the normal state in the list to be detected.
6. The method of claim 1, further comprising:
the service provider issues service to a local registration center through the service issuing SDK by adopting a structured data format, and the registration center stores the information of the service into a cluster; the structured data format includes: the service type name, the environment group where the service is located, the data center where the service is located, the available area of the data center where the service is located, the interface protocol and address information of the service, and the additional information of the service.
7. A service discovery apparatus, the apparatus comprising: a subscription module and a receiving module; wherein,
the subscription module is used for subscribing the target service type to a local registry and registries except the local registry when the service caller depends on the service of the target service type;
the receiving module is configured to receive, through a service subscription software development kit SDK, information of a service provider corresponding to the target service type, which is sent to the service invoker by the local registration center and a registration center other than the local registration center, so that the service invoker discovers the service provider corresponding to the target service type.
8. The apparatus of claim 7, the subscription module, in particular, configured to subscribe to the target service type directly from a registry other than the local registry; or subscribing the target service type to a registry other than the local registry through a proxy.
9. The apparatus of claim 7, further comprising: the calling module is used for determining a target service to be called in the service provider of the service type based on a predetermined service selection algorithm if the service caller needs to call the service of the service type; wherein the service selection algorithm comprises: a general service selection algorithm and a nearby service selection algorithm; and initiating service call to the target service based on the information of the service provider corresponding to the target service.
10. The apparatus of claim 9, the generic service selection algorithm comprising: a random algorithm, a polling algorithm without weight, a polling algorithm with weight and a consistent hash algorithm; the nearby service selection algorithm comprises: the method comprises an environment-shared preference algorithm, an environment-shared preference algorithm and a data center-shared preference algorithm, and an environment-shared preference algorithm and a data center-shared preference algorithm.
11. The apparatus of claim 7, further comprising: the detection module is used for marking the service which is notified of offline as temporarily unavailable and adding the service which is notified of offline into a list to be detected if the service caller receives the service offline notification sent by the registration center through the service subscription SDK; detecting the survival state of the service which is notified of the offline; wherein the survival status comprises: service alive and service not alive; and if the survival state of the service for notifying offline is service survival, changing the service mark for notifying offline from temporary unavailability to a normal state in the list to be detected.
12. The apparatus of claim 7, further comprising: the release module is used for the service provider to release the service to a local registration center through the service release SDK by adopting a structured data format, and the registration center stores the information of the service into a cluster; the structured data format includes: the service type name, the environment group where the service is located, the data center where the service is located, the available area of the data center where the service is located, the interface protocol and address information of the service, and the additional information of the service.
13. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
14. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-6.
15. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-6.
CN202210267545.3A 2022-03-17 2022-03-17 Service discovery method, device, electronic equipment and storage medium Pending CN114598743A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210267545.3A CN114598743A (en) 2022-03-17 2022-03-17 Service discovery method, device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210267545.3A CN114598743A (en) 2022-03-17 2022-03-17 Service discovery method, device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114598743A true CN114598743A (en) 2022-06-07

Family

ID=81819665

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210267545.3A Pending CN114598743A (en) 2022-03-17 2022-03-17 Service discovery method, device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114598743A (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105933444A (en) * 2016-06-27 2016-09-07 焦点科技股份有限公司 Service discovering method based on cooperation of registration center and caching mechanism
CN109618005A (en) * 2019-01-18 2019-04-12 华为终端有限公司 Method for calling server and proxy server
CN110377431A (en) * 2019-07-29 2019-10-25 中国工商银行股份有限公司 Service calling method and device under more registration center's scenes
KR20200012945A (en) * 2017-06-02 2020-02-05 후아웨이 테크놀러지 컴퍼니 리미티드 Methods, Registration Centers, and Devices for Service Discovery
CN112463382A (en) * 2020-12-01 2021-03-09 中国工商银行股份有限公司 Heterogeneous data processing method and device under distributed scene
WO2021109640A1 (en) * 2019-12-06 2021-06-10 华为技术有限公司 Registration method and apparatus
CN113055479A (en) * 2021-03-17 2021-06-29 中国工商银行股份有限公司 Self-adaptive processing method, device and system for distributed service cluster load
WO2021129008A1 (en) * 2019-12-23 2021-07-01 中国银联股份有限公司 Service invocation method, apparatus and device, and medium
CN113496004A (en) * 2020-04-02 2021-10-12 华为技术有限公司 Message sending method and device
US20210377722A1 (en) * 2018-03-02 2021-12-02 Huawei Technologies Co., Ltd. Profile generation method, profile acquisition method, and related device and storage medium

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105933444A (en) * 2016-06-27 2016-09-07 焦点科技股份有限公司 Service discovering method based on cooperation of registration center and caching mechanism
KR20200012945A (en) * 2017-06-02 2020-02-05 후아웨이 테크놀러지 컴퍼니 리미티드 Methods, Registration Centers, and Devices for Service Discovery
US20210377722A1 (en) * 2018-03-02 2021-12-02 Huawei Technologies Co., Ltd. Profile generation method, profile acquisition method, and related device and storage medium
CN109618005A (en) * 2019-01-18 2019-04-12 华为终端有限公司 Method for calling server and proxy server
CN110377431A (en) * 2019-07-29 2019-10-25 中国工商银行股份有限公司 Service calling method and device under more registration center's scenes
WO2021109640A1 (en) * 2019-12-06 2021-06-10 华为技术有限公司 Registration method and apparatus
WO2021129008A1 (en) * 2019-12-23 2021-07-01 中国银联股份有限公司 Service invocation method, apparatus and device, and medium
CN113496004A (en) * 2020-04-02 2021-10-12 华为技术有限公司 Message sending method and device
CN112463382A (en) * 2020-12-01 2021-03-09 中国工商银行股份有限公司 Heterogeneous data processing method and device under distributed scene
CN113055479A (en) * 2021-03-17 2021-06-29 中国工商银行股份有限公司 Self-adaptive processing method, device and system for distributed service cluster load

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
易强等: "调度自动化系统多网段资源定位技术的研究与实现", 智慧电力, 20 December 2017 (2017-12-20) *

Similar Documents

Publication Publication Date Title
CN112583931B (en) Message processing method, message middleware, electronic device, and storage medium
CN110795503A (en) Multi-cluster data synchronization method and related device of distributed storage system
CN112860342B (en) Method, device, equipment, system and storage medium for micro-service configuration
EP3817338B1 (en) Method and apparatus for acquiring rpc member information, electronic device and storage medium
CN113656147B (en) Cluster deployment method, device, equipment and storage medium
US11223522B1 (en) Context-based intelligent re-initiation of microservices
US7805503B2 (en) Capability requirements for group membership
CN110391940A (en) Response method, device, system, equipment and the storage medium of address of service
KR20220049498A (en) State machine processing method and device, state processing method and device, electronic equipment and storage medium
CN113067860B (en) Method, apparatus, device, medium and product for synchronizing information
CN112817992B (en) Method, apparatus, electronic device and readable storage medium for executing change task
CN112087506B (en) Cluster node management method and device and computer storage medium
WO2021082868A1 (en) Data managmenet method for distributed storage system, apparatus, and electronic device
CN114598743A (en) Service discovery method, device, electronic equipment and storage medium
CN114338763B (en) Micro-service calling method, micro-service calling device, server and computer readable storage medium
CN112799879B (en) Fault processing method, device, equipment and storage medium of node
CN114567540B (en) Master-slave node switching method, device, equipment, medium and program product
CN113992690B (en) Message transmission method, device, equipment and storage medium
CN113660339B (en) Method and apparatus for decentralizing clusters
CN117395263B (en) Data synchronization method, device, equipment and storage medium
CN113259445B (en) Service management method and system in mixed cloud mode
CN114513524B (en) Resource synchronization method and device, electronic equipment and storage medium
CN112818060B (en) Data synchronization method, device, electronic equipment and readable storage medium
CN113596172B (en) Method and device for updating nodes in distributed cluster
CN114138538A (en) Abnormal instance processing method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination