Method and system for managing third-party application by registryTechnical Field
The invention relates to the technical field of micro-service management, in particular to a method and a system for managing third-party application by a registration center.
Background
The registry is one of the core base services in the microservice architecture. In the architecture of micro-services, the number of services is large; and for high availability, many services are clustered; if the information of each service is maintained by using the traditional configuration mode, the difficulty of operation, maintenance, upgrading and management is greatly improved.
The registration center can uniformly manage service information, maintain the service state of each micro service, and provide mechanisms such as service registration, service discovery and the like. To provide services at a registry, service providers need to register for services. Common service registration modes include automatic registration and manual registration; auto-registration is when a service starts up, the service sends a message to the registry that the service is registered. Manual registration is through a command line or web manual registration service. For the third-party service, if the information of the third-party service is to be uniformly maintained by using a registry, manual registration is usually required; but there is not a good service drop and detection method.
Disclosure of Invention
The technical problem to be solved by the invention is to provide a method and a system for managing third-party application by a registry, which realize that the registry of a micro-service architecture provides service information of third-party service and automatically process service continuation, offline, forced online and forced offline of the third-party service.
The technical scheme for solving the technical problems is as follows:
the method comprises the steps of obtaining service information of a third-party service comprising a service address, a service port and a service name; then, sending a request for service registration to a registry; detecting the service state of the third-party service at regular time, and requesting service continuation or service offline from the registration center; and performing offline, forced online and logout on the third-party service through event monitoring and state pulling.
When the service state of the third-party service is detected regularly, if the third-party service can normally respond, a service renewal request is sent to the registration center, and the state of the third-party service is marked as Active in the cache; if the third-party service does not normally respond, marking the state of the third-party service as nonresponsive in the cache; if the third-party service does not normally respond for 3 times continuously, sending a service Offline request to a registration center, and marking the state of the third-party service as Offline in a cache;
the time interval of the service state clock timing of the timing detection third-party service is one third of the heartbeat timeout time configured by the registration center.
The event monitoring is a listener for registering a service event to a registration center, and the type of the received third-party service event is judged; triggering a corresponding processing flow of the third-party service according to the judged type; the types comprise offline, forced online and logout.
The state pulling is to regularly acquire a service list of the registration center; triggering a corresponding processing flow of the third-party service according to the acquired service state type, wherein the service state type comprises offline, forced offline and forced online; and if the third-party service exists in the cache but does not exist in the registration center, triggering a logout processing flow of the third-party service.
The Offline processing of the third-party service is to judge the state of the service in the cache, and if the state is NonResponsible, the state of the service is marked as Offline in the cache;
the forced offline processing of the third-party service is to judge the state of the service in the cache, if the state is not OutOfService, the state of the service is marked as OutOfService in the cache, and the service state timing detection of the service is stopped;
the forced online processing of the third-party service is to judge the state of the service in the cache, mark the state of the service in the cache as offservice if the state is OutOfService, and recover the service state timing detection of the service;
the third-party service logout processing is to cancel the service state timing detection of the service and delete the record of the service in the cache.
The system comprises a third-party service agent, wherein the third-party service agent is responsible for communicating with a registration center and detecting the service state of the third-party service at regular time, so that service registration, offline forced offline, online forced and logout of the third-party service are realized;
the third-party service agent specifically comprises a third-party service registration module, a third-party service state detection module, a state management module and a cache module;
the third-party service registration module is responsible for receiving service information of third-party services, including service addresses, service ports and service names, and sending a service registration request to a registration center;
the third-party service state detection module detects the service availability of the third-party service at regular time and performs service renewal or service offline to a registration center;
the state management module registers a service event listener with the registration center and compares the service states of the third-party service in the registration center and the cache; performing offline, forced online and logout processing on the third-party service;
the cache module stores the service information and the state of the third-party service.
The invention can provide the service information of the third-party service in the registration center under the condition of not changing the third-party service and the registration center, automatically process the service continuation, the off-line, the forced on-line and the forced off-line of the third-party service, does not change the registration center and the third-party service, and is suitable for the old system or the third-party service to access the registration center.
Drawings
The invention is further described below with reference to the accompanying drawings:
FIG. 1 is a flow chart of the method of the present invention;
fig. 2 is a block diagram of the present invention.
Detailed Description
As shown in fig. 1, the method for managing the third party service by the registry of the present invention has the following processes:
s1, acquiring service information of the third-party service, including a service address, a service port, a service name and the like;
s2, sending a service registration request to a registration center;
s3, detecting the service state of the third-party service at regular time, and continuing service contract or taking off the service line to the registration center;
and S4, performing processing flows of offline, forced online, logout and the like on the third-party service through event monitoring and state pulling.
In step S3, the periodically detecting the service status of the third-party service further includes:
if the third-party service can normally respond, sending a service renewal request to the registration center, and marking the state of the third-party service as Active in the cache;
if the third-party service does not normally respond, marking the state of the third-party service as nonresponsive in the cache;
and if the third-party service does not normally respond for 3 times continuously, sending a service Offline request to the registration center, and marking the state of the third-party service as Offline in the cache.
The service state of the third-party service is detected at the timing, and the time interval of the timing is equal to the heartbeat timeout time configured by the registration center divided by 3.
In step S4, the event listening further includes:
1) registering a listener of a service event with a registry;
2) receiving a service event, and if the service event is not a third-party service, ignoring the service event;
3) and judging the event type, and triggering the processing flows of offline, forced online, logout and the like of the third-party service if the event is an event of offline, forced online, logout and the like.
In step S4, the state pull further includes:
1) acquiring a service list of a registration center at regular time;
2) for the third-party service, if the service state is offline, forced online and the like, triggering the processing flows of the third-party service such as offline, forced online, logout and the like;
3) and comparing the service list of the registration center with the cached service list, and if the third-party service exists in the cache and does not exist in the registration center, triggering a logout processing flow of the third-party service.
The third-party service downloading process comprises the following steps: and judging the state of the service in the cache, and if the state is NonResponsible, marking the state of the service as Offline in the cache.
The forced offline flow of the third-party service is as follows: the state of the service in the cache is determined. If the service is not OutOfService, the state of the service is marked as OutOfService in the cache, and the service state timing detection of the service is stopped.
The forced online process of the third-party service comprises the following steps: the state of the service in the cache is determined. If the service is OutOfService, the state of the service is marked Offline in the cache, and the service state timing detection of the service is recovered.
The logout flow of the third-party service is as follows: and canceling the service state timing detection of the service and deleting the record of the service in the cache.
As shown in fig. 2, the system for managing the third-party service by the registry of the present invention includes a third-party service agent, which is responsible for communicating with the registry and detecting the service status of the third-party service at regular time, so as to realize the functions of service registration, service renewal, service offline, etc. of the third-party service. The third-party service agent specifically includes:
the third-party service registration module is responsible for receiving service information of the third-party service, including a service address, a service port, a service name and the like, and sending a service registration request to the registration center;
the third-party service state detection module is used for detecting the service availability of the third-party service at regular time and performing service renewal or service offline to the registration center;
the state management module is used for performing processing flows of offline, forced online, logout and the like on the third-party service by registering the service event listener in the registration center and comparing the service states of the third-party service in the registration center and the cache;
and the cache module is used for storing the service information and the state of the third-party service.
In the invention, the service provider and the service consumer directly communicate with the registry, and a method for integrating the third-party service into the registry is provided for the service consumer to directly consume, and the state maintenance and management are carried out on the third-party service.