CN115412562A - Service registration and subscription method, device and equipment - Google Patents

Service registration and subscription method, device and equipment Download PDF

Info

Publication number
CN115412562A
CN115412562A CN202211006915.4A CN202211006915A CN115412562A CN 115412562 A CN115412562 A CN 115412562A CN 202211006915 A CN202211006915 A CN 202211006915A CN 115412562 A CN115412562 A CN 115412562A
Authority
CN
China
Prior art keywords
server
subscription
service
cluster
cluster server
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
CN202211006915.4A
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.)
Tianyi Safety Technology Co Ltd
Original Assignee
Tianyi Safety 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 Tianyi Safety Technology Co Ltd filed Critical Tianyi Safety Technology Co Ltd
Priority to CN202211006915.4A priority Critical patent/CN115412562A/en
Publication of CN115412562A publication Critical patent/CN115412562A/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/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • H04L67/1023Server selection for load balancing based on a hash applied to IP addresses or costs
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application discloses a service registration and subscription method, a device and equipment, wherein the method is executed by a server proxy: receiving a registration request and a subscription request; when the cluster server is determined to be normal, communicating with the cluster server to update a server IP port list of a corresponding service name and generate a subscription event of subscription service; monitoring subscription events of different subscription services issued by a cluster server, and generating copy synchronization queues ISR of the different subscription services on the basis of the subscription events; when the cluster server is determined to be abnormal, sensing online and offline information of a server side and updating ISRs (abnormal subscriber servers) of different subscription services; and issuing the cluster server state and a server IP port list of the client subscription service based on ISRs of different subscription services. Therefore, the problem that the high availability of the current micro-service depends on the robustness of the zk cluster and the on-line and off-line information of the latest server cannot be dynamically sensed during the election period of the zk main node or the downtime of the zk cluster is solved.

Description

Service registration and subscription method, device and equipment
Technical Field
The present invention relates to the field of micro service technologies, and in particular, to a method, an apparatus, and a device for service registration and subscription.
Background
In the existing micro-service development system, many projects are based on a distributed framework Dubbo + cluster zookeeper (zk for short) micro-service mode, and service registration discovery is realized through zk. But zk implements the CP principle in the distributed system CAP (consistency C + availability a + partition tolerance P), which is somewhat weakened for Avaliable during master node master election. After the zk master is hung up, the rest nodes of the zk can select a new master node to provide service for the outside in hundreds of milliseconds at the fastest speed, but the zk cluster is unavailable during zk election or cluster down. Although the Dubbo service polls and accesses the server through the server IP port list cached by the client, the latest offline and online of the server cannot be sensed, the availability of the cached IP port cannot be guaranteed, and the polling access reduces the access performance and possibly causes the client to call a fault phenomenon. Project replacement zk reconstruction, which is strictly required for service, may introduce project instability.
Disclosure of Invention
The application aims to provide a service registration and subscription method, device and equipment. The method and the device are used for solving the problems that the latest offline and online of a server cannot be sensed, the availability of a cached IP port cannot be guaranteed, the access performance is reduced by polling access and the phenomenon of calling fault of a client possibly occurs when a zk cluster is unavailable due to the fact that zk election is carried out or the cluster is down in the prior art.
In a first aspect, an embodiment of the present application provides a service registration and subscription method, which is applied to a server proxy in communication with a cluster server, a server and a client, and the method includes:
receiving a registration request carrying a service name sent by a server side and a subscription request of subscription service sent by a client side;
when the cluster server is determined to be normal, communicating with the cluster server to enable the cluster server to update a server IP port list of a corresponding service name and generate a subscription event of the subscription service;
monitoring subscription events of different subscription services issued by a cluster server, and generating replica synchronization queues ISR of the different subscription services by taking the subscription events of the different subscription services as a reference;
when the cluster server is determined to be abnormal, sensing online and offline information of a server side and updating copy synchronization queues ISR of different subscription services;
and issuing the cluster server state and the server IP port list of the client subscription service based on the copy synchronization queue ISR of the different subscription services.
As a possible implementation manner, the following manner is adopted to monitor whether the cluster server is normal or abnormal:
monitoring subscription events of different subscription services published by a cluster server according to the subscription event publishing frequency of the subscription services;
and when the subscription events of different subscription services are not monitored for the continuous set times, determining that the cluster server is abnormal, otherwise, determining that the cluster server is normal.
As a possible implementation manner, sensing online and offline information of a server and updating a copy synchronization queue ISR of different subscription services includes:
detecting whether different service terminals in ISRs of different subscription services are online or not through a heartbeat mechanism;
deleting the IP port corresponding to the offline server from the corresponding ISR;
and adding the IP port of the server side, which abnormally sends the registration request by the cluster server, to a copy synchronization queue ISR (Internet service register) corresponding to the subscription service.
As a possible implementation manner, the server-side agent is multiple and stateless server-side agents, and each time the copy synchronization queue ISR is generated or updated, the method further includes:
and generating a globally unique and incremental identification ID bound with the replica synchronization queue ISR, and broadcasting the replica synchronization queue ISR and the ID to other server-side agents when the cluster server is abnormal, so that the other server-side agents determine whether to update the local replica synchronization queue ISR according to the ID.
As a possible implementation manner, based on the ISR, the method for issuing a server IP port list of the client subscription service includes:
and when the cluster server is determined to be abnormal, based on the copy synchronization queues ISR of different subscription services, arranging the IP ports of the service ends of the subscription services in the order from late to early according to the registration time, and then issuing the IP ports to the corresponding client.
As a possible implementation manner, after receiving a subscription request for subscribing to a service sent by a client, the method further includes:
determining whether a subscription is initiated to a cluster server for the subscription service before, if not, sending the subscription request to the cluster server so as to generate a server IP port list for the subscription service;
determining whether a subscription to the client agent is made, and if not, adding the client to the receiver of the subscription event of the subscription service.
In a second aspect, an embodiment of the present application provides a service registration and subscription method, applied to a client, including:
sending a subscription request for subscribing service to a server proxy through a client proxy;
receiving the cluster server state sent by the server agent and the server IP port list of the subscription service through a client agent;
and polling the server IP ports in the server IP port list to normal access by adopting a corresponding strategy through the client agent according to the cluster server state.
As a possible implementation manner, polling the server IP ports in the server IP port list by using a corresponding policy according to the cluster server state includes:
when the cluster server is determined to be in a normal state, performing polling access according to the priority of the server IP port determined according to the access times in the server IP port list of the subscription service, wherein the priority is higher when the access times are less;
and when the successful access to the IP port of the service end is determined, adding 1 to the access frequency of the IP port of the service end with the successful access.
As a possible implementation manner, polling the server IP ports in the server IP port list by using a corresponding policy according to the cluster server state includes:
when the cluster server is determined to be abnormal, performing polling access according to the priority of the service end IP port determined according to the registration time in the service end IP port list of the subscription service, wherein the later the registration time, the higher the priority is;
and when the IP port of the service end is successfully accessed, adding 1 to the access frequency of the IP port of the service end which is successfully accessed.
In a third aspect, an embodiment of the present application provides a service registration and subscription apparatus, where the apparatus includes:
the request receiving module is used for receiving a registration request carrying a service name sent by a server and receiving a subscription request of subscription service sent by a client;
the subscription updating module is used for communicating with the cluster server to enable the cluster server to update a server IP port list of a corresponding service name and generate a subscription event of the subscription service when the cluster server is determined to be normal;
the system comprises a copy generation module, a synchronization queue management module and a synchronization queue management module, wherein the copy generation module is used for monitoring subscription events of different subscription services issued by a cluster server and generating copy synchronization queues ISR of the different subscription services by taking the subscription events of the different subscription services as a reference;
the system comprises a copy updating module, a synchronization queue updating module and a service module, wherein the copy updating module is used for sensing online and offline information of a server side and updating copy synchronization queues ISR of different subscription services when the cluster server is determined to be abnormal;
and the copy synchronization module is used for issuing a cluster server state and a server IP port list of the client subscription service based on the copy synchronization queues ISR of the different subscription services.
In a fourth aspect, an embodiment of the present application provides a service registration and subscription device, where the device includes:
the request receiving module is used for sending a subscription request of subscription service to the server-side proxy through the client-side proxy;
the port determining module is used for receiving the cluster server state sent by the server agent and the server IP port list of the subscription service through the client agent;
and the port access module is used for polling the server IP ports in the server IP port list to normal access by adopting a corresponding strategy according to the cluster server state through the client agent.
In a fifth aspect, an embodiment of the present application provides a device for service registration and subscription, including 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, the instructions being executable by the at least one processor to enable the at least one processor to perform the method for service registration and subscription provided by the first aspect above, or to perform the method for service registration and subscription provided by the second aspect above.
In a sixth aspect, another embodiment of the present application further provides a computer storage medium storing a computer program, where the computer program is used to enable a computer to execute the method for registering and subscribing to a service provided in the embodiment of the present application.
The service registration service and subscription method, device and equipment provided by the embodiment of the application belong to a technical scheme for normally providing latest service registration discovery capability through an ISR copy adapted by an agent under zk election and long-time downtime of a zk cluster, and the high availability of the whole service is improved.
Additional features and advantages of the application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments of the present application will be briefly described below, and it is obvious that the drawings described below are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic diagram illustrating a service registration and subscription process according to the related art;
FIG. 2 is a flowchart illustrating a service registration and subscription method performed by a server agent according to an embodiment of the present disclosure;
FIG. 3 is a flow chart illustrating a process for providing registration capability by a server agent according to an embodiment of the present disclosure;
FIG. 4a is a schematic diagram illustrating a processing flow of a server-side proxy receiving a subscription request according to an embodiment of the present application;
FIG. 4b is a flowchart illustrating a process for providing a subscription capability by a server proxy according to an embodiment of the present disclosure;
FIG. 5 is a flowchart illustrating a service registration and subscription method performed by a client agent according to an embodiment of the present application;
FIG. 6a is a flowchart illustrating a process of a client agent initiating a subscription request according to an embodiment of the application;
FIG. 6b is a detailed flowchart of a service registration and subscription method performed by a client agent according to an embodiment of the present application;
FIG. 7 is a detailed flowchart illustrating a method for performing service registration and subscription by a server agent in cooperation with a client agent according to an embodiment of the present disclosure;
FIG. 8 is a block diagram illustrating an exemplary architecture of a service registration and subscription device according to an embodiment of the present application;
FIG. 9 is a block diagram illustrating a service registration and subscription device according to another embodiment of the present application;
fig. 10 is a schematic structural diagram of a service registration and subscription device according to an embodiment of the present application.
Detailed Description
To further illustrate the technical solutions provided by the embodiments of the present application, the following detailed description is made with reference to the accompanying drawings and the detailed description. Although the embodiments of the present application provide method steps as shown in the following embodiments or figures, more or fewer steps may be included in the method based on conventional or non-inventive efforts. In steps where no necessary causal relationship exists logically, the order of execution of the steps is not limited to that provided by the embodiments of the present application. The method can be executed in the order of the embodiments or the method shown in the drawings or in parallel in the actual process or the control device.
As shown in fig. 1, a service registration and subscription process in the related art mainly includes the following steps:
when the server A1 is started, the IP port of A1 is registered with zk services zk providers according to the service name A.
When the server A2 is started, the IP port of A2 is registered with zk services providers zk providers according to the service name A.
When the client B is started, according to the service name a, subscribing events of different subscription services, which are also referred to as subscribing zk providers events in the embodiments of the present application, the zk providers event is used to publish a list of server IP ports that newly join or exit a certain subscription service.
The server A1 is online or offline, the client B subscribes and senses the latest server IP port list of the service name A through zk providers events, and meanwhile, the server IP port list is cached locally.
And when the client B calls the service according to the service name A, the client B inquires the normally called IP port of the service end in a polling mode through the IP port list of the cache service end to realize communication.
If zk elects the period or zk cluster down, the client B cannot sense the latest server a online and offline information, the cached IP port list of the service name a may be unavailable, and the high availability of the overall service depends on the high availability of zk cluster.
The high availability of the dubbo + zk micro-service of the related art depends on the robustness of the cluster server zk. When the zk master election period is too long or the cluster server zk is down for a long time, the client B cannot sense the latest online and offline information of the server a, and the cached IP port list of the service name a may be unavailable. Although the server calling is realized through the server IP port list caching mechanism, the problem caused by unavailability of the cluster server zk is relieved to a certain extent, the availability of the caching server IP port cannot be guaranteed, and when the server is frequently online or offline during zk master election or downtime, the overall service failure probability is greatly improved.
The embodiment of the application mainly aims at providing a server-side agent (independent process) and a client-side agent (jar) on a server side to make up the availability of zk service registration discovery during service failure caused by zk election or cluster downtime. The ISR (In-Sync replication) copy of the server agent provides the service registration discovery capability of online and offline of the server, and the client agent improves the normal efficiency of service access according to different state strategies. When the cluster server zk is recovered to normal, the ISR copy is updated again by taking the subscription events of different subscription services issued by the cluster server zk as a reference, and the ISR copy is consistent with the cluster server zk. Meanwhile, high coupling between the client and the cluster server is reduced, and the use of different service registration technologies for project migration is facilitated.
The embodiment of the application provides a service registration and subscription method, which is applied to a server-side agent communicated with a cluster server, a server and a client, wherein the server-side agent is arranged on the server side as an independent process and is an independent stateless background service, is arranged on the cluster server in a nearby clustering way, can be independently arranged outside the cluster server, can also be arranged with the cluster server in an integrated way, belongs to a process independent of the cluster server for providing micro-services, and is not influenced by election or downtime of the cluster server. The high availability of the server-side agent cluster is utilized to temporarily provide normal service discovery registration capability when zk is abnormal, and normal service capability can be provided for the client-side agent only by normally starting one server-side agent.
As shown in fig. 2, the service registration and subscription method provided by the embodiment of the present application includes:
step 201, receiving a registration request carrying a service name sent by a server and receiving a subscription request of a subscription service sent by a client;
the server-side proxy provides a part of routing-like functions, receives a registration request and a subscription request sent to the cluster server, wherein the registration request carries a service name and a server-side IP port, and the subscription request carries subscription service so as to request the server-side to provide the server-side IP port of the subscription service.
Step 202, when determining that a cluster server is normal, communicating with the cluster server to enable the cluster server to update a server IP port list of a corresponding service name and generate a subscription event of the subscription service;
in the embodiment of the application, the server-side agent is responsible for monitoring and determining the state of the cluster server, and is used for determining whether the cluster server is in a normal service state or in a zk election or downtime state. When the cluster server is in a normal state, the server-side proxy serves as a routing function, and sends the registration request to the cluster server, so that the cluster server updates a server-side IP port list corresponding to the service name according to the registration request, and sends the subscription request to the cluster server, so that the cluster server generates a subscription event corresponding to the subscription service according to the subscription request, wherein the subscription event comprises a server-side IP port corresponding to the subscription service.
Step 203, monitoring subscription events of different subscription services issued by the cluster server, and generating a copy synchronization queue ISR of the different subscription services by taking the subscription events of the different subscription services as a reference;
and the cluster server generates a subscription event and then routes the subscription event to the server-side proxy, and when the cluster server is in a normal state, the server-side proxy generates a copy synchronization queue ISR of different subscription services by taking the subscription event of the different subscription services as a reference, and keeps consistent with the cluster server.
The server-side agent is located on the server side and is responsible for realizing a routing function when the cluster server is normal, so that all subscription events issued by the cluster server can be received in a normal state, and the embodiment of the application can determine whether the cluster server is normal or not by monitoring the subscription events, and as an optional implementation mode, the following mode is adopted to monitor whether the cluster server is normal or abnormal:
monitoring subscription events of different subscription services published by a cluster server according to the publication frequency of the subscription events of the subscription services, wherein the cluster server publishes the subscription events at a certain publication frequency, and different subscription events can adopt different publication frequencies or the same publication frequency;
and when the subscription events of different subscription services are not monitored for the continuous set times, determining that the cluster server is abnormal, otherwise, determining that the cluster server is normal.
The cluster server does not publish any subscription event during election or downtime, so that the subscription event is not monitored at a plurality of continuous publishing occasions, and abnormal travel of the cluster server can be judged.
Step 204, when the cluster server is determined to be abnormal, sensing online and offline information of a server and updating copy synchronization queues ISR of different subscription services;
the server agent is located at the server side, can realize the communication with each server, as an optional implementation way, senses the online and offline information of the server and updates the copy synchronization queue ISR of different subscription services, including:
detecting whether different service terminals in ISRs of different subscription services are online or not through a heartbeat mechanism, determining all the service terminals according to the ISRs by a service terminal agent, performing heartbeat ping, finding that the service is still unavailable after a certain number of times of limitation, and judging that the service terminal is offline;
deleting the IP port corresponding to the offline server from the corresponding ISR;
and adding the IP port of the server side, which abnormally sends the registration request by the cluster server, to a copy synchronization queue ISR (Internet service register) corresponding to the subscription service.
Step 205, based on the copy synchronization queues ISR of the different subscription services, issuing a cluster server state and a server IP port list of the client subscription service.
The application mainly provides an availability technical scheme for making up zk service registration discovery based on proxy adaptation. The problem that the service is offline during the downtime of the zk cluster or the election period cannot be dynamically sensed is solved by developing a stateless server agent. The server agent subscribes all zk providers events, when the server agent monitors that the zk providers events are abnormal, heartbeat ping is carried out on all the server nodes in the ISR copy, the service is found to be still unavailable after a certain number of times of limitation, the service is judged to be offline, and meanwhile, the service is deleted from the ISR copy; when a new service is on-line through a certain server agent, zk abnormity is found, and a new service IP port is added to the ISR copy, so that the on-line and off-line conditions of the server can be sensed in time during zk election and downtime of the cluster server, and the ISR is updated to the client in time.
As a possible implementation manner, the server-side agent is multiple and stateless server-side agents, and each time the copy synchronization queue ISR is generated or updated, the method further includes:
and generating a globally unique and incrementally-increased identification ID bound with the copy synchronization queue ISR, broadcasting the copy synchronization queue ISR and the ID to other server-side agents when the cluster server is abnormal, so that the other server-side agents determine whether to update the local copy synchronization queue ISR according to the ID, the other server-side agents compare the size according to the local last globally unique ID, and if the ID-updated ISR determines that the service is updated, updating the ISR copy, thereby realizing the data consistency of the ISR copy.
As an optional implementation manner, based on the ISR, the sending a server IP port list of the client subscription service includes:
and when the cluster server is determined to be abnormal, based on the copy synchronization queues ISR of different subscription services, arranging the server IP ports of the subscription services according to the sequence of the registration time from late to early, and then issuing the server IP ports to the corresponding client, specifically, arranging the server IP ports of the same subscription service according to the sequence of the registration time from late to early.
The service end agent of the embodiment of the application establishes the corresponding ISR copy (arranged according to the service registration sequence) for each service name by using the ISR copy strategy. When zk providers event subscription is normal, informing the client of ISR copies (arranged according to service registration sequence); when the server agent finds that zk providers event subscription is abnormal, the client is notified of the ISR reverse order (the latest priority order of service registration), so that the reliability of providing the micro-service can be improved.
As shown in fig. 3, the flow implemented by the server agent during registration in the embodiment of the present application mainly includes:
and receiving a service registration request sent by a client agent, wherein the service registration request carries a service name and a server IP port.
Judging whether a cached ISR copy of the service name exists, if so, directly adding a service end IP port to update the ISR copy (the ISR copy: the service end IP port); and if not, establishing an ISR copy and adding a service end IP port.
And judging whether the zk providers event is normal or not to determine whether the cluster server is normal or not.
If the cluster server is determined to be normal, setting the state of the cluster server as 1: and normally, updating the ISR copy, communicating with the cluster server, and additionally registering a new server IP port through zkclient.
If the cluster server is determined to be abnormal, setting the state of the cluster server as-1: and if the abnormal condition is detected, updating the ISR copy, storing the ISR copy in a reverse order (latest priority) at the IP port of the service end, generating a global unique incremental ID, broadcasting the unique incremental ID and the ISR copy to other service end proxy nodes, comparing the size of the other nodes according to the local previous global unique ID, and updating the ISR copy if the new service update is found.
The client agents that have subscribed to the service are notified of the cluster server's status, the latest ISR copy.
As an optional implementation manner, after receiving a subscription request for subscribing to a service sent by a client, the method further includes:
determining whether a subscription is initiated to a cluster server for the subscription service before, if not, sending the subscription request to the cluster server so as to generate a server IP port list for the subscription service;
determining whether a subscription to the client agent is made, and if not, adding the client to the receiver of the subscription event of the subscription service.
The server-side agent realizes a routing function when the cluster server is normal during service registration and subscription, can update ISR copies in time when the cluster server is abnormal, and informs the client of detailed implementation processes given below.
As shown in fig. 4a, a flow implemented by the server proxy during subscription in the embodiment of the present application mainly includes:
and receiving a client proxy service subscription request, wherein the subscription request comprises a service name and an IP port of a subscription service.
And judging whether the service name is subscribed to zk providers or not, if not, communicating with the cluster server, and subscribing the zk providers of the service through a zk client.
And judging whether the service of the client agent is subscribed to zk providers of the service name or not, and if not, increasing the subscription event of the client agent to the service name.
As shown in fig. 4b, a process flow of the server agent receiving the subscription event notification in the embodiment of the present application is as follows:
and receiving a zk providers event notification, and judging whether the subscription is normal.
If the subscription event is published normally, determining that the cluster server is normal, and setting the cluster server state to 1: normally, determining a latest server IP port list to update a local ISR copy according to a subscription event issued by the cluster server, and notifying a client agent subscribed with the service of the state of the cluster server and the latest server IP port list;
if the subscription event is abnormal, determining that the cluster server is abnormal, and setting the state of the cluster server to-1: and if the abnormal condition exists, polling all service end nodes in the ISR copy to perform heartbeat ping, finding that the service is still not communicated after a certain number of times of limitation, judging that the service is offline, deleting the service from the ISR copy and storing the service in a reverse order.
And informing the client agent subscribed with the service of the state of the cluster server and the latest server IP port list.
In the embodiment of the application, the server-side agent heartbeat detection is added, and offline is judged if connection is not successful for a limited number of times. If the subscription event is normally published, setting the node to be offline through zkclient, and simultaneously setting the state to be 1: and normally, receiving the latest server IP port list to update the local ISR copy. If the subscription event is abnormally released, setting the state as-1: and (4) deleting the exception from the ISR copy, storing the exception in a reverse order, and broadcasting the exception to other server agent nodes.
Based on the same conception, the embodiment of the application provides a service registration and subscription method, which is applied to a client executed by a client agent, and is specifically provided for the client to load and use in a jar form, rather than a single process, the client obtains a service-dependent server IP port list through the client agent, and accesses the server through different state policies based on access times. And a second-level cache mechanism of the server-side proxy cache and the client-side proxy cache is realized, and the high availability of the service is improved.
As shown in fig. 5, the service registration and subscription method provided in the embodiment of the present application mainly includes:
step 501, sending a subscription request for subscribing service to a server proxy through a client proxy;
the subscription request includes a service name of the subscription service.
Step 502, receiving, by a client agent, a cluster server state sent by the server agent and a server IP port list of the subscription service;
step 503, polling the server IP ports in the server IP port list to normal access by using a corresponding policy according to the cluster server state through the client agent.
The cluster server state includes normal and abnormal, and thus polling is performed using different policies to provide reliability of the service.
In some possible embodiments, polling the server IP ports in the server IP port list by using a corresponding policy according to the cluster server state includes:
when the cluster server is determined to be in a normal state, performing polling access according to the server IP port priority determined according to the access times in the server IP port list of the subscription service, wherein the priority is higher when the access times are less;
and when the successful access to the IP port of the service end is determined, adding 1 to the access frequency of the IP port of the service end with the successful access.
In some possible embodiments, polling the server IP ports in the server IP port list by using a corresponding policy according to the cluster server state includes:
when the cluster server is determined to be abnormal, performing polling access according to the priority of the service end IP port determined according to the registration time in the service end IP port list of the subscription service, wherein the later the registration time, the higher the priority is;
and when the successful access to the IP port of the service end is determined, adding 1 to the access frequency of the IP port of the service end with the successful access.
As shown in fig. 6a, the process of the client agent initiating a request for subscribing to an event mainly includes:
acquiring a server proxy IP port list through the configured server proxy IP port configuration file;
and randomly acquiring a server proxy IP port, and polling the next node until normal access is realized if the access is abnormal.
A service registration request (service name, IP port) is initiated through the server proxy IP port.
A dependent service subscription request (dependent service name) is initiated through the server proxy IP port.
Fig. 6b shows a flow of executing service call by the client agent, which mainly includes:
and receiving a service end proxy service subscription event notification, acquiring the cluster server state and the server end IP port list, and updating the cluster server state and the server end IP port list to a local cache.
The client requests to access the server, and the client agent judges the mode of acquiring the IP port of the server through the state of the cluster server:
1) If the cluster server is in a normal state, the IP port of the service end with the minimum access frequency is returned and called by the client, and meanwhile, 1 is added to the access frequency of the IP port of the service end and the local cache is updated.
2) If the cluster server is abnormal, the first server IP port is returned and called by the client (the registration is latest and prior), and meanwhile, the access times of the server IP port are added by 1 and the local cache is updated.
If the access to the IP port of the service end is abnormal according to the mode, deleting the IP port of the service end from the local cache, and polling and processing the next IP port of the service end until the access is normal.
The application provides a technical scheme for normally providing latest service registration discovery capability through an ISR copy adapted by an agent under zk election and zk cluster long-time downtime, and improves the high availability of the whole service. Meanwhile, the coupling between the client and zk is reduced by using the server agent, the client does not sense the service registration discovery technology, and the project is convenient to migrate seamlessly and use the new service registration discovery technology.
Fig. 7 is a block diagram illustrating a cooperation implementation of a client agent and a server agent in the embodiment of the present application, and specific processes executed by the server agent and the client agent are described in the above embodiments and will not be repeated here.
Based on the same inventive concept, the present application further provides a service registration and subscription device, as a server agent, as shown in fig. 8, the device includes:
a request receiving module 801, configured to receive a registration request carrying a service name sent by a server and a subscription request for subscribing a service sent by a client;
a subscription update module 802, configured to communicate with a cluster server to update a server IP port list of a corresponding service name and generate a subscription event of the subscription service when it is determined that the cluster server is normal;
a duplicate generation module 803, configured to monitor subscription events of different subscription services published by the cluster server, and generate duplicate synchronization queues ISRs of the different subscription services based on the subscription events of the different subscription services;
a copy update module 804, configured to sense online and offline information of a server and update copy synchronization queues ISRs of different subscription services when determining that the cluster server is abnormal;
the replica synchronization module 805 is configured to issue a cluster server state and a server IP port list of a client subscription service based on the replica synchronization queues ISR of different subscription services.
In some possible embodiments, the cluster server is monitored for normality or abnormality in the following manner:
monitoring subscription events of different subscription services published by a cluster server according to the subscription event publishing frequency of the subscription services;
and when the subscription events of different subscription services are not monitored for the continuous set times, determining that the cluster server is abnormal, otherwise, determining that the cluster server is normal.
In some possible embodiments, the method for updating the copy synchronization queue ISR of the different subscription services includes:
detecting whether different service terminals in ISRs of different subscription services are online or not through a heartbeat mechanism;
deleting the IP port corresponding to the offline server from the corresponding ISR;
and adding the IP port of the server side, which abnormally sends the registration request by the cluster server, to a copy synchronization queue ISR (Internet service register) corresponding to the subscription service.
In some possible embodiments, the server-side agent is multiple and stateless server-side agents, further comprising:
and the ID updating module is used for generating a globally unique incremental identification ID bound with the copy synchronization queue ISR when the copy synchronization queue ISR is generated or updated every time, and broadcasting the copy synchronization queue ISR and the ID to other server-side agents when the cluster server is abnormal so that the other server-side agents determine whether to update the local copy synchronization queue ISR according to the ID.
In some possible embodiments, the copy synchronization module issues a server IP port list of the client subscription service based on the copy synchronization queue ISR of the different subscription services, including:
and when the cluster server is determined to be abnormal, based on the copy synchronization queues ISR of different subscription services, arranging the IP ports of the service ends of the subscription services in the order from late to early according to the registration time, and then issuing the IP ports to the corresponding client.
In some possible embodiments, after the request receiving module receives the subscription request for subscribing to the service sent by the client, the request receiving module is further configured to:
determining whether a subscription is initiated to a cluster server for the subscription service before, if not, sending the subscription request to the cluster server so as to generate a server IP port list for the subscription service;
determining whether a subscription to the client agent is made, and if not, adding the client to the receiver of the subscription event of the subscription service.
Based on the same inventive concept, the present application further provides a service registration and subscription device, as a client agent, as shown in fig. 9, the device includes:
a request receiving module 901, configured to send a subscription request for subscribing to a service to a server proxy through a client proxy;
a port determining module 902, configured to receive, by a client agent, a cluster server state sent by the server agent and a server IP port list of the subscription service;
and the port access module 903 is configured to poll, by the client proxy, the server IP ports in the server IP port list to normal access by using a corresponding policy according to the cluster server state.
In some possible embodiments, the polling, by the port access module, the server IP ports in the server IP port list by using a corresponding policy according to the cluster server state includes:
when the cluster server is determined to be in a normal state, performing polling access according to the server IP port priority determined according to the access times in the server IP port list of the subscription service, wherein the priority is higher when the access times are less;
and when the successful access to the IP port of the service end is determined, adding 1 to the access frequency of the IP port of the service end with the successful access.
In some possible embodiments, the polling, by the port access module, the server IP ports in the server IP port list by using a corresponding policy according to the cluster server state includes:
when the cluster server is determined to be abnormal, performing polling access according to the priority of the service end IP port determined according to the registration time in the service end IP port list of the subscription service, wherein the later the registration time, the higher the priority is;
and when the successful access to the IP port of the service end is determined, adding 1 to the access frequency of the IP port of the service end with the successful access.
After introducing the service registration and subscription method and apparatus according to an exemplary embodiment of the present application, a service registration and subscription device according to another exemplary embodiment of the present application is introduced next.
As will be appreciated by one skilled in the art, aspects of the present application may be embodied as a system, method or program product. Accordingly, various aspects of the present application may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.), or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
In some possible embodiments, a service registration and subscription device according to the present application may include at least one processor, and at least one memory. The memory stores program code, and when the program code is executed by the processor, the processor executes the steps of the service registration and subscription method executed by the server agent or the steps of the service registration and subscription method executed by the client agent according to various exemplary embodiments of the present application described above in this specification.
The service registration and subscription device 130 according to this embodiment of the present application is described below with reference to fig. 10. The service registration and subscription device 130 shown in fig. 10 is only an example, and should not bring any limitation to the function and use range of the embodiment of the present application.
As shown in fig. 10, the service registration and subscription device 130 is embodied in the form of a general-purpose electronic device. The components of the service registration and subscription device 130 may include, but are not limited to: the at least one processor 131, the at least one memory 132, and a bus 133 that connects the various system components (including the memory 132 and the processor 131).
Bus 133 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor, or a local bus using any of a variety of bus architectures.
The memory 132 may include readable media in the form of volatile memory, such as Random Access Memory (RAM) 1321 and/or cache memory 1322, and may further include Read Only Memory (ROM) 1323.
Memory 132 may also include programs/utilities 1325 having a set (at least one) of program modules 1324, such program modules 1324 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
The service registration and subscription device 130 may also communicate with one or more external devices 134 (e.g., keyboard, pointing device, etc.), with one or more devices that enable a user to interact with the service registration and subscription device 130, and/or with any device (e.g., router, modem, etc.) that enables the service registration and subscription device 130 to communicate with one or more other service registration and subscription devices. Such communication may occur through input/output (I/O) interfaces 135. Also, the service registration and subscription device 130 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet) via the network adapter 136. As shown, the network adapter 136 communicates with other modules for the service registration and subscription device 130 over a bus 133. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the service registration and subscription device 130, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
In some possible embodiments, aspects of a service registration and subscription method provided by the present application may also be implemented in the form of a program product, which includes program code for causing a computer device to perform the steps of a service registration and subscription according to various exemplary embodiments of the present application described above in this specification, when the program product is run on the computer device.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The program product for service registration and subscription of embodiments of the present application may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be executable on an electronic device. However, the program product of the present application is not limited thereto, and in this document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A readable signal medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the consumer electronic device, partly on the consumer electronic device, as a stand-alone software package, partly on the consumer electronic device and partly on a remote electronic device, or entirely on the remote electronic device or server. In the case of remote electronic devices, the remote electronic devices may be connected to the consumer electronic device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external electronic device (e.g., through the internet using an internet service provider).
It should be noted that although in the above detailed description several units or sub-units of the apparatus are mentioned, such a division is merely exemplary and not mandatory. Indeed, the features and functions of two or more units described above may be embodied in one unit, according to embodiments of the application. Conversely, the features and functions of one unit described above may be further divided into embodiments by a plurality of units.
Further, while the operations of the methods of the present application are depicted in the drawings in a particular order, this does not require or imply that these operations must be performed in this particular order, or that all of the illustrated operations must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and block diagrams, and combinations of flows and blocks in the flowchart illustrations and block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (12)

1. A service registration and subscription method is applied to a server proxy which is communicated with a cluster server, a server and a client, and is characterized by comprising the following steps:
receiving a registration request carrying a service name sent by a server side and a subscription request of subscription service sent by a client side;
when the cluster server is determined to be normal, communicating with the cluster server to enable the cluster server to update a server IP port list of a corresponding service name and generate a subscription event of the subscription service;
monitoring subscription events of different subscription services issued by a cluster server, and generating replica synchronization queues ISR of the different subscription services by taking the subscription events of the different subscription services as a reference;
when the cluster server is determined to be abnormal, sensing online and offline information of a server side and updating copy synchronization queues ISR of different subscription services;
and issuing the cluster server state and the server IP port list of the client subscription service based on the copy synchronization queue ISR of the different subscription services.
2. The method of claim 1, wherein the cluster server is monitored for normality or abnormality as follows:
monitoring subscription events of different subscription services published by a cluster server according to the subscription event publishing frequency of the subscription services;
and when the subscription events of different subscription services are not monitored for the continuous set times, determining that the cluster server is abnormal, otherwise, determining that the cluster server is normal.
3. The method of claim 1, wherein sensing online and offline information of a server and updating ISRs of replica synchronization queues of different subscribed services comprises:
detecting whether different service terminals in ISRs of different subscription services are online or not through a heartbeat mechanism;
deleting the IP port corresponding to the offline server from the corresponding ISR;
and adding the IP port of the server side, which abnormally sends the registration request by the cluster server, to a copy synchronization queue ISR (Internet service register) corresponding to the subscription service.
4. The method of claim 1, wherein the server-side agents are a plurality of stateless server-side agents, and each time a replica synchronization queue (ISR) is generated or updated, the method further comprises:
and generating a globally unique and incremental identification ID bound with the replica synchronization queue ISR, and broadcasting the replica synchronization queue ISR and the ID to other server-side agents when the cluster server is abnormal, so that the other server-side agents determine whether to update the local replica synchronization queue ISR according to the ID.
5. The method of claim 1, wherein issuing a list of server IP ports of a client subscription service based on the ISR, which is a replica synchronization queue of different subscription services, comprises:
and when the cluster server is determined to be abnormal, based on the copy synchronization queues ISR of different subscription services, arranging the IP ports of the service ends of the subscription services in the order from late to early according to the registration time, and then issuing the IP ports to the corresponding client.
6. The method according to any one of claims 1 to 5, wherein after receiving the subscription request for subscribing to the service sent by the client, the method further comprises:
determining whether a subscription is initiated to a cluster server aiming at the subscription service before, if not, sending the subscription request to the cluster server so as to generate a server IP port list for the subscription service;
determining whether a subscription to the client agent is made, and if not, adding the client to the receiver of the subscription event of the subscription service.
7. A service registration and subscription method is applied to a client and is characterized by comprising the following steps:
sending a subscription request for subscribing service to a server proxy through the client proxy;
receiving cluster server states sent by the server-side proxy and a server-side IP port list of the subscription service through a client-side proxy;
and polling the server IP ports in the server IP port list to normal access by adopting a corresponding strategy through the client agent according to the cluster server state.
8. The method of claim 7, wherein polling the server IP ports in the server IP port list using a corresponding policy according to the cluster server status comprises:
when the cluster server is determined to be in a normal state, performing polling access according to the priority of the server IP port determined according to the access times in the server IP port list of the subscription service, wherein the priority is higher when the access times are less;
and when the successful access to the IP port of the service end is determined, adding 1 to the access frequency of the IP port of the service end with the successful access.
9. The method of claim 7, wherein polling the server IP ports in the server IP port list using a corresponding policy according to the cluster server status comprises:
when the cluster server is determined to be abnormal, performing polling access according to the priority of the service end IP port determined according to the registration time in the service end IP port list of the subscription service, wherein the later the registration time, the higher the priority is;
and when the successful access to the IP port of the service end is determined, adding 1 to the access frequency of the IP port of the service end with the successful access.
10. A service registration and subscription apparatus, the apparatus comprising:
the request receiving module is used for receiving a registration request carrying a service name sent by a server and receiving a subscription request of subscription service sent by a client;
the subscription updating module is used for communicating with the cluster server to enable the cluster server to update a server IP port list of a corresponding service name and generate a subscription event of the subscription service when the cluster server is determined to be normal;
the system comprises a copy generation module, a synchronization queue management module and a synchronization queue management module, wherein the copy generation module is used for monitoring subscription events of different subscription services issued by a cluster server and generating copy synchronization queues ISR of the different subscription services by taking the subscription events of the different subscription services as a reference;
the system comprises a copy updating module, a synchronization queue updating module and a service module, wherein the copy updating module is used for sensing online and offline information of a server side and updating copy synchronization queues ISR of different subscription services when the cluster server is determined to be abnormal;
and the copy synchronization module is used for issuing a cluster server state and a server IP port list of the client subscription service based on the copy synchronization queues ISR of the different subscription services.
11. A service registration and subscription apparatus, the apparatus comprising:
the request receiving module is used for sending a subscription request of subscription service to the server proxy through the client proxy;
the port determining module is used for receiving the cluster server state sent by the server agent and the server IP port list of the subscription service through the client agent;
and the port access module is used for polling the server IP ports in the server IP port list to normal access by adopting a corresponding strategy according to the cluster server state through the client agent.
12. An apparatus for service registration and subscription, 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 or to perform the method of any one of claims 7-9.
CN202211006915.4A 2022-08-22 2022-08-22 Service registration and subscription method, device and equipment Pending CN115412562A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211006915.4A CN115412562A (en) 2022-08-22 2022-08-22 Service registration and subscription method, device and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211006915.4A CN115412562A (en) 2022-08-22 2022-08-22 Service registration and subscription method, device and equipment

Publications (1)

Publication Number Publication Date
CN115412562A true CN115412562A (en) 2022-11-29

Family

ID=84162273

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211006915.4A Pending CN115412562A (en) 2022-08-22 2022-08-22 Service registration and subscription method, device and equipment

Country Status (1)

Country Link
CN (1) CN115412562A (en)

Similar Documents

Publication Publication Date Title
US6438707B1 (en) Fault tolerant computer system
US6314512B1 (en) Automatic notification of connection or system failure in asynchronous multi-tiered system by monitoring connection status using connection objects
US8719386B2 (en) System and method for providing configuration synchronicity
US6986076B1 (en) Proactive method for ensuring availability in a clustered system
US9450700B1 (en) Efficient network fleet monitoring
US7518983B2 (en) Proxy response apparatus
CN110830283B (en) Fault detection method, device, equipment and system
EP1323040A2 (en) A system and method for managing clusters containing multiple nodes
CN106941420B (en) cluster application environment upgrading method and device
CN112217847A (en) Micro service platform, implementation method thereof, electronic device and storage medium
CN111835685A (en) Method and server for monitoring running state of Nginx network isolation space
CN113347037A (en) Data center access method and device
CN114531373A (en) Node state detection method, node state detection device, equipment and medium
CN112751916B (en) Data publishing-subscribing method and system for micro-service governance
US9973569B2 (en) System, method and computing apparatus to manage process in cloud infrastructure
US20040100971A1 (en) Communication system
CN115412562A (en) Service registration and subscription method, device and equipment
CN111309515A (en) Disaster recovery control method, device and system
CN114422335A (en) Communication method, communication device, server and storage medium
CN114816866A (en) Fault processing method and device, electronic equipment and storage medium
CN111338647A (en) Big data cluster management method and device
CN117221093A (en) Control method and device for distributed storage service
CN115102854B (en) Remote procedure call route management control method, system and equipment for micro-service
CN110932878A (en) Management method, equipment and system of distributed network
CN116455963A (en) Cluster node registration method, medium, device and computing 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