CN116974791A - Method and device for connecting micro-service to and from line - Google Patents

Method and device for connecting micro-service to and from line Download PDF

Info

Publication number
CN116974791A
CN116974791A CN202310961922.8A CN202310961922A CN116974791A CN 116974791 A CN116974791 A CN 116974791A CN 202310961922 A CN202310961922 A CN 202310961922A CN 116974791 A CN116974791 A CN 116974791A
Authority
CN
China
Prior art keywords
service
micro
offline
node
intermediate component
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
CN202310961922.8A
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.)
Chongqing Seres New Energy Automobile Design Institute Co Ltd
Original Assignee
Chongqing Seres New Energy Automobile Design Institute 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 Chongqing Seres New Energy Automobile Design Institute Co Ltd filed Critical Chongqing Seres New Energy Automobile Design Institute Co Ltd
Priority to CN202310961922.8A priority Critical patent/CN116974791A/en
Publication of CN116974791A publication Critical patent/CN116974791A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/544Remote

Abstract

The application relates to the technical field of computer communication, and provides a method, a device, electronic equipment and a computer readable storage medium for connecting a micro service to a line. According to the method, in the process of uploading and downloading the micro-service by the user center service cluster, the intermediate component is utilized, so that the application background service can be directly informed of node information of the node corresponding to the micro-service to be offline, and the node information is deleted from the service node set of the application background service without waiting. Thus, the method provided by the embodiment can avoid the problems of stuck state, long response time and easy error reporting in the micro-service online and offline process, thereby realizing stable online and offline of the micro-service and further improving the user experience.

Description

Method and device for connecting micro-service to and from line
Technical Field
The present application relates to the field of computer communications technologies, and in particular, to a method and apparatus for connecting a micro-service to a line, an electronic device, and a computer readable storage medium.
Background
Micro-services are a variant of the software development technology-Service Oriented Architecture (SOA) architecture style, which advocates the division of a single application into a small set of services, which are coordinated and matched with each other, providing the final value for users. Each service runs in an independent process, and the service communicate with each other by adopting a lightweight communication mechanism. Each service is built around a specific business and can be deployed independently to a production environment, class production environment, etc.
In the prior art, in the process of connecting a micro service to and disconnecting a micro service, when a node of the micro service is disconnected, the service registration center cannot immediately sense the node, and the service registration center senses the node through heartbeat detection, and the higher the heartbeat detection time interval is, the longer the delay is (for example, the common detection is performed for 5 seconds, three times of continuous failures are used for considering that the node is unhealthy, and the delay reaches 15 seconds). However, the heartbeat detection time cannot be too short, otherwise, the request amount of the service registration center and the service node is too large, and the normal operation of the micro service is affected. In addition, the service registry perceives that a node of a certain micro service is unhealthy, and needs to update the list information of the service nodes of the user center and inform the client of the service registry; after receiving the change request, the service registry client needs to update the user center node service list information in the local variable node set of the service registry client; the load balancing component synchronizes the data through the local variable node of the service registry client by periodically timing the task, and it should be emphasized that when the task synchronization frequency is too high, the service performance of the micro service is seriously affected, and if the task synchronization period is 30 seconds, the service performance of the micro service is seriously affected. Through the steps, when the operation and maintenance personnel stop the service of the old node by the user center, the load balancer component senses that the change is needed for 45 seconds at maximum, and if a great number of users request the old node, a great number of errors are reported when the load balancer initiates the request call. Therefore, in the micro service online-offline process in the prior art, there are problems that a card is easy to be on, a response time is long, and a report error is easy to occur, so that user experience is affected, and a new micro service online-offline method is needed.
Disclosure of Invention
In view of the above, embodiments of the present application provide a method, an apparatus, an electronic device, and a computer readable storage medium for online and offline of a micro service, so as to solve the problems of easy occurrence of a card, long response time, and easy occurrence of a report error in the online and offline process of the micro service in the prior art.
In a first aspect of an embodiment of the present application, a method for providing a microservice online/offline is provided, including:
the user center service cluster acquires a micro-service to be online and a micro-service to be offline;
the user center service cluster sets the node corresponding to the micro-service to be on line, sets the node corresponding to the micro-service to be off line, and sends node information of the node corresponding to the micro-service to be off line to an intermediate component;
the intermediate component sends node information of the node corresponding to the micro service to be offline to an application background service;
the application background service deletes node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service, and sends a service disconnection completion message to the intermediate component;
And after receiving the service offline completion message, the intermediate component sends a service offline message to the user center service cluster, so that the user center service cluster responds to the service offline message to set the node corresponding to the micro-service to be offline to be in an offline state.
In a second aspect of the embodiment of the present application, there is provided an apparatus for connecting a micro service to a line, including:
the acquisition module is configured to control the user center service cluster to acquire the to-be-online micro-service and the to-be-offline micro-service;
the processing module is configured to control the user center service cluster to set the node corresponding to the micro-service to be on line, set the node corresponding to the micro-service to be off line, and send the node information of the node corresponding to the micro-service to be off line to an intermediate component;
the sending module is configured to control the intermediate component to send the node information of the node corresponding to the micro service to be disconnected to an application background service;
the configuration module is configured to control the application background service to delete node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service and send a service disconnection completion message to the intermediate component;
And the off-line module is configured to send a service off-line message to the user center service cluster after the intermediate component receives the service off-line completion message, so that the user center service cluster responds to the service off-line message to set the node corresponding to the micro-service to be off-line to be in the off-line state.
In a third aspect of the embodiments of the present application, there is provided an electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the above method when executing the computer program.
In a fourth aspect of the embodiments of the present application, there is provided a computer readable storage medium storing a computer program which, when executed by a processor, implements the steps of the above method.
Compared with the prior art, the embodiment of the application has the beneficial effects that: after the user center service cluster obtains the micro service to be online and the micro service to be offline, the user center service cluster can set the node corresponding to the micro service to be online, set the node corresponding to the micro service to be offline, and send the node information of the node corresponding to the micro service to be offline to the intermediate component. And then, the intermediate component can send the node information of the node corresponding to the to-be-off-line micro-service to an application background service. And then, the application background service deletes the node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service, and sends a service disconnection completion message to the intermediate component. And then, after receiving the service offline completion message, the intermediate component sends a service offline message to the user center service cluster. Finally, the user center service cluster may set the node corresponding to the micro-service to be offline to an offline state in response to the service offline message. Therefore, in this embodiment, in the process of loading and unloading the micro-service from the user center service cluster by using the intermediate component, the application background service can be directly notified to delete the node information of the node corresponding to the micro-service to be unloaded from the service node set of the application background service without waiting. Thus, the method provided by the embodiment can avoid the problems of stuck state, long response time and easy error reporting in the micro-service online and offline process, thereby realizing stable online and offline of the micro-service and further improving the user experience.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic view of an application scenario according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating a method for provisioning and offline of a micro-service according to an embodiment of the present application;
FIG. 3 is a system diagram of a method for providing a micro-service online and offline according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an apparatus for providing a micro service for online and offline according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth such as the particular system architecture, techniques, etc., in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
A test method and apparatus according to embodiments of the present application will be described in detail with reference to the accompanying drawings.
Fig. 1 is a schematic view of an application scenario according to an embodiment of the present application. The application scenario may include terminal devices 1, 2 and 3, a server 4 and a network 5.
The terminal devices 1, 2 and 3 may be hardware or software. When the terminal devices 1, 2 and 3 are hardware, they may be various electronic devices having a display screen and supporting communication with the server 4, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like; when the terminal apparatuses 1, 2, and 3 are software, they may be installed in the electronic apparatus as described above. The terminal devices 1, 2 and 3 may be implemented as a plurality of software or software modules, or as a single software or software module, to which the embodiments of the present application are not limited. Further, various applications, such as a data processing application, an instant messaging tool, social platform software, a search class application, a shopping class application, and the like, may be installed on the terminal devices 1, 2, and 3.
The server 4 may be a server that provides various services, for example, a background server that receives a request transmitted from a terminal device with which communication connection is established, and the background server may perform processing such as receiving and analyzing the request transmitted from the terminal device and generate a processing result. The server 4 may be a server, a server cluster formed by a plurality of servers, or a cloud computing service center, which is not limited in this embodiment of the present application.
The server 4 may be hardware or software. When the server 4 is hardware, it may be various electronic devices that provide various services to the terminal devices 1, 2, and 3. When the server 4 is software, it may be a plurality of software or software modules providing various services to the terminal devices 1, 2 and 3, or may be a single software or software module providing various services to the terminal devices 1, 2 and 3, to which the embodiment of the present application is not limited.
The network 5 may be a wired network using coaxial cable, twisted pair wire, and optical fiber connection, or may be a wireless network that can implement interconnection of various communication devices without wiring, for example, bluetooth (Bluetooth), near field communication (Near Field Communication, NFC), infrared (Infrared), etc., which is not limited in the embodiment of the present application.
The user can establish a communication connection with the server 4 via the network 5 through the terminal devices 1, 2, and 3 to receive or transmit information or the like. Specifically, when the user needs to perform the micro-service online-offline, the micro-service online-offline instruction may be output to the terminal devices 1, 2 and 3, where the micro-service online-offline instruction may include the micro-service to be online and the micro-service to be offline, and the terminal devices 1, 2 and 3 may send the micro-service online-offline instruction to the server 4. After the server 4 obtains the micro-service online and offline instruction, the server 4 may control the user center service cluster to obtain the micro-service to be online and the micro-service to be offline. Then, the server 4 may control the user center service cluster to set the node corresponding to the micro service to be online to be in an online state, set the node corresponding to the micro service to be offline to be in an offline state, and send the node information of the node corresponding to the micro service to be offline to an intermediate component. Then, the server 4 may control the intermediate component to send the node information of the node corresponding to the to-be-offline micro service to an application background service. Then, the server 4 may control the application background service to delete the node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service, and send a service disconnection completion message to the intermediate component. Finally, the server 4 may control the intermediate component to send a service offline message to the user center service cluster after receiving the service offline completion message, so that the user center service cluster sets the node corresponding to the micro-service to be offline to the offline state in response to the service offline message. In this way, in the process of uploading and downloading the micro-service to and from the user center service cluster by using the intermediate component, the embodiment can directly inform the application background service of deleting the node information of the node corresponding to the micro-service to be offline from the service node set of the application background service without waiting. Thus, the method provided by the embodiment can avoid the problems of stuck state, long response time and easy error reporting in the process of the micro-service online and offline, thereby realizing the stable online and offline of the micro-service, improving the fault tolerance, reducing the system coupling and further improving the user experience.
It should be noted that the specific types, numbers and combinations of the terminal devices 1, 2 and 3, the server 4 and the network 5 may be adjusted according to the actual requirements of the application scenario, which is not limited in the embodiment of the present application.
Fig. 2 is a flow chart of a method for connecting a micro-service to a line according to an embodiment of the present application. The method of micro service up-down of fig. 2 may be performed by the server of fig. 1, and in particular, the method may be performed by the corresponding system of fig. 3. As shown in fig. 2, the method for connecting the micro service to the line may include:
s201, a user center service cluster acquires a micro-service to be online and a micro-service to be offline.
The micro-service to be online may be understood as a micro-service to be online, and the micro-service to be offline may be understood as a micro-service to be offline. In this embodiment, an operator may serve the service information of the to-be-online micro-service and the to-be-offline micro-service to the user center, where the service information of the to-be-online micro-service may include a service name of the to-be-online micro-service and node information of a node corresponding to the to-be-online service, and the service information of the to-be-offline micro-service may include a service name of the to-be-offline micro-service and node information of a node corresponding to the to-be-offline service. It should be noted that, all the nodes corresponding to the online micro services are deployed in the user center service cluster.
S202, the user center service cluster sets the node corresponding to the micro-service to be on line, sets the node corresponding to the micro-service to be off line, and sends node information of the node corresponding to the micro-service to be off line to an intermediate component.
In this embodiment, after receiving the micro service to be online and the micro service to be offline, the user center service cluster sets the node corresponding to the micro service to be online, and sets the node corresponding to the micro service to be offline. When the node of the micro service is in the on-line state, the micro service is indicated to be on-line, and the application client can access the node of the micro service; when the node of the micro service is in the off-line state, the micro service is still in the on-line state, and the application client can access the node of the micro service, but the micro service is off-line.
After the node corresponding to the micro-service to be offline is set to be in the offline state, the user center service cluster can send node information of the node corresponding to the micro-service to be offline to the intermediate component. It should be noted that, the micro service to be offline may be correspondingly provided with at least one node, and each node is different; the node information of the node may be understood as attribute information of the node, for example, the node information of the node may include a service name (such as order service) of a micro service corresponding to the node, an IP address corresponding to the node, port information corresponding to the node, and the like.
It should be noted that an intermediate component may be understood as a component for providing synchronous or asynchronous message transmission for a system. For example, the intermediate component may be a kafka component or a communication component http protocol. In one implementation manner, if the intermediate component is a kafka component, the node information of the node corresponding to the micro-service to be disconnected may include a service name of the micro-service and an IP address of the node; if the intermediate component is a communication component http protocol, the node information of the node corresponding to the to-be-off-line micro-service may include a service name of the micro-service, an IP address of the node, and port information of the node. It should be noted that, when the number of service subscription objects of one micro service is numerous, for example, hundreds to thousands, the intermediate component may use the kafka component; because the directly newly-built thread synchronously calls through http, the service subscription objects are notified of the long waiting time of the whole offline, and therefore, when the number of the service subscription objects of one micro service is less than one hundred, the intermediate component can use the http protocol of the communication component.
And S203, the intermediate component sends the node information of the node corresponding to the micro service to be disconnected to an application background service.
In this embodiment, after the intermediate component obtains node information of a node corresponding to a micro-service to be offline sent by the user center service cluster, the intermediate component sends the node information of the node corresponding to the micro-service to be offline to the application background service, so that the application background service can be used for downloading the node corresponding to the micro-service to be offline.
In an implementation manner, the intermediate component sends the node information of the node corresponding to the to-be-offline micro service to an application background service, which specifically includes the following steps:
s203a: and the intermediate component acquires attribute information of the service subscription object corresponding to the micro-service to be offline.
In this embodiment, the intermediate component may first obtain a list of service subscription objects corresponding to the to-be-offline micro-service, and attribute information of each service subscription object in the list. Wherein the attribute information of the service subscription object may include a name identifier and an IP address of the service subscription object.
As an example, the intermediate component may obtain the attribute information of the service subscription object corresponding to the micro-service to be offline by calling a service registry client in the application background service. It should be noted that, when a micro service is subscribed by a service subscription object, a service registry client in an application background service records attribute information of the service subscription object subscribed by the micro service, so that an intermediate component can query, by using a service name of a to-be-offline service, attribute information of the service subscription object corresponding to the to-be-offline micro service by calling the service registry client in the application background service, that is, acquire attribute information of the service subscription object corresponding to the to-be-offline micro service.
S203b: and the intermediate component sends node information of the node corresponding to the micro-service to be offline to the service subscription object according to the attribute information of the service subscription object.
After the intermediate component acquires the attribute information of the service subscription object corresponding to the service to be offline, the intermediate component can locate the service subscription object according to the attribute information of the service subscription object and establish connection with the service subscription object, so that the intermediate component can send the node information of the node corresponding to the micro service to be offline to the service subscription object. It is understood that the service subscription object of the micro-service may comprise a number of objects, wherein the service subscription object comprises at least the application background service.
In one implementation manner, if the intermediate component is a kafka component, the attribute information of the service subscription object corresponding to the to-be-offline micro-service may include an object name and an IP address of the service subscription object. Specifically, the intermediate component may first create a first topic task, for example, a first topic task topic may be defined in the kafka component, such as topic being: service_offline_topic (service offline to complete topic); it should be noted that the first theme task may be set according to actual situations. And then, the intermediate component can generate a task message corresponding to the service subscription object according to the attribute information of the service subscription object and the node information of the node corresponding to the micro-service to be offline, and store the task message into the first theme task. For example, the intermediate component may encapsulate node information of the node to be disconnected from the micro service (e.g., IP address of the node, service name of the micro service, and disconnection flag) and attribute information of each service subscription object (e.g., IP address of the service subscription object, service name of the service subscription object) into a task message, for example, if there are 10 service subscription objects, then 10 task messages are to be encapsulated, and store the IP address of the service subscription object and the micro service disconnection state into a subscription object Map set, where key in the subscription object Map set is IP, value is whether the subscriber has completed the disconnection state, and initialization is incomplete by default; then, the encapsulated task message and the subscription object Map set are stored into a first theme task (namely, a task of which the service is to be completed in an offline manner) and the kafka component is called to issue the task message, namely, the first theme task is executed, specifically: the kafka component stores the encapsulated task message to the already defined topic as: service_offline_topic (service down-line to complete topic) task. Then, the intermediate component can send the node information of the node corresponding to the micro-service to be offline in the task message to the service subscription object according to the attribute information in the task message; for example, the kafka component may notify the service subscription object corresponding to the service to be offline in a broadcast manner of the task message, so that the service subscription object corresponding to the service to be offline may determine whether the micro-service offline operation is required according to attribute information (e.g., an IP address of the service subscription object, a service name of the service subscription object) in the broadcast task information.
In another implementation manner, if the intermediate component is a communication component http protocol, the attribute information of the service subscription object corresponding to the to-be-offline micro-service may include an object name, an IP address, and port information of the service subscription object. Specifically, the intermediate component may determine, according to the object name, the IP address, and the port information of the service subscription object, a subscriber service receiving interface corresponding to the service subscription object. And then, the intermediate component sends the node information of the node corresponding to the micro service to be disconnected to a subscriber service receiving interface corresponding to the service subscription object. For example, the communication component http protocol may write a service provider logoff interface (e.g., http: 127.0.0.1:9527/down), the communication component http protocol may utilize the logoff interface to round the service subscription object corresponding to the to-be-offline micro-service according to the object name, the IP address and the port information of the service subscription object, and the communication component http protocol may send the node information of the node corresponding to the to-be-offline micro-service to the subscriber service receiving interface corresponding to the service subscription object.
S204, the application background service deletes the node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service, and sends a service disconnection completion message to the intermediate component.
In this embodiment, the application background service may first receive node information of a node corresponding to the to-be-offline micro-service. And then, the application background service can update the locally stored service node set of the application background service by utilizing the node information of the node corresponding to the micro service to be offline, namely, delete the locally stored service node set of the application background service, so that the application background service finishes the offline operation of the micro service to be offline, and further, the application background service can send a service offline completion message to the intermediate component.
In one implementation, as shown in fig. 3, the application background service may include: the load balancer component and the service registry client. The load balancing component is mainly used for formulating some strategies, such as random, weight and polling strategies, and aims at selecting one node from a plurality of nodes of the user center service cluster and then initiating a request to the node; the service registration center client is mainly used for being responsible for communication with the user center service cluster, for example, micro services in the user center service cluster are changed, and the service registration center client actively initiates the function of inquiring service node list information in the user center service cluster to the user center service cluster.
The application background service deletes node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service, and sends a service disconnection completion message to the intermediate component, which may include the following steps:
s204a, the application background service deletes the node information of the node corresponding to the micro-service to be offline from the service node set of the load balancer component, and deletes the node information of the node corresponding to the micro-service to be offline from the service node set of the service registry client;
and S204b, the application background service sends a service offline completion message to the intermediate component.
It should be noted that, the load balancer component and the local of the service registry client are both pre-stored with a service node set, where the service node set is used to record the node corresponding to the online micro service in the service cluster of the user center. Specifically, the application background service may first invoke the cloud platform service registry to obtain node information of the nodes of the micro service in the user center service cluster (i.e., the latest list information of the user center nodes), and then update, by using the application background service, a service node set local to the client of the service registry in a reflection manner, and update, by using the application background service, a service node set local to the load balancer component in a reflection manner. As an example, a service registry client may obtain node information of nodes of micro services in a user center service cluster by invoking a cloud platform service registry, and store the obtained node information of the nodes of the micro services into a service node set local to the service registry client; next, the load balancer component reads the service node set local to the service registry client, and stores data in the service node set local to the service registry client into the service node set local to the load balancer component, so that node information (i.e., user center node latest list information) of the micro-service nodes in the user center service cluster is also stored in the service node set local to the load balancer component. The cloud platform service registry is mainly used for storing information (such as service names, IP addresses, ports and the like) of a plurality of nodes deployed by the user center service cluster, and judging which node data needs to be read after an app instruction is acquired.
In this embodiment, the application background service may delete node information of a node corresponding to the to-be-offline micro-service in the service node set of the load balancer component, and delete node information of a node corresponding to the to-be-offline micro-service in the service node set of the to-be-offline micro-service.
In one implementation, assuming that the intermediate component is a kafka component, the application background service may newly write a subscriber list to receive the kafka message interface, monitor a topic message (i.e. a task message) of a first theme task of kafka, and after the application background service receives the task message, the application background service may remove an IP (i.e. node information of a node corresponding to a micro service to be disconnected) of a service provider by determining whether the subscriber list IP in the task message includes the application background service, that is, whether attribute information of a service subscription object includes the application background service, and if so, the application background service may immediately acquire a service registry client local variable map (i.e. a service node set), and load balancing component local variable map (i.e. a service node set). After the removal is completed, the application background service may send a service offline completion message to the intermediate component.
In one implementation, assuming that the intermediate component is a communication component http protocol, the communication component http protocol may write a subscriber service receiving interface (updateService) for receiving task messages of the first task topic. The http protocol of the communication component receives the task message of the first task body through the subscriber service receiving interface, and removes the IP of the service provider to be disconnected (namely, the node information of the node corresponding to the micro-service to be disconnected) from the service registry client and the map (namely, the service node set) in the load balancing component according to the task message. After the removal is completed, the application background service may send a service offline completion message to the intermediate component.
In this way, the load balancing component and the service registry client component can realize data update (i.e. service node set update) in the same frequency, so that the function of further improving smooth online and offline of the micro service can be achieved, the performance can not be lost, and smooth online and offline of the micro service can be further guaranteed.
And S205, after receiving the service offline completion message, the intermediate component sends a service offline message to the user center service cluster, so that the user center service cluster responds to the service offline message to set the node corresponding to the micro-service to be offline to be in an offline state.
In this embodiment, after receiving the service offline completion message, the intermediate component may send a service offline message to the user center service cluster, so as to notify the user center service cluster that the node to be offline for the micro service may be offline. As an example, the intermediate component may periodically confirm whether a service offline completion message sent by all service subscription objects corresponding to the micro-service to be offline is received, and if the intermediate component receives the service offline completion message sent by all service subscription objects corresponding to the micro-service to be offline, send a service offline message to the user center service cluster; it should be noted that, the period time for the intermediate component to confirm whether the service offline completion message sent by all the service subscription objects corresponding to the to-be-offline micro-service is received may be set according to the actual situation. For example, the intermediate component may poll every 100 ms whether all service subscription objects in the subscription object Map set have completed the offline, that is, the value in the subscription object Map set is updated, and if all service offline completion messages sent by all service subscription objects corresponding to the to-be-offline micro-service are received within a specified timeout period of 5 (seconds), return a service offline message to the user center service cluster.
In one implementation, if the intermediate component is a kafka component, the intermediate component may first create a second theme task, e.g., topic (service_offline_finish_topic); the second theme task comprises attribute information of a service subscription object corresponding to the micro service to be offline and a service offline identifier; it should be noted that the second theme task may be set according to actual situations. And if the intermediate component receives a service offline completion message sent by a service subscription object corresponding to the micro-service to be offline, the intermediate component can change the service offline identifier corresponding to the attribute information of the service subscription object in the second theme task into the completed offline according to the attribute information of the service subscription object. And if all the service offline identifiers in the second theme task are offline completed, the intermediate component sends a service offline message to the user center service cluster.
In another implementation manner, if the intermediate component is a communication component http protocol, the user center service cluster notifies the application background service to update local aggregate data according to attribute information (for example, an object name, an IP address and port information of the service subscription object) of the service subscription object through the communication component http protocol, and traverses the service subscription object to complete the micro-service offline action. For example, the step sdk of realizing service stability is directly invoked by http:
1. Introducing a registry client component and a load balancing component through newly-built springBoot engineering projects.
2. Writing a subscriber service receiving interface (/ updateService);
2.1, interface parameters: service name + IP of service provider offline;
2.2, receiving the request, and removing the IP of the service provider about to be off line from the registry client component and the load balancing component map according to the service name;
2.3, updating is completed and an updating result is returned;
3. writing a service provider logoff interface (http: 127.0.0.1:9527/down);
3.1, calling a service registry client sdk to log off the service needing to be offline from the registry;
3.2, receiving a service offline request, and acquiring subscriber list information (IP+ port) of the service from a service registry according to the current service name;
and 3.3, training the subscriber list, directly initiating calling by the parameter transmitted into the service name+IP of the service provider downlink through the IP+port+/updateService of the subscriber, and interfacing in the step 2.
It should be noted that, in an implementation manner, the method of the embodiment corresponding to fig. 2 may be packaged in a sdk package, so that the service of each item is introduced into the sdk package, and the stable on-line and off-line of the micro-service can be completed, thereby improving the convenience of the on-line and off-line of the micro-service.
It should be noted that if the same type of service registry client component and the same type of load balancer component are adopted for each item, the item is directly introduced into the sdk package. If a different type of service registry client component or a different type of load balancer component is adopted, it needs to check whether the service registry client component has locally cached node information of nodes in the user center service cluster, and if so, the load balancer component can directly update the sdk packet.
It should be noted that, if the service provider does not receive the message through the sdk packet and the service is not reported by the subscription or the kafka message is delayed at the specified time, the service list data frequency of the cloud platform service registry can be adjusted by synchronizing the load balancer component and the service registry client component, for example, the default 30 seconds is changed to the default 5 seconds for synchronizing once by the default load balancer component and the service registry client component.
Compared with the prior art, the embodiment of the application has the beneficial effects that: after the user center service cluster obtains the micro service to be online and the micro service to be offline, the user center service cluster can set the node corresponding to the micro service to be online, set the node corresponding to the micro service to be offline, and send the node information of the node corresponding to the micro service to be offline to the intermediate component. And then, the intermediate component can send the node information of the node corresponding to the to-be-off-line micro-service to an application background service. And then, the application background service deletes the node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service, and sends a service disconnection completion message to the intermediate component. And then, after receiving the service offline completion message, the intermediate component sends a service offline message to the user center service cluster. Finally, the user center service cluster may set the node corresponding to the micro-service to be offline to an offline state in response to the service offline message. Therefore, in this embodiment, in the process of loading and unloading the micro-service from the user center service cluster by using the intermediate component, the application background service can be directly notified to delete the node information of the node corresponding to the micro-service to be unloaded from the service node set of the application background service without waiting. Thus, the method provided by the embodiment can avoid the problems of stuck state, long response time and easy error reporting in the process of the micro-service online and offline, thereby realizing the stable online and offline of the micro-service, improving the fault tolerance, reducing the system coupling and further improving the user experience. It should be noted that stable online and offline can be understood as ensuring that the user currently accessing is not affected in any way during the system release process, so that the user is in a non-inductive state, and the user cannot feel the phenomena of system blocking, error reporting and the like.
Any combination of the above optional solutions may be adopted to form an optional embodiment of the present application, which is not described herein.
The following are examples of the apparatus of the present application that may be used to perform the method embodiments of the present application. For details not disclosed in the embodiments of the apparatus of the present application, please refer to the embodiments of the method of the present application.
Fig. 4 is a schematic diagram of an apparatus for providing a microservice online/offline according to an embodiment of the present application. As shown in fig. 4, the device for connecting the micro service to the line includes:
an acquisition module 401 configured to control the user center service cluster to acquire the to-be-online micro-service and the to-be-offline micro-service;
the processing module 402 is configured to control the user center service cluster to set a node corresponding to the micro service to be online to an online state, set a node corresponding to the micro service to be offline to an offline state, and send node information of the node corresponding to the micro service to be offline to an intermediate component;
a sending module 403, configured to control the intermediate component to send node information of a node corresponding to the to-be-offline micro-service to an application background service;
a configuration module 404, configured to control the application background service to delete node information of a node corresponding to the micro service to be disconnected from the service node set of the application background service, and send a service disconnection completion message to the intermediate component;
And the offline module 405 is configured to send a service offline message to the user center service cluster after the intermediate component receives the service offline completion message, so that the user center service cluster sets the node corresponding to the micro-service to be offline to an offline state in response to the service offline message.
Optionally, if the intermediate component is a kafka component, the node information of the node corresponding to the micro-service to be disconnected includes a service name of the micro-service and an IP address of the node; if the intermediate component is a communication component http protocol, the node information of the node corresponding to the micro-service to be disconnected comprises the service name of the micro-service, the IP address of the node and the port information of the node.
Optionally, the sending module 403 is configured to:
controlling the intermediate component to acquire attribute information of a service subscription object corresponding to the micro-service to be offline;
controlling the intermediate component to send node information of the node corresponding to the micro-service to be offline to the service subscription object according to the attribute information of the service subscription object; wherein the service subscription object at least comprises the application background service.
Optionally, the sending module 403 is configured to:
And controlling the intermediate component to acquire the attribute information of the service subscription object corresponding to the micro-service to be offline by calling a service registry client in the application background service.
Optionally, if the intermediate component is a kafka component, the attribute information of the service subscription object corresponding to the to-be-offline micro-service includes an object name and an IP address of the service subscription object; the sending module 403 is configured to:
controlling the intermediate component to create a first theme task;
the intermediate component is controlled to generate a task message corresponding to the service subscription object according to the attribute information of the service subscription object and the node information of the node corresponding to the micro-service to be offline, and the task message is stored in the first theme task;
and controlling the intermediate component to send the node information of the node corresponding to the micro-service to be offline in the task message to the service subscription object according to the attribute information in the task message.
Optionally, if the intermediate component is a http protocol of the communication component, the attribute information of the service subscription object corresponding to the to-be-offline micro-service includes an object name, an IP address and port information of the service subscription object; the sending module 403 is configured to:
Controlling the intermediate component to determine a subscriber service receiving interface corresponding to the service subscription object according to the object name, the IP address and the port information of the service subscription object;
and controlling the intermediate component to send the node information of the node corresponding to the micro service to be disconnected to a subscriber service receiving interface corresponding to the service subscription object.
Optionally, the application background service includes: a load balancer component and a service registry client; the configuration module 404 is configured to:
controlling the application background service to delete node information of the node corresponding to the micro-service to be offline from a service node set of the load balancer component, and deleting node information of the node corresponding to the micro-service to be offline from a service node set of the service registry client;
and controlling the application background service to send a service offline completion message to the intermediate component.
Optionally, the offline module 405 is configured to:
and if the intermediate component receives service offline completion messages sent by all the service subscription objects corresponding to the micro-services to be offline, sending service offline messages to the user center service cluster.
Optionally, the offline module 405 is configured to:
the intermediate component creates a second theme task; the second theme task comprises attribute information of a service subscription object corresponding to the micro service to be offline and a service offline identifier;
if the intermediate component receives a service offline completion message sent by a service subscription object corresponding to the micro-service to be offline, changing a service offline identifier corresponding to the attribute information of the service subscription object in the second theme task into a completed offline state according to the attribute information of the service subscription object;
and if all the service offline identifiers in the second theme task are offline completed, the intermediate component sends a service offline message to the user center service cluster.
Or alternatively, the process may be performed,
if the intermediate component is a communication component http protocol, after receiving service offline completion messages sent by all service subscription objects corresponding to the micro-services to be offline, the intermediate component sends service offline messages to the user center service cluster, including:
and the user center service cluster informs the application background service to update the local aggregate data according to the attribute information of the service subscription object through a communication component http protocol, traverses the service subscription object and completes the micro service offline action.
According to the technical scheme provided by the embodiment of the application, as the intermediate component is utilized, in the process of loading and unloading the micro-service to the user center service cluster, the application background service can be directly informed of deleting the node information of the node corresponding to the micro-service to be unloaded from the service node set of the application background service without waiting. Thus, the method provided by the embodiment can avoid the problems of stuck state, long response time and easy error reporting in the micro-service online and offline process, thereby realizing stable online and offline of the micro-service and further improving the user experience.
Fig. 5 is a schematic diagram of an electronic device 5 according to an embodiment of the present application. As shown in fig. 5, the electronic apparatus 5 of this embodiment includes: a processor 501, a memory 502 and a computer program 503 stored in the memory 502 and executable on the processor 501. The steps of the various method embodiments described above are implemented by processor 501 when executing computer program 503. Alternatively, the processor 501, when executing the computer program 503, performs the functions of the modules/units in the above-described apparatus embodiments.
The electronic device 5 may be a desktop computer, a notebook computer, a palm computer, a cloud server, or the like. The electronic device 5 may include, but is not limited to, a processor 501 and a memory 502. It will be appreciated by those skilled in the art that fig. 5 is merely an example of the electronic device 5 and is not limiting of the electronic device 5 and may include more or fewer components than shown, or different components.
The processor 501 may be a central processing unit (Central Processing Unit, CPU) or other general purpose processor, digital signal processor (Digital Signal Processor, DSP), application specific integrated circuit (Application Specific Integrated Circuit, ASIC), field programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like.
The memory 502 may be an internal storage unit of the electronic device 5, for example, a hard disk or a memory of the electronic device 5. The memory 502 may also be an external storage device of the electronic device 5, for example, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card (Flash Card) or the like, which are provided on the electronic device 5. Memory 502 may also include both internal storage units and external storage devices of electronic device 5. The memory 502 is used to store computer programs and other programs and data required by the electronic device.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions. The functional units and modules in the embodiment may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit, where the integrated units may be implemented in a form of hardware or a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the present application may implement all or part of the flow of the method of the above embodiment, or may be implemented by a computer program to instruct related hardware, and the computer program may be stored in a computer readable storage medium, where the computer program, when executed by a processor, may implement the steps of each of the method embodiments described above. The computer program may comprise computer program code, which may be in source code form, object code form, executable file or in some intermediate form, etc. The computer readable medium may include: any entity or device capable of carrying computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), an electrical carrier signal, a telecommunications signal, a software distribution medium, and so forth. It should be noted that the content of the computer readable medium can be appropriately increased or decreased according to the requirements of the jurisdiction's jurisdiction and the patent practice, for example, in some jurisdictions, the computer readable medium does not include electrical carrier signals and telecommunication signals according to the jurisdiction and the patent practice.
The above embodiments are only for illustrating the technical solution of the present application, and are not limiting; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.

Claims (10)

1. A method for placing a micro-service online and offline, comprising:
the user center service cluster acquires a micro-service to be online and a micro-service to be offline;
the user center service cluster sets the node corresponding to the micro-service to be on line, sets the node corresponding to the micro-service to be off line, and sends node information of the node corresponding to the micro-service to be off line to an intermediate component;
the intermediate component sends node information of the node corresponding to the micro service to be offline to an application background service;
the application background service deletes node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service, and sends a service disconnection completion message to the intermediate component;
And after receiving the service offline completion message, the intermediate component sends a service offline message to the user center service cluster, so that the user center service cluster responds to the service offline message to set the node corresponding to the micro-service to be offline to be in an offline state.
2. The method according to claim 1, wherein if the intermediate component is a kafka component, the node information of the node corresponding to the micro service to be disconnected includes a service name of the micro service and an IP address of the node; if the intermediate component is a communication component http protocol, the node information of the node corresponding to the micro-service to be disconnected comprises the service name of the micro-service, the IP address of the node and the port information of the node.
3. The method of claim 1, wherein the intermediate component sends node information of the node corresponding to the micro-service to be offline to an application background service, comprising:
the intermediate component acquires attribute information of a service subscription object corresponding to the micro-service to be offline;
the intermediate component sends node information of the node corresponding to the micro-service to be offline to the service subscription object according to the attribute information of the service subscription object; wherein the service subscription object at least comprises the application background service.
4. The method of claim 3, wherein the obtaining, by the intermediary component, attribute information of a service subscription object corresponding to the micro-service to be offline includes:
and the intermediate component acquires the attribute information of the service subscription object corresponding to the micro-service to be disconnected by calling a service registry client in the application background service.
5. The method of claim 3, wherein if the intermediate component is a kafka component, the attribute information of the service subscription object corresponding to the to-be-offline micro-service includes an object name and an IP address of the service subscription object; the intermediate component sends node information of the node corresponding to the micro-service to be offline to the service subscription object according to the attribute information of the service subscription object, and the node information comprises:
the intermediate component creates a first theme task;
the intermediate component generates a task message corresponding to the service subscription object according to the attribute information of the service subscription object and the node information of the node corresponding to the micro-service to be offline, and stores the task message into the first theme task;
and the intermediate component sends the node information of the node corresponding to the micro-service to be offline in the task message to the service subscription object according to the attribute information in the task message.
6. The method of claim 3, wherein if the intermediate component is a communication component http protocol, the attribute information of the service subscription object corresponding to the to-be-offline micro-service includes an object name, an IP address, and port information of the service subscription object; the intermediate component sends node information of the node corresponding to the micro-service to be offline to the service subscription object according to the attribute information of the service subscription object, and the node information comprises:
the intermediate component determines a subscriber service receiving interface corresponding to the service subscription object according to the object name, the IP address and the port information of the service subscription object;
and the intermediate component sends the node information of the node corresponding to the micro service to be disconnected to a subscriber service receiving interface corresponding to the service subscription object.
7. The method of claim 1, wherein the application background service comprises: a load balancer component and a service registry client; the application background service deletes node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service, and sends a service disconnection completion message to the intermediate component, including:
The application background service deletes the node information of the node corresponding to the micro-service to be offline from the service node set of the load balancer component, and deletes the node information of the node corresponding to the micro-service to be offline from the service node set of the service registry client;
and the application background service sends a service offline completion message to the intermediate component.
8. The method of claim 3, wherein the sending, by the intermediary component, a service down message to the user center service cluster after receiving the service down completion message comprises:
and if the intermediate component receives service offline completion messages sent by all the service subscription objects corresponding to the micro-services to be offline, sending service offline messages to the user center service cluster.
9. The method of claim 8, wherein if the intermediate component is a kafka component, the sending a service offline message to the user center service cluster after the intermediate component receives service offline completion messages sent by all service subscription objects corresponding to the to-be-offline micro-service includes:
The intermediate component creates a second theme task; the second theme task comprises attribute information of a service subscription object corresponding to the micro service to be offline and a service offline identifier;
if the intermediate component receives a service offline completion message sent by a service subscription object corresponding to the micro-service to be offline, changing a service offline identifier corresponding to the attribute information of the service subscription object in the second theme task into a completed offline state according to the attribute information of the service subscription object;
if all the service offline identifiers in the second theme task are offline completed, the intermediate component sends a service offline message to the user center service cluster;
or alternatively, the process may be performed,
if the intermediate component is a communication component http protocol, after receiving service offline completion messages sent by all service subscription objects corresponding to the micro-services to be offline, the intermediate component sends service offline messages to the user center service cluster, including:
and the user center service cluster informs the application background service to update the local aggregate data according to the attribute information of the service subscription object through a communication component http protocol, traverses the service subscription object and completes the micro service offline action.
10. An apparatus for placing a micro-service online and offline, comprising:
the acquisition module is configured to control the user center service cluster to acquire the to-be-online micro-service and the to-be-offline micro-service;
the processing module is configured to control the user center service cluster to set the node corresponding to the micro-service to be on line, set the node corresponding to the micro-service to be off line, and send the node information of the node corresponding to the micro-service to be off line to an intermediate component;
the sending module is configured to control the intermediate component to send the node information of the node corresponding to the micro service to be disconnected to an application background service;
the configuration module is configured to control the application background service to delete node information of the node corresponding to the micro service to be disconnected from the service node set of the application background service and send a service disconnection completion message to the intermediate component;
and the off-line module is configured to send a service off-line message to the user center service cluster after the intermediate component receives the service off-line completion message, so that the user center service cluster responds to the service off-line message to set the node corresponding to the micro-service to be off-line to be in the off-line state.
CN202310961922.8A 2023-07-30 2023-07-30 Method and device for connecting micro-service to and from line Pending CN116974791A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310961922.8A CN116974791A (en) 2023-07-30 2023-07-30 Method and device for connecting micro-service to and from line

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310961922.8A CN116974791A (en) 2023-07-30 2023-07-30 Method and device for connecting micro-service to and from line

Publications (1)

Publication Number Publication Date
CN116974791A true CN116974791A (en) 2023-10-31

Family

ID=88480979

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310961922.8A Pending CN116974791A (en) 2023-07-30 2023-07-30 Method and device for connecting micro-service to and from line

Country Status (1)

Country Link
CN (1) CN116974791A (en)

Similar Documents

Publication Publication Date Title
CN109889551B (en) Method for accessing intelligent hardware to Internet of things cloud platform
EP1745673B1 (en) Method and system for device discovery
EP2621243A1 (en) Method and system for configuring and managing third party software, and management server
WO2018033015A1 (en) Method and device for communicating between terminals in multiple systems
EP2974159B1 (en) Method, device and system for voice communication
CN106357654B (en) Remote procedure calling method, device and communication system
CN107818027B (en) Method and device for switching main name node and standby name node and distributed system
CN105376761A (en) Method, device and conversation system for establishing conversation connection
KR100818962B1 (en) Method for managing remote mobile device
CN112751689B (en) Network connectivity detection method, monitoring server and monitoring proxy device
CN116974791A (en) Method and device for connecting micro-service to and from line
KR20220006605A (en) Cloud communication method and device, user device, network device
CN111262779A (en) Method, device, server and system for acquiring data in instant messaging
CN108696855B (en) Information management method, session management function and mobility management function
CN110995780A (en) API calling method and device, storage medium and electronic equipment
US20220109607A1 (en) Customer premises equipment configuration management method and apparatus
US20190068737A1 (en) Message pushing system, client equipment and message pushing method thereof
CN115632815A (en) Data updating method and device, electronic equipment and storage medium
CN114064395A (en) Method and device for monitoring health degree of integrated interface, storage medium and electronic equipment
CN113645259B (en) Micro-service elastic expansion method, system and related equipment
CN110545527B (en) Call forwarding method, video communication server and calling terminal
CN112134749A (en) Dynamic network access management method and system
EP1941356B1 (en) Electronic apparatus with server device for managing setting data
CN113766437B (en) Short message sending method and device
CN110086706B (en) Method and system for joining a device-specific message group

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