A server, data push method, and data push system
By establishing long connections and storing client connection objects on the server, pushing data information based on long connections, the problems of poor timeliness and high server pressure under polling methods are solved, real-time data push is realized, and user experience and system stability are improved .
Patent Information
- Application Number
- CN202010583477.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-23
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2040-06-23
AI Technical Summary
When obtaining real-time data of the system, the existing polling method has poor timeliness, ignores network delays, and has great pressure on the server, resulting in poor user experience and service stability problems.
By establishing a long connection on the server, storing client connection objects, and pushing data information to the target client based on the long connection, avoiding polling requests and real-time data push is achieved.
Improves data timeliness, reduces network latency and server pressure, and improves user experience and system stability.
Smart Images

Figure CN111737029B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to data push technology, and more particularly to a server, a data push method, and a data push system. Background Art
[0002] With the continuous promotion of information systems, the increasing popularization of artificial intelligence, and the increasing variety of application scenarios such as real-time chat and hot information push, the efficiency of system data interaction becomes particularly important.
[0003] The existing system for obtaining real-time data can only send requests to the server periodically by polling. At present, the cloud customer service project is connected to real-time chat, and more and more tenants are using smart question-and-answer scenarios. Users have higher and higher requirements for the timeliness of data. A large number of users are visiting, and the number of visits is increasing. The existing smart question-and-answer and manual customer service mostly use the user-side ajax polling method to request data from the server. After the server finds the data, it returns the request. If there is no data, it returns nothing. The user-side obtains the data and then renders it. Polling has the following disadvantages:
[0004] (1) Poor timeliness. If a timer is set and the user requests the server once every 5 seconds, if the customer service or intelligent robot sends a message at 5.1 seconds, the user will need to wait for the second request, which is 10 seconds, to get the message. The low timeliness of the data leads to poor user experience.
[0005] (2) Polling ignores network delays. Regardless of the network conditions, it will send requests over and over again. If the network conditions are poor and a request is sent but no result is returned, it will continue to send requests, resulting in a backlog of requests.
[0006] (3) A large number of requests cause heavy pressure on the server. If a large number of users access the server, polling will consume more resources and even cause the server to crash. The client will still initiate HTTP requests when the server does not return any data, resulting in a lot of unnecessary network transmission. Summary of the invention
[0007] The embodiments of the present invention provide a server, a data push method and a data push system to achieve the effect of pushing data messages in real time.
[0008] In a first aspect, an embodiment of the present invention provides a server, which includes: a plurality of servers, each of which is respectively deployed with at least one service, wherein the service is persistently connected to a client and stores a client connection object;
[0009] The server generates data information and determines a client connection object of the data information;
[0010] The server pushes the data information to a target client corresponding to the client connection object based on the long connection.
[0011] In a second aspect, an embodiment of the present invention further provides a data push method, the method comprising:
[0012] The server generates data information and determines a client connection object of the data information;
[0013] The server pushes the data information to a target client corresponding to the client connection object based on the persistent connection and the client connection object;
[0014] The service end includes a plurality of servers, each of which is respectively deployed with at least one service, and a long connection is established between the service and the client, and a client connection object is stored.
[0015] In a third aspect, an embodiment of the present invention further provides a data push system, the system comprising: a client and a server as described in any one of the embodiments of the present invention;
[0016] The server is used to generate data information and send the data information to the client based on the long connection between the server and the client;
[0017] The client is used to monitor the data information pushed by the server and render the data information.
[0018] The technical solution of the embodiment of the present invention is to develop a server side, which includes multiple servers, each of which is respectively deployed with at least one service. A long connection is established between each service and a client, and the client connection object is stored. The server side can push data information to the target client corresponding to the client connection object based on the long connection. This solves the problem in the prior art that push data messages need to be obtained by polling, achieves the effect of real-time push of data information, and improves user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 This is a schematic diagram of the structure of a server in Embodiment 1 of the present invention;
[0020] Figure 2 This is a schematic diagram of the structure of a server in Embodiment 2 of the present invention;
[0021] Figure 3 This is a schematic diagram of routing work in Embodiment 2 of the present invention;
[0022] Figure 4 This is a schematic diagram of the structure of a server in Embodiment 3 of the present invention;
[0023] Figure 5 This is a schematic diagram of the structure of a server in Embodiment 4 of the present invention;
[0024] Figure 6 is a schematic diagram of the relationship between data channels and services in the fourth embodiment of the present invention;
[0025] Figure 7 is a schematic diagram of the operation of the data channel in the fourth embodiment of the present invention;
[0026] Figure 8 is a flow chart of a data push method in Embodiment 5 of the present invention;
[0027] Fig. 9 It is a schematic diagram of the structural framework of a data push system in Embodiment 6 of the present invention. DETAILED DESCRIPTION
[0028] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0029] Embodiment 1
[0030] Figure 1 This is a schematic diagram of the structure of a server provided in Embodiment 1 of the present invention. This embodiment is applicable to situations where data messages are pushed in real time, such as Figure 1 As shown, the server 10 includes: multiple servers 11, each of which deploys at least one service 12, wherein the service has a long connection with the client and stores a client connection object; the server generates data information and determines the client connection object of the data information; the server pushes the data information to the target client corresponding to the client connection object based on the long connection.
[0031] Exemplarily, the server here can be developed based on socket.io. The client connection object here can be the unique identification information of the client, for example, the client ID, the unique code of the client, etc. Each client has a unique client connection object. The data information here can be a push message generated by the server, for example, it can be a current news, entertainment news, etc. The target client here can be the client to which the data information is to be pushed.
[0032] At least one service deployed on each server in the server establishes a long connection with the client, and stores the client connection object of the client in the service. When the server determines the client connection object of the generated data information, based on the long connection relationship, the data is newly pushed to the target client corresponding to the client connection object.
[0033] Here, the server determines the client connection object of the generated data information. Specifically, the server can determine the client connection object according to the generated data information, the attributes of the data information, the browsing information of the user-side connection object, etc. For example, the server analyzes the generated data information to determine that the data information is entertainment news, and at the same time, according to the browsing information habits of each user-side connection object, it is determined that the user-side connection object A often browses entertainment news. Then, the server determines that the client connection object of the data information is the user-side connection object A, and the server pushes the data information to the client corresponding to the client connection object A.
[0034] By establishing a long connection between each service and the client and storing the client connection object, the server pushes data information to the target client corresponding to the client connection object based on the long connection. This solves the problem of obtaining push data messages through polling in the prior art, achieves the effect of real-time push data information, and improves user experience.
[0035] The technical solution of the embodiment of the present invention is to develop a server side, which includes multiple servers, each of which is respectively deployed with at least one service. A long connection is established between each service and a client, and the client connection object is stored. The server side can push data information to the target client corresponding to the client connection object based on the long connection. This solves the problem in the prior art that push data messages need to be obtained by polling, achieves the effect of real-time push of data information, and improves user experience.
[0036] Embodiment 2
[0037] Figure 2 This is a schematic diagram of the structure of a server provided in the second embodiment of the present invention. The embodiment of the present invention can be combined with each optional solution in the above embodiment. In the embodiment of the present invention:
[0038] Optionally, the server 10 also includes a router 13; the router 13 receives a long connection request sent by the client, and based on the service type of the long connection request, sends the long connection request to any service 13 corresponding to the service type, so that the service 13 creates and stores a client connection object corresponding to the long connection request.
[0039] Exemplarily, a long connection request may be a request sent by a client to establish a long connection with any service. The service type may be the specific service type that the client wants to obtain, for example, it may be a Jingdong service, a Taobao service, an entertainment news service, a current affairs news service, etc. The same type of services can be distributed in different servers, thus ensuring the stability of the service. Routing sends the long connection request to any service corresponding to the service type according to the service type of the long connection request, creates a long connection of the client connection object corresponding to the long connection request in the service, and stores the client connection object corresponding to the long connection request.
[0040] For example, refer to Figure 3 The routing work schematic diagram, wherein socket.io service 1 and socket.io service 2 can be two different types of services, and these two services can be deployed on one server or on two different servers respectively.
[0041] The client (for example, client Q) sends a long connection request to the router. The service type of the long connection request is data information requiring entertainment news. There are three services corresponding to entertainment news, and these three services are deployed in three different servers. According to the service type of the entertainment news, the router establishes a long connection between the client connection object of client Q and the entertainment news service in any of the three servers. For example, the router establishes a long connection between the client connection object of client Q and the entertainment news service in server No. 1, and stores the client connection object of client Q in the entertainment news service in server No. 1.
[0042] It should be noted that when the client connection object establishes a persistent connection with the service, the client will also receive the unique identification information of the service, such as the ID. However, what the client receives here is not the ID of the service, but the ID of the received route. Specifically, it can be to use Zuul (a component of the microservice architecture) of spring-cloud (a microservice architecture) to provide routing for the service, so that the user end can directly access the routing address.
[0043] In this way, through routing, the user end can be connected to the service, achieving the goals of high availability and high system capacity.
[0044] Optionally, the router receives a communication check request sent by the user end; if the router fails to detect the communication check request, the client is controlled to establish a long connection with any other service in at least one server end.
[0045] Exemplarily, the communication check request may be a request to check whether a communication connection is established. When the router receives the communication check request sent by the user, the router checks whether the communication between the client connection object corresponding to the client and the service that establishes a persistent connection with the client is intact. If not, the router controls the service on other servers of the same service type as the service that establishes a persistent connection with the client to establish a persistent connection with the client.
[0046] The technical solution of the embodiment of the present invention receives a long connection request sent by a client through routing, and based on the service type of the long connection request, sends the long connection request to any service corresponding to the service type, so that the service creates and stores a client connection object corresponding to the long connection request, thereby achieving the purpose of high availability and high system capacity. In addition, the routing can also receive a communication check request sent by the user end; if the routing detects that the communication check request fails, the client is controlled to establish a long connection with any other service in at least one server end, thereby ensuring that the client is connected to a complete and healthy service, and avoiding failure to receive data information pushed by the service.
[0047] Embodiment 3
[0048] Figure 4 This is a schematic diagram of the structure of a server provided in Embodiment 3 of the present invention. The embodiment of the present invention can be combined with each optional solution in the above embodiments. In the embodiment of the present invention:
[0049] Optionally, the server further includes a business layer 14, and the business layer 14 is used to determine the client connection object according to the type of data information, wherein the type of data information includes broadcast data and designated user data.
[0050] For example, broadcast data may be data information that can be pushed to all clients corresponding to all client connection objects that have established a persistent connection with a service. Designated user data may be data information that can be pushed to clients corresponding to one or several designated client connection objects that have established a persistent connection with a service.
[0051] When the server determines the client connection object of the data information, it is the business layer in the service that determines the client connection object of the data information based on the data information.
[0052] Specifically, when a service generates data information, the business layer determines whether the data information is broadcast data or designated user data based on the type of the data information, that is, whether the data information is to be pushed to all user terminals corresponding to all user terminal connection objects that have established a long connection with the service, or to the user terminals corresponding to one or several designated user terminal connection objects that have established a long connection with the service.
[0053] In this way, the business layer can determine the client connection object according to the type of data information, so as to subsequently push the data information to the client corresponding to the corresponding client connection object.
[0054] Optionally, the business layer 14 forwards the data information and the client connection object corresponding to the target client to each of the services through routing; if the client connection object is stored in any service, the data information is pushed to the target client corresponding to the client connection object based on the long connection corresponding to the client connection object.
[0055] Exemplarily, when the business layer determines a client connection object corresponding to the data information based on the data information generated by a service, for example, the business layer generates a data message 1 based on a service a, and determines that the client connection object corresponding to the data message 1 is C, the business layer sends the data message 1 and the client connection object C to service a, and service a determines whether the client connection object C is stored therein. If so, based on the long connection established between the client connection object C and service a, the business layer sends the data message 1 to the target client corresponding to the client connection object C.
[0056] This solves the problem in the prior art that push data messages need to be obtained by polling, achieves the effect of real-time push data information, and improves user experience.
[0057] The technical solution of the embodiment of the present invention determines the client connection object according to the type of data information through the business layer included in the server, wherein the type of data information includes broadcast data and specified user data, so as to push the data information to the client corresponding to the corresponding client connection object later. The business layer forwards the data information and the client connection object corresponding to the target client to each of the services through routing; if the client connection object is stored in any service, the data information is pushed to the target client corresponding to the client connection object based on the long connection corresponding to the client connection object. This solves the problem of obtaining push data messages by polling in the prior art, achieves the effect of real-time push data information, and improves user experience.
[0058] Embodiment 4
[0059] Figure 5 This is a schematic diagram of the structure of a server provided in Embodiment 4 of the present invention. The embodiment of the present invention can be combined with each optional solution in the above embodiments. In the embodiment of the present invention:
[0060] Optionally, the server also includes: a data channel 15; when at least one service establishes a long connection with the client, at least one service subscribes to the data channel.
[0061] For example, a data channel can be a data transmission channel, which can be a redis channel. Figure 6 The relationship diagram between the data channel and the service, wherein socket.io service 1 and socket.io service 2 can be two different types of services, which can be deployed on one server or on two different servers. After the service establishes a long connection with the client, the service can start subscribing to a data channel, for example, the service can start subscribing to a redis channel single_msg (channel name, customizable). In this way, data information can be transmitted in the data channel.
[0062] Optionally, the business layer generates data information based on the current service, and a client connection object determined based on the data information generated by the current service. If the current service does not store the client connection object determined based on the data information generated by the current service, the current service sends the data information generated by the current service to the data channel; when any other service other than the current service stores the client connection object determined based on the data information generated by the current service, the service that stores the client connection object determined based on the data information generated by the current service pushes the data information generated by the current service to the client corresponding to the client connection object determined based on the data information generated by the current service.
[0063] Exemplarily, the current service may be a service that currently generates a data message that needs to be pushed. Figure 7 The operation diagram of the data channel is as follows: when the business layer determines a client connection object corresponding to the data information generated by the current service based on the data information, for example, the business layer generates a data message 1 based on the current service a, and determines that a client connection object corresponding to the data message 1 is C, the business layer sends the data message 1 and the client connection object C to the current service a, and the current service a determines whether the client connection object C is stored therein. If not, the data message 1 is sent to the data channel (for example, it can be a redis channel), and the data channel sends the data message 1 to all other services except service a, such as service b, service c and service d. When the client connection object C is stored in any of services b, service c and service d, for example, the client connection object C is stored on service d, then service d sends the data message 1 to the client corresponding to the client connection object C.
[0064] like Figure 7As shown, in addition to determining whether a data message generated by itself can find a corresponding client connection object on itself, any service also needs to determine whether data information transmitted via a data channel can find a corresponding client connection object on itself.
[0065] In this way, by establishing data channels, distributed services of different instances are realized, the problem that services cannot be deployed in a distributed manner is solved, and the goals of high availability and high system capacity are achieved.
[0066] The technical solution of the embodiment of the present invention also includes: a data channel through the service end; when at least one service establishes a long connection with the client, at least one service subscribes to the data channel, so that data information can be transmitted in the data channel. The business layer is based on the data information generated by the current service, and the client connection object determined based on the data information generated by the current service. If the client connection object determined based on the data information generated by the current service is not stored in the current service, the current service sends the data information generated by the current service to the data channel; when the client connection object determined based on the data information generated by the current service is stored in any other service other than the current service, the service storing the client connection object determined based on the data information generated by the current service pushes the data information generated by the current service to the client corresponding to the client connection object determined based on the data information generated by the current service. In this way, by establishing a data channel, distributed services of different instances are realized, the problem that services cannot be deployed in a distributed manner is solved, and the purpose of high availability and high system capacity is achieved.
[0067] Embodiment 5
[0068] Figure 8 This is a flow chart of a data push method provided in Embodiment 5 of the present invention. This embodiment is applicable to the case of real-time push of data messages, and specifically includes the following steps:
[0069] S510, the server generates data information and determines a client connection object of the data information;
[0070] S520, the server pushes the data information to the target client corresponding to the client connection object based on the long connection and the client connection object; wherein the server includes multiple servers, each server deploys at least one service, the service is long connected to the client, and the client connection object is stored.
[0071] Optionally, the server also includes routing.
[0072] Optionally, the routing is based on a persistent connection request sent by the client, and based on the service type of the persistent connection request, sends the persistent connection request to any service corresponding to the service type, so that the service creates and stores a client connection object corresponding to the persistent connection request.
[0073] Optionally, the routing is based on a communication check request sent by the user end; if the routing fails to detect the communication check request, the client is controlled to establish a long connection with any other service in at least one server end.
[0074] Optionally, the server also includes a business layer.
[0075] Optionally, the service layer determines the client connection object based on a type of data information, wherein the type of data information includes broadcast data and designated user data.
[0076] Optionally, the business layer forwards the data information and the client connection object corresponding to the target client to each of the services through routing; if the client connection object is stored in any service, the business layer pushes the data information to the target client corresponding to the client connection object based on the long connection corresponding to the client connection object.
[0077] Optionally, the server also includes: a data channel.
[0078] Optionally, after at least one service establishes a persistent connection with the client, at least one service subscribes to the data channel.
[0079] Optionally, the business layer generates data information based on the current service, and a client connection object determined based on the data information generated by the current service. If the current service does not store the client connection object determined based on the data information generated by the current service, the current service sends the data information generated by the current service to the data channel; when any other service other than the current service stores the client connection object determined based on the data information generated by the current service, the service that stores the client connection object determined based on the data information generated by the current service pushes the data information generated by the current service to the client corresponding to the client connection object determined based on the data information generated by the current service.
[0080] Optionally, the server is developed based on socket.io technology.
[0081] The data push method provided in the embodiment of the present invention has the functions and beneficial effects of a server provided in any embodiment of the present invention.
[0082] Embodiment 6
[0083] Fig. 9 A schematic diagram of the structure framework of a data push system provided in Embodiment 6 of the present invention is shown in FIG. Fig. 9 As shown, the system includes a client 20 and a server 10 provided by any embodiment of the present invention.
[0084] The server 10 is used to generate data information and send the data information to the client based on a long connection with the client.
[0085] The client 20 is used to monitor the data information pushed by the server and render the data information.
[0086] Exemplarily, the client 20 can monitor the data message pushed by the server, and render the data message to display it on the display device (for example, a display screen) of the client. In this way, the client can display the data message pushed by the server in real time.
[0087] The data push system provided by the embodiment of the present invention has the functions and beneficial effects of a server provided by any embodiment of the present invention.
[0088] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A server, comprising a plurality of servers, each of which is respectively deployed with at least one service, wherein the service is persistently connected to a client and stores a client connection object; The server generates data information and determines a client connection object of the data information; The server pushes the data information to a target client corresponding to the client connection object based on the long connection; The server further includes a service layer, and the service layer is used to determine the client connection object according to the type of data information, wherein the type of data information includes broadcast data and designated user data; The broadcast data is data information pushed to all user terminals corresponding to all user terminal connection objects that have established a long connection with the target service; the designated user data is data information pushed to the user terminals corresponding to one or several designated user terminal connection objects that have established a long connection with the target service; When the service generates data information, the business layer determines whether the data information is broadcast data or designated user data, thereby determining the client connection object.
2. The server according to claim 1, characterized in that: The server also includes a router; The router receives a persistent connection request sent by a client, and based on a service type of the persistent connection request, sends the persistent connection request to any service corresponding to the service type, so that the service creates and stores a client connection object corresponding to the persistent connection request.
3. The server according to claim 2, characterized in that: The router receives a communication check request sent by the user end; if the router fails to detect the communication check request, the router controls the client to establish a long connection with any other service in at least one server end.
4. The server according to claim 2, characterized in that: The business layer forwards the data information and the client connection object corresponding to the target client to each of the services through routing; If the client connection object is stored in any service, the data information is pushed to the target client corresponding to the client connection object based on the long connection corresponding to the client connection object.
5. The server according to claim 1, characterized in that: The server also includes: a data channel; After at least one service establishes a persistent connection with the client, at least one service subscribes to the data channel.
6. The server according to claim 5, characterized in that: The business layer generates data information based on the current service, and the client connection object determined based on the data information generated by the current service. If the client connection object determined based on the data information generated by the current service is not stored in the current service, the current service sends the data information generated by the current service to the data channel; When a client connection object determined based on data information generated by the current service is stored in any service other than the current service, the service that stores the client connection object determined based on data information generated by the current service pushes the data information generated by the current service to the client corresponding to the client connection object determined based on the data information generated by the current service.
7. The server according to claim 1, characterized in that: The server is developed based on socket.io technology.
8. A data push method, characterized in that: The method comprises: The server generates data information and determines a client connection object of the data information; The server pushes the data information to a target client corresponding to the client connection object based on the persistent connection and the client connection object; The server includes multiple servers, each of which deploys at least one service. The service is permanently connected to the client and stores a client connection object. The server further includes a service layer, and the service layer determines the client connection object according to the type of data information, wherein the type of data information includes broadcast data and designated user data; The broadcast data is data information pushed to all user terminals corresponding to all user terminal connection objects that have established a long connection with the target service; the designated user data is data information pushed to the user terminals corresponding to one or several designated user terminal connection objects that have established a long connection with the target service; When the service generates data information, the business layer determines whether the data information is broadcast data or designated user data, thereby determining the client connection object.
9. A data push system, characterized in that: Comprising a client and a server as described in any one of claims 1 to 7; The server is used to generate data information and send the data information to the client based on the long connection between the server and the client; The client is used to monitor the data information pushed by the server and render the data information.
